[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:
@@ -885,7 +885,6 @@ class GLM46VVideoBackend(VideoBackend):
|
|||||||
extract_t = min(extract_t, cls._MAX_FRAME_COUNT_DYNAMIC)
|
extract_t = min(extract_t, cls._MAX_FRAME_COUNT_DYNAMIC)
|
||||||
|
|
||||||
duration_per_frame = 1 / original_fps if original_fps > 0 else 0
|
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
|
max_second = int(duration) if duration else 0
|
||||||
|
|
||||||
if total_frames_num < extract_t:
|
if total_frames_num < extract_t:
|
||||||
@@ -897,7 +896,7 @@ class GLM46VVideoBackend(VideoBackend):
|
|||||||
current_second = 0.0
|
current_second = 0.0
|
||||||
inv_fps = 1 / (temporal_patch_size * target_fps)
|
inv_fps = 1 / (temporal_patch_size * target_fps)
|
||||||
for frame_index in range(total_frames_num):
|
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
|
current_second += inv_fps
|
||||||
frame_indices.append(frame_index)
|
frame_indices.append(frame_index)
|
||||||
if current_second >= max_second:
|
if current_second >= max_second:
|
||||||
@@ -991,7 +990,6 @@ class GLMGAVideoBackend(VideoBackend):
|
|||||||
extract_t = min(extract_t, max_frames)
|
extract_t = min(extract_t, max_frames)
|
||||||
|
|
||||||
duration_per_frame = 1 / original_fps
|
duration_per_frame = 1 / original_fps
|
||||||
timestamps = [i * duration_per_frame for i in range(total_frames_num)]
|
|
||||||
|
|
||||||
if total_frames_num < extract_t:
|
if total_frames_num < extract_t:
|
||||||
frame_indices = [
|
frame_indices = [
|
||||||
@@ -1002,7 +1000,7 @@ class GLMGAVideoBackend(VideoBackend):
|
|||||||
current_second = 0.0
|
current_second = 0.0
|
||||||
inv_fps = 1 / target_fps
|
inv_fps = 1 / target_fps
|
||||||
for frame_index in range(total_frames_num):
|
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
|
current_second += inv_fps
|
||||||
frame_indices.append(frame_index)
|
frame_indices.append(frame_index)
|
||||||
if current_second >= duration - inv_fps:
|
if current_second >= duration - inv_fps:
|
||||||
|
|||||||
Reference in New Issue
Block a user