[Bugfix][Model][Lance] Support decoded video frames in video editing (#5128)

Signed-off-by: 吴俊鹏 <248679769+junpengw67-max@users.noreply.github.com>
Co-authored-by: 吴俊鹏 <248679769+junpengw67-max@users.noreply.github.com>
This commit is contained in:
junpengw67-maxand吴俊鹏 authored and GitHub committed 2026-09-12 04:23:24 +00:00
1 parent b3ba67d71e
commit bc0c9f4b45
3 files changed
+224 -1

No files matched your search

+50 -1
View File
@@ -1,10 +1,59 @@
from collections.abc import Callable
import math
from collections.abc import Callable, Sequence
from contextlib import contextmanager
import numpy as np
import torch
from PIL import Image
from vllm.model_executor.models.utils import maybe_prefix
def normalize_decoded_video_frames(
video_input: Sequence[Image.Image],
*,
default_fps: float,
) -> tuple[np.ndarray, float]:
"""Convert decoded image frames to a contiguous THWC uint8 video array."""
if not video_input:
raise ValueError("video_edit received an empty decoded video frame sequence.")
frame_rate = float(default_fps)
for fps in (
getattr(video_input, "fps", None),
getattr(video_input, "frame_rate", None),
):
try:
candidate = float(fps)
except (TypeError, ValueError):
continue
if math.isfinite(candidate) and candidate > 0:
frame_rate = candidate
break
frames = []
frame_size = None
for index, frame in enumerate(video_input):
if not isinstance(frame, Image.Image):
raise ValueError(
f"video_edit decoded video frame at index {index} must be a PIL.Image.Image, got {type(frame)}."
)
width, height = frame.size
if width <= 0 or height <= 0:
raise ValueError(
f"video_edit decoded video frame at index {index} must have positive dimensions, got {width}x{height}."
)
if frame_size is None:
frame_size = frame.size
elif frame.size != frame_size:
raise ValueError(
"video_edit decoded video frames must have identical dimensions; "
f"frame 0 is {frame_size}, frame {index} is {frame.size}."
)
frames.append(np.asarray(frame.convert("RGB"), dtype=np.uint8))
return np.ascontiguousarray(np.stack(frames)), frame_rate
@contextmanager
def transformers_keys_to_ignore_compat():
"""Make ``trust_remote_code`` weight loading robust to the transformers 5.9