fix(template): guard MiniCPM-V/mPLUG-Owl3 video sampling against 0-fps metadata#9750
Open
he-yufeng wants to merge 1 commit into
Open
fix(template): guard MiniCPM-V/mPLUG-Owl3 video sampling against 0-fps metadata#9750he-yufeng wants to merge 1 commit into
he-yufeng wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request ensures that sample_fps is clamped to a minimum value of 1 in vision_utils.py, preventing a zero-step range error when processing videos with 0 FPS. A corresponding unit test, test_load_video_minicpmv_handles_zero_fps, has been added to verify this fix. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…s metadata load_video_minicpmv_mplug_owl3 computes sample_fps = round(vr.get_avg_fps()) and then walks the frames with range(0, len(vr), sample_fps). decord's get_avg_fps() returns 0.0 for a video whose container has no / broken fps metadata (and a very low sub-1 fps rounds to 0 too), so sample_fps becomes 0 and range() raises "ValueError: range() arg 3 must not be zero" before any frame is read. The MiniCPM-V and mPLUG-Owl3 templates reach this for any user-supplied video and there is no upstream fps check; the same file already treats fps == 0 as a real case in _video_get_metadata_local (fps if fps > 0 else 0). Clamp sample_fps to at least 1 so a 0-fps video falls back to sampling every frame, which the existing max_num_frames uniform_sample then downsamples. Normal videos (fps >= 1) are unaffected.
ac80301 to
7d8775f
Compare
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.
What
load_video_minicpmv_mplug_owl3picks frames withdecord's
get_avg_fps()returns0.0when the container has no / broken fps metadata (and a very low sub-1 fps rounds to 0 as well), sosample_fpsbecomes0andrange(0, len(vr), 0)raisesValueError: range() arg 3 must not be zerobefore a single frame is read. TheMiniCPM-VandmPLUG-Owl3templates call this for any user-supplied video (swift/template/templates/minicpm.py,swift/template/templates/mplug.py), and there is no upstream fps check, so an ordinary video with missing fps metadata crashes encoding. The same file already treatsfps == 0as a real case elsewhere (_video_get_metadata_localusesfps if fps > 0 else 0).Fix
Clamp
sample_fpsto at least 1 so a 0-fps video falls back to sampling every frame, which the existingmax_num_framesuniform_samplethen downsamples. Normal videos (fps >= 1) are unaffected.Verification
decord/torch are not installable in my environment, so I reproduced the exact sampling logic standalone:
ValueError: range() arg 3 must not be zeroValueError: range() arg 3 must not be zeroThe added
test_load_video_minicpmv_handles_zero_fpsmocks a decordVideoReaderwhoseget_avg_fps()returns0.0and assertsload_video_minicpmv_mplug_owl3returns frames instead of raising (fails before this change, passes after). It needs no real video or GPU.