vllm.multimodal.video
¶
Classes:
-
ClefOmniVideoBackend–Clef-Omni's reference sampling: the first frame at or after each
-
DynamicVideoBackend–Duration-aware dynamic-sampling video backend.
-
EmbeddingGemma2VideoBackend–Samples frames with the same indices as HF EmbeddingGemma2VideoProcessor.
-
GLM46VVideoBackend–GLM-4.6V dynamic FPS video backend.
-
Glm5NextVideoBackend–GLM-5.3-Flash fps-interval video backend.
-
Molmo2VideoBackend– -
PyNvVideoCodecVideoBackend–Hardware-accelerated video backend using PyNvVideoCodec.
-
Qwen2VLVideoBackend–Qwen2-VL / Qwen2.5-VL fps-based video backend.
-
VideoBackend–Uniform-sampling video backend.
-
VideoLoader– -
VideoLoaderRegistry–
Attributes:
-
DecodedFrames(TypeAlias) –Decoded video frames: a host
np.ndarray, or a devicetorch.Tensor
DecodedFrames = npt.NDArray | torch.Tensor
module-attribute
¶
Decoded video frames: a host np.ndarray, or a device torch.Tensor
when a GPU decoding codec is used (e.g. torchcodec with device="cuda").
ClefOmniVideoBackend
¶
Bases: VideoBackend
Clef-Omni's reference sampling: the first frame at or after each
1/fps boundary (frame i sits at i / original_fps seconds, so the
k-th boundary is crossed by frame ceil(k * original_fps / fps)),
capped at 768 frames and padded to an even count by repeating the last
frame.
DynamicVideoBackend
¶
Bases: VideoBackend
Duration-aware dynamic-sampling video backend.
Samples at fps up to max_duration seconds, falling back to
uniform sampling across the full duration when the video is longer
than max_duration. Codec is selectable the same way as
VideoBackend.
EmbeddingGemma2VideoBackend
¶
Bases: VideoBackend
Samples frames with the same indices as HF EmbeddingGemma2VideoProcessor.
_get_processor_defaults(**kwargs)
classmethod
¶
Read default fps and max_frames from video_processor if available.
GLM46VVideoBackend
¶
Bases: VideoBackend
GLM-4.6V dynamic FPS video backend.
Faithfully replicates the frame sampling logic from transformers'
Glm46VVideoProcessor.sample_frames:
- Dynamic FPS thresholds based on effective video duration:
{≤30s: 3fps, ≤300s: 1fps, >300s: 0.5fps} temporal_patch_sizemultiplier (default 2) applied to extract count- Duration capped at 2400s, frame count capped at 640
- Even frame count enforced (append last frame if odd)
Glm5NextVideoBackend
¶
Bases: VideoBackend
GLM-5.3-Flash fps-interval video backend.
Selects frames with the same sampler the processor falls back to, so only
the sampled frames are materialized. fps_interval semantics (default
2.0) with a temporal-patch-scaled greedy walk, frame count capped at 2048,
temporal pairs kept even. Request overrides: fps -> fps interval,
max_frames -> frame cap, temporal_patch_size (default 2).
_sample_frame_indices(total_frames, fps, duration, *, target_fps=None, max_frame_count=None, temporal_patch_size=2)
classmethod
¶
GLM video frame sampling (training-reference parity).
target_fps is the fps_interval request knob. The greedy walk
advances at 1 / (temporal_patch_size * target_fps) seconds, so on
frame-dense sources it collects more candidates than extract_t and
the > extract_t fixup re-spreads the picks uniformly with
np.linspace -- that fallback is the intended reference behavior, not
an accident. Short clips (fewer frames than extract_t) are spread at
evenly spaced timestamps (floor sampling; the linspace variant
samples frames unevenly and cost 4 points on video grounding evals).
Request overrides: target_fps -> fps interval, max_frame_count
-> frame cap.
Molmo2VideoBackend
¶
Bases: VideoLoader
Methods:
-
get_candidate_target_fps–Return the subset of
video_fpsfactors that remain multiples -
get_target_fps–Get the target fps that best spans the video and samples the most
get_candidate_target_fps(video_fps, sampling_fps, max_fps=8.0)
classmethod
¶
Return the subset of video_fps factors that remain multiples
of sampling_fps.
Examples:
>>> get_candidate_target_fps(video_fps=6, sampling_fps=2)
[2, 6]
>>> get_candidate_target_fps(video_fps=5, sampling_fps=1)
[1, 5]
>>> get_candidate_target_fps(video_fps=2, sampling_fps=2)
[2]
>>> get_candidate_target_fps(video_fps=5, sampling_fps=2)
Traceback (most recent call last):
...
ValueError: sampling_fps=2 must divide video_fps=5 to produce
consistent frame steps.
get_target_fps(video_fps, max_frames, total_frames, frame_sample_mode, candidate_target_fps)
classmethod
¶
Get the target fps that best spans the video and samples the most frames.
PyNvVideoCodecVideoBackend
¶
Bases: VideoBackend
Hardware-accelerated video backend using PyNvVideoCodec.
The backend first opens the stream only to read metadata and compute the
sampled frame indices. It then acquires the raw decoded RGB byte count from
the process-local multimodal GPU memory pool before decoding the selected
frames into VRAM. Decoded frames are copied into pinned host memory before
the lease is released, so downstream preprocessing continues to receive a
CPU np.ndarray in NHWC RGB format.
Qwen2VLVideoBackend
¶
Bases: VideoBackend
Qwen2-VL / Qwen2.5-VL fps-based video backend.
Ports transformers' Qwen2VLVideoProcessor.sample_frames (fps mode),
shared by Qwen2-VL and Qwen2.5-VL (the latter has no video processor of its
own): sample total / original_fps * fps frames, clamp to
[min_frames, max_frames] (4 and 768), floor to a multiple of
temporal_patch_size (2), and take indices with the exact
torch.arange(0, total, total / n) call so they match HF byte-for-byte.
num_frames is ignored (fps-driven, like the Qwen3-VL loader). The
float32 step can emit an out-of-range tail index (e.g. 451 for a 451-frame
clip); it is clamped to the last valid frame.
VideoBackend
¶
Bases: VideoLoader
Uniform-sampling video backend.
Samples num_frames uniformly across the video (or one frame every
1/fps seconds, whichever produces fewer frames). The decoding codec
is selected via the backend kwarg ("opencv", "torchcodec",
"pynvvideocodec", or "deepstream"),
which can be passed through --media-io-kwargs. Defaults to "opencv".
Methods:
-
load_bytes–Load sampled frames from raw video bytes.
load_bytes(data, num_frames=-1, fps=-1, max_duration=300, frame_recovery=False, *, backend='opencv', **kwargs)
classmethod
¶
Load sampled frames from raw video bytes.
Parameters:
-
(data¶bytes) –Raw video bytes.
-
(num_frames¶int, default:-1) –Target number of frames to sample (
-1for all). -
(fps¶int, default:-1) –Target FPS for sampling (
-1for original). -
(max_duration¶int, default:300) –Maximum duration in seconds — only used by the dynamic subclass; ignored here.
-
(frame_recovery¶bool, default:False) –Enable forward-scan recovery for failed frames. Only honored by the OpenCV codec.
-
(backend¶VideoDecoderBackend, default:'opencv') –Decoding codec —
"opencv","torchcodec","pynvvideocodec"or"deepstream". -
(kwargs¶Any, default:{}) –Codec-specific options, validated against and forwarded to
backend:num_ffmpeg_threads(TorchCodec): number of FFmpeg decoding threads;0(default) relies on the FFmpeg default value which ismin(cpu_count + 1, 16). OpenCV will always usemin(cpu_count, 16).seek_mode(TorchCodec):"exact"(default) guarantees frame-accurate sampling by scanning the file on creation, while"approximate"skips that scan for faster decoder creation at the cost of relying on the file's metadata. See https://meta-pytorch.org/torchcodec/stable/generated_examples/decoding/approximate_mode.html for details.device(TorchCodec):"cpu"(default) decodes on the host and returns anp.ndarray;"cuda"decodes with NVDEC and returns the frames as a CUDAtorch.Tensor, which a device-side HF video processor can consume without a host round-trip.hw_decoders(PyNvVideoCodec): maximum number of concurrent decoder slots. Defaults to 2 and must be a positive integer.max_width/max_height(PyNvVideoCodec): optional maximum input dimensions configured for each decoder. Both must be positive integers and set together. Values are clamped to each codec's hardware limits. By default, decoder dimensions also cover the input's opposite orientation when that fits the reserved memory and hardware limits.pool_size/timeout_sec(DeepStream): decoder pool size and pool acquisition timeout in seconds.
Returns:
-
DecodedFrames–Tuple of
(frames, metadata_dict), whereframesis a -
dict[str, Any]–CPU
np.ndarrayunless TorchCodec decodes ondevice="cuda".
VideoLoader
¶
Methods:
-
compute_frames_index_to_sample–Return the list of frame indices to sample from the video.
-
load_bytes–Load video frames from bytes and return (frames, metadata_dict).
_prepare_source(source)
classmethod
¶
Sampling-algorithm-specific metadata adjustment hook.
compute_frames_index_to_sample(source, target, **kwargs)
classmethod
¶
Return the list of frame indices to sample from the video.
load_bytes(data, **kwargs)
abstractmethod
classmethod
¶
Load video frames from bytes and return (frames, metadata_dict).
frames is a CPU np.ndarray unless a GPU decoding codec is
used (e.g. torchcodec with device="cuda"), in which case it is
a torch.Tensor living on that device.
VideoLoaderRegistry
¶
Bases: ExtensionManager
Methods:
-
register_gpu_codec–Mark a codec name as requiring GPU without registering a loader.
register_gpu_codec(name)
¶
Mark a codec name as requiring GPU without registering a loader.
_frame_nbytes(frames)
¶
Size in bytes of one frame of frames.