How to Add Native Video Input to a Multimodal Inference Service

    This article explains why a multimodal inference service that already handles text and images often fails on video requests, and how to close that gap incrementally. It walks through the unified pipeline where text, image, and video inputs merge into a single sequence, then details the three video-specific stages to add: decoding video into frames, sampling frames with temporal chunking, and adapting the vision encoder with temporal position information. It also covers a plugin-based integration approach, deployment trade-offs around memory, throughput, caching, and observability, plus a checklist of common mistakes such as dropping frame order or leaving frame counts unbounded.

    \n## 1. Background: Why the Image Path Works but Video Still Cannot Get In\n\nIn multimodal LLM engineering, text and image inputs are usually the first two paths teams get working. Text is tokenized and embedded before entering the language model; images are decoded, preprocessed, visually encoded, and projected so they map reliably into the language model’s hidden space. But when stakeholders ask for something like “let the model watch a screen recording of an operation” or “describe events in a surveillance clip,” teams often find that the existing inference service either errors out or silently degrades on video requests.\n\nThe reason is not mysterious. Video is not a new modality: in terms of information form, it is equivalent to “a set of image frames with timestamps.” The gap is in the middle of the path, between receiving the request and fusing features: who decodes the container, what strategy selects frames, how the selected frames retain their temporal order, how multiple frames are organized into input the vision encoder accepts, and how temporal position information is injected. None of these stages has a counterpart in the image path, so they cannot be switched on through configuration.\n\nThis article takes a general engineering perspective and lays out a practical way to fill the gap. The core idea is incremental change rather than a rewrite: reuse the existing image preprocessing, vision encoder weights, and feature projection modules, add only the three video-specific stages, and plug them into the inference framework.\n\n## 2. The Overall Pipeline: How Text, Image, and Video Merge into One Sequence\n\nBefore looking at the extension points, it helps to be clear about how the three input paths eventually converge.\n\n- Text path: tokenization produces token IDs, and the embedding layer turns them into language model input vectors.\n- Image path: the input is read and decoded into pixel data, then enters image preprocessing.\n- Video path: the input is read and decoded into a frame sequence, frames are sampled according to configuration, chunked in temporal order, and the original order of sampled frames is preserved.\n\nImage pixels and the organized video frames share the same image preprocessing: resizing, padding, normalization, and patch splitting. Then comes the vision encoding stage. The key design here is shared weights with a split flow: the encoder parameters are the same set, but an image is processed as a single batch, while video frames carry a temporal dimension and position information.\n\nThe resulting visual features are mapped by the feature projection module into the language model’s hidden dimension, and are finally concatenated with the text vectors at the placeholder positions defined in the prompt, forming a unified input sequence for the language model. Roughly:\n\npython\n# Pseudocode: three input paths converging\ntext_vec = embed(tokenize(prompt)) # [L, H]\nimg_vec = projector(vit(preprocess(image))) # [P_img, H]\nvid_vec = projector(vit(preprocess(frames), # [P_vid, H]\n temporal_pos=frame_ids))\nseq = merge_by_placeholder(text_vec, img_vec, vid_vec)\nlogits = llm(seq)\n\n\n## 3. The Three Stages to Add Incrementally\n\nThe existing image path already has preprocessing, encoding, projection, and generation. Supporting video only requires three additions.\n\n### 3.1 Reading and Decoding Video into Frames\n\nThe video in a request may arrive as a binary stream or as a reference address. The decoding layer needs to handle container parsing, locating the video stream, and color space conversion, and output a unified pixel format. Engineering recommendations: cap the maximum decode resolution and maximum frame count to avoid memory spikes from overly long videos; and return an explicit error code for segments that cannot be decoded instead of silently returning empty frames.\n\n### 3.2 Frame Sampling and Temporal Chunking\n\nFrame sampling is the first gate on both quality and cost. Common strategies include uniform sampling, keyframe sampling, and scene-change sampling. Whichever is used, the original temporal order of the sampled frames must be preserved, because the later temporal position encoding depends on it. Temporal chunking then splits the frame sequence into overlapping or non-overlapping segments, keeping the number of frames encoded at once bounded while maintaining cross-segment understanding through the relationships between chunks:\n\npython\nframes = decode(video, max_res=720, max_frames=64)\nidx = uniform_sample(len(frames), k=32) # or keyframe / scene-based selection\nchunks = temporal_chunk(frames[idx], size=8, overlap=2)\n\n\n### 3.3 Adapting the Vision Encoding for Video\n\nThe vision encoder itself can reuse the image weights, but the input tensor gains a temporal dimension, so temporal position information must be introduced to let the model distinguish “which frame” it is looking at. In practice, temporal encoding can be added on top of the patch embeddings, or the frame index can be supplied as an additional position channel. Take care to keep numerical consistency with the image path, so the same image does not produce a different feature distribution depending on which path it takes.\n\n## 4. Plugin-Based Integration: Keeping Changes Inside the Boundary\n\nTo reduce intrusion into the main inference framework, it is advisable to package the video capability as a standalone plugin exposing three standard actions: request preprocessing, feature construction, and cache cleanup. The narrower the contract between the plugin and the framework, the safer later upgrades become.\n\npython\nclass VideoInputPlugin:\n def preprocess(self, request): ... # decode, sample frames, chunk\n def build_features(self, frames): ...# preprocess + encode + project\n def cleanup(self, ctx): ... # release intermediate tensors\n\n\nOnce the plugin is registered, text, image, and video all enter the same local inference service, with no need to spin up a separate model process for video. This is the engineering value of “reusing the existing model”: only one copy of the weights resides in GPU memory.\n\n## 5. Key Deployment and Runtime Trade-Offs\n\n- GPU memory and batching: the number of video frames directly amplifies activations on the vision side, so chunked encoding over the frame dimension followed by concatenation is recommended to control the peak.\n- Throughput and latency: frame count, chunk size, and overlap ratio together determine the time per request and need tuning against business SLAs.\n- Caching strategy: for repeated requests on the same video, decoded and encoded results can be cached; set eviction rules and a capacity limit.\n- Observability: build monitoring and alerts for decode failure rate, average sampled frame count, and visual token length, so quality regressions are easy to locate.\n- Consistency checks: compare features and outputs before and after the change using the same set of image samples to ensure the image path has not regressed.\n\n## 6. Common Pitfalls and a Troubleshooting Checklist\n\n1. Sampling frames without preserving order: scrambled temporal positions can make the model invert cause and effect, so always verify frame order.\n2. No cap on frame count: long videos can blow up GPU memory, so a hard limit and a degradation strategy are mandatory.\n3. Inconsistent preprocessing: video frames normalized with different parameters than images cause feature drift.\n4. Swallowed errors: returning empty input on decode failure leads the model to produce meaningless answers, so errors should be raised explicitly.\n5. Misplaced prompt placeholders: inserting visual vectors at positions that do not match the text placeholders causes semantic misalignment.\n\n## 7. Conclusion\n\nNative video input is not about replacing the image path. It is about completing the four-stage pipeline of “decode, sample frames, organize in time, encode multiple frames” on top of existing visual capability, and integrating it into a unified inference service in a plugin-based way. As long as a team holds to three principles, weight reuse, contained boundaries, and observable parameters, it can give a self-built multimodal service video understanding aligned with official interfaces at a relatively low modification cost, while making controllable trade-offs among quality, cost, and latency.