Skip to content

Migrate read_video_properties from OpenCV to PyAV#958

Closed
mprib wants to merge 1 commit intomainfrom
fix/video-utils-pyav-migration
Closed

Migrate read_video_properties from OpenCV to PyAV#958
mprib wants to merge 1 commit intomainfrom
fix/video-utils-pyav-migration

Conversation

@mprib
Copy link
Owner

@mprib mprib commented Mar 9, 2026

Summary

  • Rewrites read_video_properties() to use PyAV (av.open() + stream metadata) instead of cv2.VideoCapture, eliminating the last OpenCV video I/O usage in production code
  • Fixes codec failures where OpenCV's CAP_PROP_FRAME_COUNT returns -1 for unsupported codecs (e.g. APV from DaVinci Resolve), causing NaN propagation in timestamp inference
  • Adds defense-in-depth guard (<= 0 instead of == 0) in from_videos() for negative frame counts

Fixes #956

Eliminates the last cv2.VideoCapture usage in production code.
OpenCV's CAP_PROP_FRAME_COUNT returns -1 for unsupported codecs
(e.g. APV from DaVinci Resolve), causing NaN propagation in
timestamp inference. 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 all PyAV exceptions as ValueError (caller contract)
- Fix from_videos() guard: frame_count == 0 → <= 0
- Add error-case tests for FileNotFoundError and ValueError

Fixes #956
@mprib mprib closed this Mar 9, 2026
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.

Issue with Extrinsics pipeline

1 participant