Skip to content

Migrate read_video_properties from OpenCV to PyAV#959

Merged
mprib merged 1 commit intomainfrom
fix/video-utils-pyav-migration
Mar 9, 2026
Merged

Migrate read_video_properties from OpenCV to PyAV#959
mprib merged 1 commit intomainfrom
fix/video-utils-pyav-migration

Conversation

@mprib
Copy link
Owner

@mprib mprib commented Mar 9, 2026

Summary

  • Replaces cv2.VideoCapture with av.open() for video metadata extraction, eliminating the last OpenCV video I/O in production code
  • Adds duration-based frame count fallback matching FrameSource.frame_count logic
  • Wraps PyAV exceptions as ValueError to preserve the caller contract
  • Adds <= 0 defense-in-depth guard on frame count in from_videos()
  • Adds error-case unit tests for FileNotFoundError and ValueError

Replaces cv2.VideoCapture with av.open() for video metadata
extraction, eliminating the last OpenCV video I/O in production
code. OpenCV's CAP_PROP_FRAME_COUNT returns -1 for codecs it
doesn't fully support; PyAV wraps FFmpeg directly and handles
all codecs consistently.

- Rewrite video_utils.py to use av.open() + stream metadata
- Add duration-based frame count fallback (matches FrameSource)
- Wrap PyAV exceptions as ValueError (preserves caller contract)
- Guard frame_count <= 0 in from_videos() (defense-in-depth)
- Add error-case tests for FileNotFoundError and ValueError
@mprib mprib merged commit 9776ea2 into main Mar 9, 2026
3 checks passed
@mprib mprib deleted the fix/video-utils-pyav-migration branch March 9, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant