How to Add Native Video Input to Multimodal Inference Services

    This article explains why self-hosted multimodal inference services often fall short on video support even when official APIs handle it, and how to close that gap. It presents a five-stage pipeline that treats video as a timestamped image sequence sharing the same backbone as text and images, along with practical guidance on frame sampling, temporal chunking, visual token budgets, and batching. The goal is to help teams build video-capable services that remain usable and cost-efficient in real production workloads.

    1. Background: Official APIs Work, So Why Do Self-Hosted Services Lag?

    Most mainstream multimodal LLM APIs already accept video input. However, teams that want to deploy models in their own environment and embed video capabilities into internal business systems often find that the default path across open weights and inference frameworks is incomplete. Take a common open source inference framework as an example: its native support typically covers two modalities, text and images. Text goes through tokenization and embedding, images go through decoding and visual encoding, and both are merged into the language model after feature projection. Video involves additional steps such as container parsing, temporal organization, frame sampling strategies, and multi-frame position encoding, which are usually missing from the default implementation.

    The direct consequence of this gap is that even when a caller passes video using the multimodal message format, the server may only pick up the first frame or ignore temporal information altogether. This significantly degrades the model’s understanding of actions, processes, and causal ordering. Filling in the video path is therefore not a matter of adding a check for one more file type. It requires changes across three layers: data preprocessing, temporal modeling, and inference scheduling.

    2. Overall Pipeline Design: One Backbone for Three Modalities

    A clear design principle is that video is not a separate modality but a sequence of images with timestamps. Based on this abstraction, the pipeline can be split into five stages.

    1. Request parsing and resource retrieval: identify video references in the message, support sources such as local paths, in-memory byte streams, and object storage addresses, and convert them uniformly into readable byte streams.
    2. Decoding and frame sampling: extract a number of frames from the video according to the configured sampling strategy, while retaining the timestamp for each frame.
    3. Temporal chunking: split the sampled frames into segments using a fixed window, so the model can see local continuous actions within a limited context while still perceiving the global order.
    4. Shared visual preprocessing: resize, pad, normalize, and split into image patches through exactly the same flow as images, so the existing visual encoder and projection layers can be reused.
    5. Fusion and generation: visual features are projected and aligned to the embedding space of the language model, concatenated with text embeddings, and passed to the decoding stage to generate a response.

    The processing logic can be sketched as follows:

    1. def build_multimodal_inputs(messages, cfg):
    2. parts = []
    3. for item in messages:
    4. if item["type"] == "text":
    5. parts.append(embed(tokenize(item["value"])))
    6. elif item["type"] == "image":
    7. parts.append(visual_embed(preprocess(decode(item["value"]))))
    8. elif item["type"] == "video":
    9. frames, ts = sample_frames(decode(item["value"]), cfg.fps, cfg.max_frames)
    10. chunks = temporal_chunk(frames, ts, cfg.window)
    11. feats = [visual_embed(preprocess(f)) for f in chunks]
    12. parts.append(merge_with_time_encoding(feats, ts))
    13. return concat(parts)

    3. Key Components

    3.1 Frame Sampling: Balancing Information and Cost

    Frame sampling directly determines token volume. Common approaches include fixed frame rate sampling, keyframe sampling, and adaptive sampling. Fixed frame rate is simple to implement and predictable in behavior. Keyframe sampling reduces redundancy but depends on the scene. Adaptive sampling can dynamically adjust density based on how drastically the picture changes. In practice, it is advisable to set both an upper limit on frames and a minimum interval, so that long videos do not overflow the context.

    3.2 Temporal Chunking and Position Information

    If all frames are flattened into a single sequence of image patches, the model struggles to tell their order apart. The value of chunking is that high temporal resolution is preserved within a chunk, while relative position is expressed across chunks through timestamps or time embeddings. This keeps the length of each encoding pass under control while preserving the semantics of what happened first and what happened later.

    3.3 Visual Token Budget and GPU Memory Control

    The GPU memory pressure introduced by video comes mainly from the number of visual tokens and activations. Available measures include lowering per-frame resolution, reducing the number of image patches per frame, pooling and compressing features of adjacent frames, and aligning dimensions at the projection layer. It is worth stressing that any compression causes loss of detail, so trade-offs should be made according to whether the business needs fine-grained recognition or overall understanding.

    3.4 Batching and Scheduling

    Video requests vary greatly in length, which can easily cause head-of-line blocking. Viable strategies include bucketing and batching by visual token size, setting up separate queues and timeout thresholds, and rejecting overly long inputs upfront or degrading them to a sparser frame sampling mode, in order to keep the service stable overall.

    4. Platform Implementation: From Components to One-Click Deployment

    Consolidating the changes above into a standalone plugin is key to lowering maintenance costs. The plugin exposes only a unified multimodal message interface externally, while internally handling decoding, frame sampling, chunking, and feature fusion, so it does not intrude on the core model code. On this basis, inference instances can be hosted on the container platform of Baidu AI Cloud, with object storage holding video and model files, and with logging services and monitoring alerts tracking metrics such as time to first token, queueing duration, and GPU memory usage, forming an observable and elastically scalable production environment.

    Before going live, three types of validation are recommended. First, temporal correctness: use samples with a clear order to check whether the model detects when the order is reversed. Second, long video stability: observe peak GPU memory usage and timeout rates. Third, regression consistency with the image and text path: ensure the new video branch does not affect existing capabilities.

    5. Conclusion

    The essence of native video input is injecting the time dimension into the existing multimodal backbone at a controllable cost. Reusing the visual encoder and projection layers can significantly reduce the cost of the changes, while frame sampling, chunking, token budgets, and scheduling strategies together determine how usable and economical the service is in real business scenarios.