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 that gap without retraining the model. It walks through the unified pipeline that turns text, images, and video into a single vector sequence, then details the three missing pieces: container demuxing and decoding, frame sampling with temporal chunking, and multi-frame visual encoding with temporal position adaptation. It also covers engineering concerns such as two-stage batching and scheduling, GPU memory governance, feature caching, observability metrics, and elastic degradation, plus pre-launch capability, consistency, and load validation. The takeaway is that reusing existing vision weights and projection modules turns a one-off change into a reusable deployment asset.
1. Background: Why “Image Support” Does Not Equal “Video Support”
When multimodal large models move into production, a common gap appears: the official API already accepts video input, but the team’s self-hosted inference service handles only text and images. The reason is not mysterious. Video is not a new data type; it is images extended along the time dimension. That extension brings three pressures at once: data volume, temporal semantics, and compute budget.
In the default path of most open-source inference frameworks, request parsing, image preprocessing, visual encoding, feature projection, and language model decoding are already in place. The gaps concentrate in three areas: demuxing and decoding containerized video, sampling and chunking frames for temporal structure, and adapting visual encoding and position information to multi-frame input. Fill those three gaps and video capability can “parasitize” the existing pipeline, with no model retraining required.
2. The Overall Pipeline: How Four Input Types Converge into One Sequence
The best entry point for understanding the extension is to observe how each modality eventually becomes a vector sequence the language model can consume.
- Text path: tokenization followed by a lookup that yields word vectors, which already carry position indices.
- Image path: decoded into a pixel tensor, then scaled, padded, normalized, and split into patches before entering the visual encoder.
- Video path: demuxed and decoded into a frame sequence, sampled and chunked by policy, then passed through the same preprocessing and encoding flow as images.
- Fusion stage: visual features are projected into the language model’s hidden dimension and interleaved with text vectors at the placeholder positions defined in the prompt.
Illustrative pseudocode summarizes this organization:
# Unified entry: normalize different modalities into a (seq_len, hidden) vector sequencedef build_input(request):text_emb = llm.embed(tokenize(request.prompt)) # text vectorsvision = []for image in request.images:vision.append(project(encode(preprocess(decode(image)))))for video in request.videos:frames = sample_frames(decode_video(video), policy="fps_or_uniform")chunks = temporal_chunk(frames, size=k, overlap=o) # preserve temporal orderfor chunk in chunks:vision.append(project(encode(preprocess(chunk))))return interleave(text_emb, vision, placeholders=request.mask)
The key point: video shares preprocessing and encoding weights with images; the only differences are how frames are organized and how temporal position is encoded. This makes the change incremental rather than a rewrite.
3. Three Pieces That Must Be Completed
3.1 Video Demuxing and Decoding
Video in production is usually wrapped in a container format, so it must be demuxed before being decoded into frames. Three engineering concerns matter. First, decoding determinism: the same input should produce a stable frame sequence, which makes reproduction and canary comparison possible. Second, resource isolation: decoding is CPU-intensive and should be decoupled from GPU inference, with queues or a separate process pool to smooth out spikes. Third, failure degradation: corrupted files, unsupported codecs, or excessive resolution should return an explicit error rather than silently producing empty frames.
3.2 Frame Sampling and Temporal Chunking
Sampling decides the tradeoff between “how much is seen” and “how much compute is spent.” Common strategies include fixed frame rate sampling, uniform sampling, and adaptive sampling based on scene changes. Uniform sampling is simple to implement and predictable, which makes it a good default; fixed frame rate stays closer to the real temporal resolution; adaptive sampling preserves key segments in long videos but adds decision cost.
Chunking controls the context length of a single encoding pass. Sampled frames are split in temporal order into several chunks, and overlap between chunks can mitigate information loss at boundaries. Note that chunking must strictly preserve temporal monotonicity; otherwise the model loses the order of actions.
def temporal_chunk(frames, size=8, overlap=2):step = size - overlapreturn [frames[i:i + size] for i in range(0, len(frames), step) if frames[i:i + size]]
3.3 Multi-Frame Visual Encoding and Temporal Position Adaptation
Multi-frame input raises two new problems: visual tokens grow linearly, and the model must distinguish “which frame” it is looking at. The first can be eased with more aggressive compression ratios, intra-chunk shared encoding, or token merging. The second requires adding a temporal dimension to position information so the model understands frame order rather than spatial position alone. If a purely 2D position assumption is kept, the model will misread multiple frames as a single jigsaw, and temporal understanding degrades significantly.
4. Engineering: Performance, GPU Memory, and Stability
The video path costs far more than the image path, so it must be designed for at the architecture level.
- Batching and scheduling: split decoding and encoding into a two-stage pipeline, scale the decode side horizontally by CPU core count, and batch dynamically on the encode side by available GPU memory, so long and short videos do not block each other.
- GPU memory governance: set a maximum frame count and maximum resolution for visual encoding, downsampling automatically when exceeded; for long videos, enable chunked streaming so intermediate tensors are released after each chunk is encoded.
- Cache reuse: cache features for repeated video segments, keyed by content digest, which significantly reduces cost in repeated question-answering scenarios.
- Observability: record decode time, number of sampled frames, visual token count, time to first token, and queue time as percentile metrics, making it easy to tell whether the bottleneck is decoding or encoding.
- Elasticity and degradation: automatically lower the default sampling density at traffic peaks, trading controlled quality loss for stable throughput.
5. Deployment Practice: From Recipe to Production
The value of a platform is turning these changes into reusable components and one-click deployment recipes. A typical flow: prepare model weights and a dependency image, create the inference service on the container platform, mount the model and sample videos from object storage, configure the number of decode worker processes and the maximum frame count, expose an endpoint compatible with the common request format, then connect logging and monitoring alerts to close the loop.
Three validations are recommended before launch. Capability validation covers short videos, long videos, videos without an audio track, and malformed files. Consistency validation feeds the same video as an image sequence and compares whether outputs stay stable. Load validation observes how time to first token and queue time percentiles change as concurrency rises, which determines the default sampling setting and the number of replicas.
6. Conclusion
The essence of native video input is接入 — bringing the time dimension into the existing modality pipeline with minimal intrusion. Reusing vision weights and the projection module, completing decoding and sampling, and introducing temporal position information are the three steps that give a local inference service video understanding on par with a cloud endpoint. Packaging this as a plugin and a deployment recipe turns a one-off change into an engineering asset the team can reuse over the long term.
