-
Notifications
You must be signed in to change notification settings - Fork 31.1k
fix: improve video processing fps and do_sample_frames assignment logic #42009
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: main
Are you sure you want to change the base?
Conversation
|
cc @molbap @yonigozlan for processors |
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.
Hey @Xqle , thanks for the PR though I am not convinced we have to automatically change the flag depending on input args. Please see my comments below
| output_kwargs["videos_kwargs"]["do_sample_frames"] = True | ||
| logger.info( | ||
| "User specified 'fps' without 'do_sample_frames'; " | ||
| "'do_sample_frames' has been automatically enabled." | ||
| ) |
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.
i don't think this is a good idea. We can't automatically change the flag only for a single model. If we are to change to all models, it will be much harder because the sampling can be set either with num_frames or fps and optionally other args. Checking for what required args are present per model is not as straightforward always
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.
For this part, we can just revert the change.
| fps = output_kwargs["videos_kwargs"].get( | ||
| "fps", [metadata.fps if metadata.fps is not None else 24 for metadata in video_metadata] | ||
| ) |
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.
i don't think this is the fps if the original video here we are using. It's more probably the sampling fps rate used which is in videos_kwargs
The sampling fps however isn't always there, we can sample with number of frames, with default values of video processor or do not sample at all. So the 2 here is just the default value of the video processor
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.
Thanks for the feedback.
In Qwen2.5-VL, the video processor we are using is the Qwen2-VL video processor, which does not initialize fps or num_frames by default, see above. So the model will not sample the input video by default.
And I think the fps in this context is not only used for frame sampling, but is later involved in computing seconds_per_grid_ts, which directly affects the temporal RoPE index inside get_rope_index. So, the fps used here should correspond to the effective fps of the processed video (i.e., the fps after potential frame sampling).
Specifically:
-
When
fpsanddo_sample_framesare passed invideo_kwargs, the processor will sample the video according to that fps, so the processed video’s fps should match the samplingfpsinvideo_kwargs. -
When either
fpsordo_sample_framesis not provided, no sampling occurs, and the processed video keeps its original fps, which ismetadata.fps. In that case, usingmetadata.fpsensures thatseconds_per_grid_tsand thus the temporal RoPE positions remain consistent with the actual video duration. -
Finally, if no sampling occurs and
metadata.fpsis unavailable, it’s reasonable to fall back to a typical video frame rate such as 24 fps, to maintain temporal consistency in downstream computations.
So, I think we can revert the part of automatic change of flag do_sample_frames, and change this part to something like:
fps = [metadata.fps if metadata.fps is not None else 24 for metadata in video_metadata]
if output_kwargs["videos_kwargs"].get("do_sample_frames") is not None:
if output_kwargs["videos_kwargs"].get("fps") is not None:
fps = output_kwargs["videos_kwargs"]["fps"]
elif output_kwargs["videos_kwargs"].get("num_frames") is not None:
fps = [output_kwargs["videos_kwargs"]["num_frames"] / metadata.duration for metadata in video_metadata]|
Thanks for the review. But I think the |
Avoid error when 'num_frames' is passed rather than 'fps'.
|
[For maintainers] Suggested jobs to run (before merge) run-slow: qwen2_5_vl |

What does this PR do?
1. Improve
fpshandling inQwen2_5_VLProcessor.__call__()Previously, the
__call__()function always defaulted tofps=2, regardless of the input video.Now, when fps is not explicitly provided and cannot be read from the video metadata, it falls back to 24 by default. Otherwise, the provided or metadata fps is used. It follows a priority order:
The default value 24 is chosen as it represents a common frame rate for most videos.
This prevents potential errors in
second_per_grid_tscalculation when the actual video frame rate differs from the assumed default.2. More robust
do_sample_framesbehaviorfpsis manually provided butdo_sample_framesis not specified,do_sample_frameswill now be automatically set to True.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@zucchini-nlp