How to Add Native Video Input to Multimodal Inference Services
This article explains why supporting video is harder than supporting images in a multimodal inference pipeline, and how to close the engineering gaps without forking existing weights. It walks through how text, image, and video paths converge into a single token sequence, then details the three capabilities you need to add: video decoding into frames, frame sampling with temporal chunking, and multi-frame inference tuning. It also covers a plugin-based design that keeps the main service untouched, practical cloud deployment and operations advice, and a layered validation strategy to confirm the pipeline is correct before launch.
1. Background: Why “Video Support” Is Harder Than “Image Support”
As multimodal large models move into production, many teams have already built local inference pipelines for text and images. But when a business team asks “can we just pass in a video directly?”, the existing service often cannot respond. The problem is not that the model lacks visual capability. The gaps are in the engineering pipeline: the variety of video container and codec formats, the choice of frame sampling strategy, the temporal organization across frames, and the memory and latency pressure caused by an exploding number of visual tokens.
Some model vendors already support video input through their official APIs. However, teams that self-deploy and simply reuse the default configuration of community open-source weights and inference frameworks usually find that the existing pipeline only covers text and images. If you force a video in as a set of concatenated “multiple images”, it may run, but the temporal order information is lost, and the model’s understanding of actions, causality, and shot transitions degrades noticeably.
So what needs to be filled in is not a single function, but a complete processing pipeline that runs from request intake to visual feature fusion. This pipeline should reuse the existing image preprocessing, visual encoding, and feature projection modules as much as possible, avoiding duplicate implementations and weight divergence.
2. The Overall Pipeline: How Text, Images, and Video Feed Into the Same Language Model
To understand the extension, first look at how the three modalities ultimately become vector sequences the language model can consume.
- Text path: after tokenization, you get token IDs, which are mapped through an embedding layer into vectors of the language model’s hidden dimension.
- Image path: pixel data is obtained by reading and decoding, enters image preprocessing, and is then mapped to the language model’s hidden dimension through the vision encoder and feature projection module.
- Video path: the video is first demuxed and decoded into image frames, frames are sampled according to configuration, and chunked by temporal order while preserving the order of sampled frames; it then shares the image preprocessing and vision encoder weights with the image path, differing only in how it is organized.
The outputs of the three paths are finally concatenated into a unified input sequence according to placeholder positions in the prompt. The value of this design is that there is only one set of vision encoder weights, shared by images and video, which avoids training or loading a separate vision tower for video and significantly reduces memory usage and deployment complexity.
The following illustrative pseudocode expresses the core idea of “placeholder replacement”:
# Pseudocode: assembling the multimodal input sequencedef build_input(prompt, text_ids, image_embeds, video_embeds):seq = []for part in prompt.parts:if part.type == "text":seq.append(text_embedding(text_ids[part.span]))elif part.type == "image":seq.append(image_embeds[part.image_index])elif part.type == "video":# video_embeds are already organized in temporal orderseq.append(video_embeds[part.video_index])return concat(seq)
3. Three Key Pieces You Need to Add
When reusing the existing image pipeline, the new capabilities can be summarized in three points.
3.1 Reading and Decoding Video Into Frames
Video sources in production are complex: uploaded files, addresses in object storage, streaming segments, and so on. Engineering-wise, you should add a layer of abstraction that decouples the “input source” from the “decoding implementation”, with a unified output of a frame sequence and frame rate metadata. Three things matter in the decoding stage. First, format compatibility: common container and codec formats need to be covered. Second, performance: prefer hardware decoding and zero-copy paths, and avoid keeping all frames resident in memory. Third, failure observability: decoding exceptions should carry clear error codes and context, making it easier to determine whether the cause is a corrupted file, an unsupported codec, or a timeout.
3.2 Frame Sampling and Temporal Chunking
Frame sampling is not simply “take one frame every N frames”. A reasonable strategy needs to account for video duration, the target visual token budget, and the task type: short videos can use a higher sampling density to preserve detail, while long videos need lower density combined with chunking. The point of temporal chunking is to organize consecutively sampled frames into several time windows, keeping order within each window and preserving the sequence between windows, so the model can capture local actions while also having a global sense of time. The recommendation is to make the “target token budget” an explicit parameter, constrained jointly by sampling and chunking, so the number of visual tokens does not spiral out of control.
3.3 Multi-Frame Inference Adaptation
Multi-frame input brings two practical problems: peak memory usage and time to first token. Possible approaches include encoding chunks and incrementally concatenating visual vectors, pooling or compressing visual tokens, and limiting the maximum number of frames per request at the scheduling layer. In addition, the prompt template needs to align with the video placeholder, ensuring the temporal order is genuinely reflected in the sequence rather than disrupted by irrelevant separators.
4. Plugin-Based Packaging: Extending Capabilities Without Touching the Core
Packaging the pipeline above as an independent plugin is key to controlling complexity. The plugin exposes a unified contract externally: the input is a normalized request, and the output is a sequence of visual vectors plus metadata. Internally, it handles decoding, sampling, chunking, and preprocessing orchestration. There are three benefits. First, the core inference service does not need to be aware of video details. Second, the plugin can be upgraded and rolled back independently. Third, images and video share the vision encoder weights, and the plugin only handles the difference in “how things are organized”.
A simplified plugin interface sketch:
class VideoInputPlugin:def preprocess(self, request) -> VideoTensors:frames, meta = decode(request.source)sampled = sample_frames(frames, budget=request.token_budget)chunks = temporal_chunk(sampled, window=request.window)pixels = shared_image_preprocess(chunks)return pixels, metadef encode(self, pixels):feats = shared_vision_encoder(pixels) # weights shared with the image pathreturn projector(feats) # map to the LLM hidden dimension
5. Deployment and Operations in the Cloud
Taking these capabilities into production requires general cloud capabilities rather than reliance on a specific proprietary interface.
- Resources and scheduling: run the inference service on a container platform, choose instance specifications based on memory requirements, and use elastic scaling to handle peaks in video requests.
- Input and storage: video files can be placed in object storage and pulled by reference on the service side, avoiding oversized request bodies; a cache layer can be added for hot videos to reduce repeated decoding overhead.
- Observability: log decoding time, number of sampled frames, visual token count, and queue time in a logging service; set thresholds for memory usage, time to first token, and failure rate in monitoring and alerting.
- Rate limiting and quotas: set maximum frame counts and concurrency limits per user or tenant to prevent long videos from dragging down overall throughput.
- Version management: model weights, the vision encoder, and plugin versions must be traceable, with canary releases to reduce the risk of changes.
If you use the relevant general capabilities of Baidu AI Cloud, you can deploy the model service on a container platform, host input files in object storage, and build a closed-loop operations workflow with logging, monitoring, and alerting, turning “video input” from a one-off adaptation into a sustainable service capability.
6. Validation and Tuning: How to Tell Whether the Pipeline Is Actually Correct
Before going live, it is recommended to establish layered validation. The first layer validates the correctness of decoding and sampling, checking whether frame order and timestamps are monotonic. The second layer validates the consistency of visual vectors with the image path: the same frame going through the image path and the video path should produce similar representations. The third layer is end-to-end task evaluation, covering action recognition, temporal question answering, and shot transition understanding. For tuning, adjust the token budget and chunking window first, then consider visual token compression strategies, and only touch model-side configuration last, to avoid introducing unnecessary variables.
7. Conclusion
The essence of native video input is introducing the dimension of “time” into the multimodal inference pipeline at an engineering-affordable cost. By reusing the existing vision encoder and feature projection, isolating complexity with a plugin, and constraining resources with an explicit token budget, teams can upgrade capabilities without overturning the existing service, and deploy, observe, and govern it in a standardized way in the cloud, so that a local inference service truly has video understanding aligned with official APIs.
