-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix process_video and add test case #2011
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import cv2 | ||
| import numpy as np | ||
|
|
||
| from supervision.utils.video import process_video | ||
|
|
||
|
|
||
| def create_test_video(path, num_frames, width=20, height=10): | ||
| fourcc = cv2.VideoWriter_fourcc(*"mp4v") | ||
| out = cv2.VideoWriter(path, fourcc, 1.0, (width, height)) | ||
|
|
||
| for _ in range(num_frames): | ||
| frame = np.zeros((height, width, 3), dtype=np.uint8) | ||
| out.write(frame) | ||
|
|
||
| out.release() | ||
|
|
||
|
|
||
| def test_process_video_max_frames_exceeds_total_frames(tmp_path): | ||
| source_path = tmp_path / "source.mp4" | ||
| target_path = tmp_path / "target.mp4" | ||
|
|
||
| create_test_video(str(source_path), num_frames=5) | ||
|
|
||
| process_video( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any assertion or other validation, then it runs? |
||
| source_path=str(source_path), | ||
| target_path=str(target_path), | ||
| callback=lambda frame, _: frame, | ||
| max_frames=10, | ||
| ) | ||
|
Comment on lines
+24
to
+29
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the 'or' operator here will incorrectly handle the case when max_frames is 0. If a user passes max_frames=0 (meaning process zero frames), this line will replace it with source_video_info.total_frames instead of respecting the 0 value.
Consider using an explicit None check instead, such as:
max_frames = source_video_info.total_frames if max_frames is None else max_frames