Skip to content

Fix torchvision video frame indices offset - #2091

Open
Travor278 wants to merge 1 commit into
QwenLM:mainfrom
Travor278:fix-torchvision-video-offset
Open

Fix torchvision video frame indices offset#2091
Travor278 wants to merge 1 commit into
QwenLM:mainfrom
Travor278:fix-torchvision-video-offset

Conversation

@Travor278

Copy link
Copy Markdown

Fixes #2085

This PR makes qwen_vl_utils report absolute frames_indices for the torchvision video backend when video_start is set.

torchvision.io.read_video returns frames from the clipped segment requested by start_pts / end_pts, so the sampled indices are relative to that segment. The decord and torchcodec backends already report indices in the original video timeline. This change adds the video_start frame offset back to the torchvision indices so the metadata is consistent across backends.

I also added a focused regression test with a mocked torchvision.io.read_video path for:

  • no trim, where indices still start at 0
  • video_start=2.0 at 25 fps, where the first index is 50
  • video_start=1.0 / video_end=3.0, where the first index is 25 and the clipped frame count is preserved

Validation:

  • D:/Dev/conda-envs/py313/python.exe -m pytest tests/test_torchvision_frame_indices.py -v
  • D:/Dev/conda-envs/py313/python.exe -m ruff check tests/test_torchvision_frame_indices.py
  • D:/Dev/conda-envs/py313/python.exe -m ruff format --check tests/test_torchvision_frame_indices.py
  • git diff --check
@Travor278
Travor278 marked this pull request as ready for review May 3, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant