Module video_preprocess

Module video_preprocess 

Source
Expand description

2026-09-25: Video to patch tensor, the temporal counterpart of crate::vision_preprocess.

Owner: model-layers (vision input). Invariants:

  • Every group of a PreprocessedVideo has the same grid_h × grid_w plane, from one target size chosen from the first kept frame.
  • preprocess_video returns at least one full temporal group or an error.

The flattened patch dimension is C × temporal_patch_size × patch², so a patch spans tp frames. A still image fills that axis by repeating itself tp times (preprocess_image); a video of n sampled frames becomes grid_t = n / tp temporal groups, each a full patch plane built from tp consecutive frames. The encoder takes each group as one image. grid_t is carried, not flattened away, because MRoPE advances T once per group of a video and holds it constant across an image.

The decoder is chosen by magic bytes, not the declared MIME: GIF decodes in-process; everything else goes to the opt-in ffmpeg subprocess (video_decode_ffmpeg).

Structs§

PreprocessedVideo
2026-09-25: A decoded, ready-to-encode video.

Constants§

DEFAULT_FPS
2026-09-25: Frames per second to sample at when the caller gives no usable rate. The Qwen3-VL-30B-A3B checkpoint’s video_preprocessor_config.json declares fps: 2.
DEFAULT_MAX_FRAMES
DEFAULT_MIN_FRAMES
2026-09-25: Sampling floor and ceiling, as min_frames: 4 and max_frames: 768 in the same video_preprocessor_config.json.

Functions§

decode_frames
2026-09-25: Decode every frame of a container, choosing a backend by what the bytes are.
preprocess_video
2026-09-25: Full pipeline: a base64 data: URI holding an animated container becomes temporal groups of patches.
sample_indices
2026-09-25: Pick which frame indices to keep so the clip plays at fps.