Skip to content

fix(video): read files with audio before the video stream - #2746

Merged
Borda merged 3 commits into
roboflow:developfrom
Nikhi00718:fix/video-audio-first-stream
Oct 17, 2026
Merged

Borda merged 3 commits into
roboflow:developfrom
Nikhi00718:fix/video-audio-first-stream

Conversation

@Nikhi00718

Copy link
Copy Markdown
Contributor

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 index 1 and video index 0: read() silently returns False, and reading the dimensions raises IndexError: tuple index out of range.

Select video stream 0, consistently with streams.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_generator or 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

  • Correct the four PyAV decode selectors.
  • Add real MP4 and Matroska fixtures with audio-first and video-first stream orders, checking dimensions, frame count, reads and backward seeking.
  • Cover the public video APIs with synchronous and prefetched reads.
  • Add an Unreleased changelog entry.

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 src on PYTHONPATH.

  • Clean develop at 6ecb27963: 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.md under Unreleased

Additional Notes

The capture continues to select the first video stream. Codec selection, audio remuxing and the OpenCV backend are unchanged.

@Nikhi00718
Nikhi00718 requested a review from SkalskiP as a code owner October 16, 2026 16:21
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (ffd0ac0) to head (eddb4b0).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda added the bug Something isn't working label Oct 16, 2026
@Borda
Borda requested a balanced review from Copilot October 16, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 0 consistently 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
Borda merged commit 1fb42a4 into roboflow:develop Oct 17, 2026
36 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants