[Perf][Multimodal] Avoid building a full timestamps list in video frame sampling (#46543)

Signed-off-by: Lynn <lynnhe02@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lynn
2026-06-24 09:38:27 +00:00
committed by GitHub
co-authored by Claude Opus 4.8
parent dc0d318177
commit 52fbe12283
+2 -4
View File
@@ -885,7 +885,6 @@ class GLM46VVideoBackend(VideoBackend):
extract_t = min(extract_t, cls._MAX_FRAME_COUNT_DYNAMIC)
duration_per_frame = 1 / original_fps if original_fps > 0 else 0
timestamps = [i * duration_per_frame for i in range(total_frames_num)]
max_second = int(duration) if duration else 0
if total_frames_num < extract_t:
@@ -897,7 +896,7 @@ class GLM46VVideoBackend(VideoBackend):
current_second = 0.0
inv_fps = 1 / (temporal_patch_size * target_fps)
for frame_index in range(total_frames_num):
if timestamps[frame_index] >= current_second:
if frame_index * duration_per_frame >= current_second:
current_second += inv_fps
frame_indices.append(frame_index)
if current_second >= max_second:
@@ -991,7 +990,6 @@ class GLMGAVideoBackend(VideoBackend):
extract_t = min(extract_t, max_frames)
duration_per_frame = 1 / original_fps
timestamps = [i * duration_per_frame for i in range(total_frames_num)]
if total_frames_num < extract_t:
frame_indices = [
@@ -1002,7 +1000,7 @@ class GLMGAVideoBackend(VideoBackend):
current_second = 0.0
inv_fps = 1 / target_fps
for frame_index in range(total_frames_num):
if timestamps[frame_index] >= current_second:
if frame_index * duration_per_frame >= current_second:
current_second += inv_fps
frame_indices.append(frame_index)
if current_second >= duration - inv_fps: