Skip to content

Fix: Handle empty lists in video_utils functions#44769

Closed
LincolnBurrows2017 wants to merge 4 commits intohuggingface:mainfrom
LincolnBurrows2017:fix-video-utils-empty-list
Closed

Fix: Handle empty lists in video_utils functions#44769
LincolnBurrows2017 wants to merge 4 commits intohuggingface:mainfrom
LincolnBurrows2017:fix-video-utils-empty-list

Conversation

@LincolnBurrows2017
Copy link
Copy Markdown

Summary

The is_batched_video() and convert_pil_frames_to_video() functions in src/transformers/video_utils.py were accessing videos[0] without first checking if the list is empty, causing IndexError when empty lists are passed.

This is similar to the fix applied to image_utils.py in commit 4afe016.

Changes

  • is_batched_video(): Added len(videos) > 0 and check before accessing videos[0]
  • convert_pil_frames_to_video(): Added early return [] for empty list input

Testing

The fix handles the following edge cases:

  • is_batched_video([]) - returns False instead of raising IndexError
  • convert_pil_frames_to_video([]) - returns [] instead of raising IndexError

LincolnBurrows2017 and others added 4 commits March 13, 2026 20:44
The is_batched_video() and convert_pil_frames_to_video() functions
were accessing videos[0] without first checking if the list is empty,
causing IndexError when empty lists are passed.

This is similar to the fix applied to image_utils.py in commit 4afe016.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants