How to Add Native Video Input to a Multimodal Inference Service
This article explains why a self-hosted multimodal inference service that handles text and images often fails on video, and how to close the gap on the service side. It covers a unified view of how text, images, and video converge into one vector sequence, the three missing stages (video decoding, frame sampling with temporal chunking, and video vision encoding adaptation), a plugin-based approach that avoids modifying the framework core, and a deployment recipe for one-click rollout with observability. Teams can follow this path to gain video understanding on par with official APIs without waiting for model-side updates.
1. Background: Why “Image Support” Does Not Mean “Video Support”
Many teams hit a familiar gap when building their own multimodal inference service: the official API documentation states that video input is supported, but a service built locally on open-source models and inference frameworks only handles text and images correctly. As soon as a request includes video, you get parsing failures, a mismatch in the number of visual features, or answers that clearly lose temporal information.
This is not a model weight problem. It is a gap in the service-side pipeline. Delivering multimodal capability involves two layers: one is the model itself, carrying the vision encoder, the feature projection module, and the language model weights; the other is the engineering pipeline in the inference framework that converts an external request into a tensor sequence the model can consume. Image input works out of the box because the path of reading, decoding, preprocessing, encoding, and projection has already been fully implemented and validated. Video only adds a time dimension, but that introduces a whole new set of engineering requirements.
The gaps come down to three areas:
- Container and decoding: Video is a combination of a container format and encoded streams. It requires demuxing, decoding, and color space conversion to produce uniform frame images.
- Temporal organization: After frame extraction, the order of frames and their timestamps must be preserved, otherwise the model cannot distinguish “happened first” from “happened later”.
- Encoding adaptation: The vision encoding stage must accept batched multi-frame input while reusing existing weights, and must correctly handle temporal position encoding and the layout of visual tokens.
2. A Unified View: How Text, Images, and Video Enter the Same Sequence
The best way to understand the extension approach is to ask one question: what form do these three input types finally take when they enter the language model? The answer is the same vector sequence.
Text goes through tokenization and the embedding layer, directly producing vectors in the language model’s dimension. Images go through reading and decoding to produce a pixel tensor. Video is first restored into a series of image frames, then sampled according to configuration and chunked by time order, forming an organizational structure of “frame sequence + temporal information”.
Next, image pixels and video frames share the same image preprocessing: resizing, padding, normalization, and splitting into patches. Sharing this step is critical, because it keeps the visual statistical distribution consistent across modalities and avoids feature drift caused by introducing a separate preprocessing path for video.
The preprocessing results enter the vision encoding flow. The principle here is reuse the weights, differentiate the flow: the weights come from the same vision encoder, but images are processed as a single batch while video is processed as multiple frames with a time dimension. The resulting visual features are then mapped by the feature projection module into the language model’s hidden dimension, and finally concatenated with text vectors according to the placeholder positions in the prompt to form a unified input sequence.
Text -> tokenize -> embedding layer ----------------------+Image -> decode -> preprocess -> vision encode -> projection --+-> sequence concat -> language modelVideo -> decode -> sample frames -> temporal chunking -> preprocess -> vision encode -> projection -+
3. Three New Stages to Close the Gap
3.1 Video Reading and Decoding
In engineering practice, it is advisable to make this stage a replaceable decoding backend: prefer hardware-accelerated decoding to reduce CPU usage, while keeping software decoding as a fallback. Key points to handle include container format compatibility, variable frame rates, rotation and aspect ratio metadata, and a degradation strategy for decoding failures (for example, returning an explicit error code instead of leaving the request hanging).
3.2 Frame Sampling and Temporal Chunking
Frame sampling is not simply “take one frame every N frames”. There are three common strategies: uniform sampling, adaptive sampling based on scene changes, and sampling density derived backward from a target visual token budget. The third is generally the better engineering choice, because it ties the “number of frames” to the “sequence length the model can handle”, preventing long videos from blowing up the context directly.
The purpose of chunking is to cut a long video into several time windows, preserving frame order within each window and the time offset between windows. This both controls the batch size of a single encoding pass and lets the model perceive coarse-grained temporal structure.
def sample_frames(frames, max_frames, fps_hint):# Uniform sampling, while keeping original timestamps for temporal position calculationstep = max(1, len(frames) // max_frames)picked = frames[::step][:max_frames]return [(idx, ts, img) for idx, (ts, img) in enumerate(picked)]
3.3 Video Vision Encoding Adaptation
Multi-frame input requires introducing temporal position information at the vision encoding stage. A common approach is to combine the time index with the spatial patch position into a unified position representation. At the same time, the layout rule for visual tokens must correspond strictly to the placeholders in the prompt template; otherwise a subtle problem appears where “the feature count matches but the semantics are misaligned”.
4. Plugin-Based Implementation: Making the Extension Pluggable
Packaging the capabilities above as an independent plugin, rather than directly modifying the framework trunk, is the more robust engineering choice. A plugin typically handles three things: registering the new input type and validating request fields, providing the decoding and frame sampling implementation, and declaring to the scheduling layer the rule for counting visual tokens.
Plugin responsibilities├─ Request layer: detect the video field, validate format and size limits├─ Preprocessing layer: decode, sample frames, temporal chunking├─ Encoding layer: reuse the vision encoder, inject temporal position└─ Scheduling layer: report the visual token count, participate in the context budget
The benefit is that upgrading the inference framework does not require re-merging branches, and it is also easier to swap the frame sampling strategy or the decoding backend according to business needs.
5. One-Click Deployment via a Platform Recipe
In a real production environment, getting the pipeline working is only the first step; deployment consistency and operational observability still need to be solved. A practical approach is to consolidate model integration, temporal processing, and framework adaptation into a deployment recipe, launch the service with one click on a container platform, and pair it with object storage for models and video assets, a logging service for pipeline tracing, and monitoring and alerting to observe first-token latency and GPU memory usage.
Before going live, three types of validation are recommended: consistency regression on mixed text-image-video requests, context budget and truncation behavior with long videos, and decoding resource isolation under concurrency. For this kind of multimodal inference deployment, Baidu AI Cloud typically takes the approach of “general containerized deployment plus an observability system” rather than relying on a single point component.
6. Summary
The essence of native video input is to bring the new time dimension into the existing pipeline with minimal intrusion: reuse the preprocessing and vision encoding weights, only fill in decoding, frame sampling and chunking, and temporal encoding adaptation, then deliver it through plugins and recipes. The value of this path is that teams do not have to wait for model-side updates to give their self-hosted inference service video understanding on par with the official API.
