How to Add Native Video Input to a Multimodal Inference Service

    This article explains why supporting images does not automatically mean supporting video in a self-hosted multimodal inference service, and how to close the gap without rewriting the model. It walks through how text, image, and video inputs converge into a single language model, then details the three incremental extension points: video reading and decoding, frame sampling with temporal chunking, and multi-frame vision encoding adaptation. It also covers plugin-based engineering, deployment recipes, production governance, and layered validation and tuning advice.

    1. Background: Why “Image Support” Does Not Equal “Video Support”

    In practice, teams running self-hosted multimodal inference services often hit a gap: the official API already accepts video input, but the local deployment pipeline only works for text and images. The reason is not mysterious — video is not a simple stack of images. It introduces new complexity across four layers: data reading, temporal organization, encoding adaptation, and request governance.

    In the default implementations of most open-source inference frameworks, the input side only covers text tokenization and single-frame image decoding; the vision side only handles preprocessing and encoding of a single image. Once a request contains video, the pipeline breaks in three places: reading and decoding, frame sampling and chunking, and multi-frame encoding adaptation. So the core idea for closing the gap is not to rewrite the model, but to extend the existing pipeline incrementally, so that text, images, and video share the same vision weights and language model backbone.

    2. Overall Pipeline: How Three Input Types Feed One Language Model

    Before looking at the extension points, it helps to be clear about how the three modalities eventually become a vector sequence the language model can consume.

    1. Text path: after tokenization you get token IDs, which are mapped through an embedding layer into vectors of the language model’s hidden dimension.
    2. Image path: reading and decoding produce a pixel tensor, which goes through image preprocessing (resize, padding, normalization, patch splitting); a vision encoder then extracts features, and a feature projection module maps them to the language model’s hidden dimension.
    3. Video path: the video is first decoded into a sequence of image frames, then sampled and chunked temporally according to configuration, preserving the time order of the sampled frames; it then reuses the image preprocessing and vision encoding weights, with adaptation only in how multiple frames are organized and in temporal position information.

    The outputs of the three paths are finally concatenated into a unified input sequence according to placeholder positions in the prompt:

    1. # Pseudocode: unified orchestration of multimodal inputs
    2. text_vec = embed(tokenize(prompt)) # [L, H]
    3. image_vec = projector(vision_encoder(preprocess(img))) # [P_img, H]
    4. video_vec = projector(vision_encoder(preprocess(frames)))# [P_vid, H]
    5. sequence = merge_by_placeholder(
    6. text_vec, image_vec, video_vec,
    7. layout=parse_media_slots(prompt) # insert based on placeholder positions
    8. )
    9. logits = llm.forward(sequence)

    The key point: the vision encoder and projection module are shared; video only changes how frames are organized before they enter the encoder.

    3. Three Incremental Extension Points

    3.1 Video Reading and Decoding

    The video content in the request must be turned back into image data that can be processed. Three things matter in engineering: the supported range of container and codec formats, decoding fault tolerance (corrupted frames, variable frame rate, rotation metadata), and resource limits (maximum duration, maximum resolution, maximum file size). It is advisable to decouple decoding from downstream preprocessing: decoding should only produce the frame sequence plus metadata (frame rate, duration, original dimensions).

    3.2 Frame Sampling and Temporal Chunking

    The goal of frame sampling is to balance information coverage against compute cost. Common strategies include uniform sampling, scene-change-based sampling, and keyframe-based sampling. Chunking organizes the sampled frames into several time windows so the model can perceive local temporal relationships. Here the time order of sampled frames must be preserved, and temporal position information must be passed explicitly to the encoding stage; otherwise the model will treat the video as an unordered set of images.

    1. def sample_frames(frames, target_count, fps):
    2. idx = uniform_indices(len(frames), target_count) # uniform sampling
    3. clips = chunk_by_time(idx, window=8) # temporal chunking
    4. return [frames[i] for i in idx], clips, fps

    3.3 Multi-Frame Vision Encoding Adaptation

    While reusing the existing weights, you need to handle the batch-dimension changes and temporal position encoding that multi-frame input brings. In practice, a “per-frame encoding plus temporal aggregation” approach works: reuse single-frame encoding to get per-frame features, then compress the token count via pooling or a lightweight aggregation layer over the time dimension, keeping the sequence length sent to the language model under control.

    4. Engineering: Plugin Architecture and a Deployment Recipe

    To keep the capability maintainable, the adaptation logic should be packaged as a standalone plugin decoupled from the main inference pipeline: request routing identifies the media type, the plugin handles decoding, sampling, chunking, and encoding adaptation, and the main pipeline only consumes unified vision vectors. On the deployment side, a “one-click recipe” approach can package model weights, plugins, and runtime parameters into a reusable template so a service can be brought up quickly on a container platform.

    Production readiness also requires governance:

    • Validate media type and enforce size/duration limits at the gateway layer;
    • Make long-video tasks asynchronous so they do not block the main inference queue;
    • Use logging services and monitoring alerts to track decode failure rate, sampling latency, time to first token, and GPU memory usage;
    • Do capacity planning based on observed data rather than guesswork.

    5. Validation and Tuning

    Validation should be layered: first unit-test the determinism of decoding and sampling, then verify the token count and ordering correctness of multi-frame encoding, and finally run end-to-end Q&A consistency regression. For tuning, start with the number of sampled frames and the chunking window, then consider visual token compression strategies; when GPU memory is constrained, reduce batch size or enable more aggressive token merging. Always treat “whether temporal information is preserved” as the correctness red line, and “whether per-request cost is under control” as the gate for going live.