-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: process_video silent hang on callback error
#2022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Borda
merged 13 commits into
roboflow:develop
from
realh4m:fix/video-worker-error-propagation
Jan 30, 2026
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2fccbf8
Handle process_video worker exceptions
realh4m fce63f8
test: add unit tests for process_video exception handling and fix doc…
realh4m 68da595
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] d5e342a
Merge branch 'develop' into fix/video-worker-error-propagation
Borda 080441d
update
Borda 9b1997f
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 7195421
linting
Borda 63eb824
Merge branch 'fix/video-worker-error-propagation' of https://github.c…
Borda 4fe154e
Update supervision/utils/video.py
Borda 6ac3641
Handle `Full` exception in video writer queue and add test for small …
Borda b2db14a
lint
Borda 1489388
Apply suggestions from code review
Borda 0830888
Merge branch 'develop' into fix/video-worker-error-propagation
Borda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import os | ||
|
|
||
| import cv2 | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from supervision.utils.video import VideoInfo, get_video_frames_generator, process_video | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def dummy_video_path(tmp_path): | ||
| path = str(tmp_path / "dummy_video.mp4") | ||
| fourcc = cv2.VideoWriter_fourcc(*"mp4v") | ||
| out = cv2.VideoWriter(path, fourcc, 25, (640, 480)) | ||
| for _ in range(10): | ||
| frame = np.zeros((480, 640, 3), dtype=np.uint8) | ||
| out.write(frame) | ||
| out.release() | ||
| return path | ||
|
|
||
|
|
||
| def test_process_video_exception_handling(dummy_video_path, tmp_path): | ||
| target_path = str(tmp_path / "target.mp4") | ||
|
|
||
| def callback_with_exception(frame, index): | ||
| if index == 5: | ||
| raise ValueError("Test exception at frame 5") | ||
| return frame | ||
|
|
||
| with pytest.raises(ValueError, match="Test exception at frame 5"): | ||
| process_video( | ||
| source_path=dummy_video_path, | ||
| target_path=target_path, | ||
| callback=callback_with_exception, | ||
| ) | ||
|
|
||
|
Borda marked this conversation as resolved.
|
||
|
|
||
| def test_process_video_success_after_fix(dummy_video_path, tmp_path): | ||
| target_path = str(tmp_path / "target_success.mp4") | ||
|
|
||
| def callback_success(frame, index): | ||
| return frame | ||
|
|
||
| # This should complete without exception | ||
| process_video( | ||
| source_path=dummy_video_path, target_path=target_path, callback=callback_success | ||
| ) | ||
|
|
||
| assert os.path.exists(target_path) | ||
|
|
||
|
Borda marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_process_video_max_frames(dummy_video_path, tmp_path): | ||
| target_path = str(tmp_path / "target_max_frames.mp4") | ||
| processed_indices = [] | ||
|
|
||
| def callback(frame, index): | ||
| processed_indices.append(index) | ||
| return frame | ||
|
|
||
| process_video( | ||
| source_path=dummy_video_path, | ||
| target_path=target_path, | ||
| callback=callback, | ||
| max_frames=5, | ||
| ) | ||
|
|
||
| assert len(processed_indices) == 5 | ||
| assert processed_indices == [0, 1, 2, 3, 4] | ||
|
|
||
|
|
||
| def test_process_video_custom_params(dummy_video_path, tmp_path): | ||
| target_path = str(tmp_path / "target_custom_params.mp4") | ||
|
|
||
| def callback(frame, index): | ||
| return frame | ||
|
|
||
| # Test with very small prefetch and writer_buffer | ||
| process_video( | ||
| source_path=dummy_video_path, | ||
| target_path=target_path, | ||
| callback=callback, | ||
| prefetch=1, | ||
| writer_buffer=1, | ||
| ) | ||
|
|
||
| assert os.path.exists(target_path) | ||
|
|
||
|
|
||
| def test_video_info(dummy_video_path): | ||
| video_info = VideoInfo.from_video_path(dummy_video_path) | ||
| assert video_info.width == 640 | ||
| assert video_info.height == 480 | ||
| assert video_info.fps == 25 | ||
| assert video_info.total_frames == 10 | ||
| assert video_info.resolution_wh == (640, 480) | ||
|
|
||
|
|
||
| def test_get_video_frames_generator(dummy_video_path): | ||
| generator = get_video_frames_generator(dummy_video_path) | ||
| frames = list(generator) | ||
| assert len(frames) == 10 | ||
| assert all(isinstance(frame, np.ndarray) for frame in frames) | ||
| assert all(frame.shape == (480, 640, 3) for frame in frames) | ||
|
|
||
|
|
||
| def test_get_video_frames_generator_with_stride(dummy_video_path): | ||
| generator = get_video_frames_generator(dummy_video_path, stride=2) | ||
| frames = list(generator) | ||
| assert len(frames) == 5 | ||
|
|
||
|
|
||
| def test_get_video_frames_generator_with_start_end(dummy_video_path): | ||
| generator = get_video_frames_generator(dummy_video_path, start=2, end=5) | ||
| frames = list(generator) | ||
| assert len(frames) == 3 | ||
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.
Uh oh!
There was an error while loading. Please reload this page.