Repository navigation
fix(video): read files with audio before the video stream - #2746
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2746 +/- ##
=======================================
Coverage 94% 94%
=======================================
Files 83 83
Lines 13612 13612
=======================================
+ Hits 12796 12807 +11
+ Misses 816 805 -11 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrowly scoped correction consistently selects the intended stream and includes targeted regression coverage, with no unresolved findings.
0 open findings
What changed in this PR
Fixes PyAV fallback video reading when audio precedes the first video stream.
Changes:
- Selects video stream
0consistently for decoding, metadata, frame counting and decoder resets. - Adds regression coverage for stream ordering, backward seeking and public video readers.
- Documents the fix in the changelog.
| File | Description |
|---|---|
| tests/cv2/test_video.py | Adds MP4, Matroska and public-reader regression tests. |
| src/supervision/_cv2/_video.py | Corrects four PyAV video-stream selectors. |
| docs/changelog.md | Records the audio-first video fix. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Borda
approved these changes
Oct 16, 2026
Borda
added a commit
that referenced
this pull request
Oct 20, 2026
* fix(video): read files with audio before the video stream * docs: link audio-first video fix to changelog --------- Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Without OpenCV, videos whose first video stream follows an audio stream cannot be decoded. The PyAV fallback passes the video's global container index to
decode(video=...), but that selector indexes only video streams. In an audio-first MP4, the first video has container index1and video index0:read()silently returnsFalse, and reading the dimensions raisesIndexError: tuple index out of range.Select video stream
0, consistently withstreams.video[0], for initial decoding, frame-count fallback, display-rotation metadata and decoder reset during backward seeking.Motivation and Context
Stream order is valid container metadata and should not prevent
VideoInfo.from_video_path,get_video_frames_generatoror the fallback capture from reading the file. This affects the default installation without OpenCV. No external model or download is needed to reproduce it: write an AAC stream before an MPEG-4 stream in a local MP4, then read it with the fallback.Changes Made
Testing
Windows, Python 3.13.15, PyAV 18.0.0, NumPy fallback backend (OpenCV absent). Commands use the existing development environment's Python with this worktree's
srconPYTHONPATH.Clean
developat6ecb27963:python -m pytest tests/cv2/test_video.py -k audio_before_video -q --tb=short— 4 failed with the stream-index error, 2 passed.Fixed:
python -m pytest tests/cv2/test_video.py tests/utils/test_video.py -q --tb=short— 112 passed, 5 skipped.Clean baseline:
python -m pytest src tests --cov=supervision -q --tb=short— 5694 passed, 105 skipped.Fixed full suite:
python -m pytest src tests --cov=supervision -q --tb=short— 5700 passed, 105 skipped.python -m pre_commit run --all-files— all hooks passed, including mypy.Added/updated tests, and the full suite passes locally
Updated docstrings for the corrected behavior
Added a changelog entry in
docs/changelog.mdunderUnreleasedAdditional Notes
The capture continues to select the first video stream. Codec selection, audio remuxing and the OpenCV backend are unchanged.