Extending a Self-Hosted Multimodal Inference Service with Video Input

    This article explains how to add video understanding capabilities to a self-hosted multimodal inference service that originally supports only text and images. It identifies three gaps—request protocol, temporal preprocessing, and multi-frame visual encoding—and presents a reusable extension approach that maximizes reuse of existing components while isolating new logic in pluggable modules. Readers will learn how to extend request schemas, implement video decoding and frame sampling, adapt visual encoders for multi-frame input, and unify sequence assembly for autoregressive generation, along with practical engineering recommendations for deployment, validation, observability, and fallback.

    Extending a Self-Hosted Multimodal Inference Service with Video Input

    As official multimodal model APIs increasingly expose video understanding capabilities, more businesses want equivalent functionality in private environments: sending a user-uploaded video directly to a locally deployed model to obtain descriptions, question answering, or summaries. However, a typical self-hosted inference service supports only text and images—request parsing, preprocessing, encoding, and sequence assembly are all designed around these two modalities. When teams try to pass in video directly, they often find that the server either returns a parameter error or silently ignores the video content. This article starts from this “last mile” problem and outlines a complete, reusable approach for extending video input support.

    1. Why Video Input Is Missing

    Before making changes, it helps to clarify the gap. A standard multimodal inference pipeline roughly works as follows: text is tokenized and embedded into vectors; images are read, decoded into pixels, resized, normalized, split into patches, fed into a visual encoder to obtain features, mapped by a feature projection module into the language model’s hidden dimension, and finally concatenated with text vectors at placeholder positions in the prompt to form a unified sequence.

    Video has gaps at three main points in this pipeline:

    1. The request layer does not recognize video formats. Existing request structures typically have only text fields and image fields. Video files (or lists of video frames) have nowhere to go and are dropped or rejected at the gateway layer.
    2. The preprocessing layer lacks temporal handling. Video is not “one large image” but a sequence of frames arranged in time. Decoding, frame sampling strategies (uniform sampling, per-second sampling, truncation by maximum frame count), and preservation and encoding of temporal order between frames—these logic components are entirely absent from a pure text-image pipeline.
    3. The visual encoding layer lacks multi-frame adaptation. Even if weights can be reused, the visual encoder must correctly handle the shape organization and temporal position information of multi-frame input. Otherwise, extracted frames are treated as a batch of unrelated images, losing the critical semantic of “what happens before and after.”

    In other words, what is missing is not a single capability but an end-to-end path spanning request protocol, preprocessing pipeline, and encoding logic.

    2. Overall Approach: Reuse First, Fill Gaps Incrementally

    A pragmatic extension principle is: avoid touching components that don’t need changes, and consolidate new logic into independent plugins.

    • Reuse visual encoder weights. Video visual encoding typically shares the backbone network with image encoding. The difference lies only in how input frames are organized and in temporal position embeddings. There is no need to train or load a second model for this.
    • Reuse the feature projection module. The mapping layer from visual features to the language model’s hidden dimension is modality-agnostic. Video features go through the same projection path after encoding.
    • Reuse sequence assembly logic. Video placeholders in prompts are handled the same way as image placeholders. The final input remains a unified “text vectors + visual vectors combined by position” structure.
    • Make new logic pluggable. Video decoding, frame sampling, temporal chunking, and multi-frame encoding adaptation are encapsulated as pluggable components that do not intrude into the inference framework’s core code, making maintenance easier as the framework version upgrades.

    The benefit is that after integrating the plugin, text, images, and video enter the same local inference service, sharing one set of model weights and one scheduling system. Operational cost does not grow linearly with the number of modalities.

    3. Implementation Details for Key Stages

    3.1 Request Protocol Extension

    First, introduce video fields into the request structure. A common industry approach is to allow clients to pass a video file URL, binary data, or an already-preprocessed frame sequence. After identifying video input during parsing, the server routes it to the video preprocessing pipeline while preserving the existing text and image paths for backward compatibility. An example structure is shown below:

    1. {
    2. "messages": [
    3. {
    4. "role": "user",
    5. "content": [
    6. {"type": "text", "text": "Please describe the events in this video"},
    7. {"type": "video_url", "video_url": {"url": "file:///data/sample.mp4"}}
    8. ]
    9. }
    10. ]
    11. }

    The protocol layer also needs to define resource limits, such as the maximum video duration per request and the maximum number of sampled frames, to prevent excessively long videos from consuming GPU memory and scheduling resources.

    3.2 Decoding, Frame Sampling, and Temporal Chunking

    Video preprocessing is the part of the pipeline that requires the most new work. It can be divided into three steps:

    Decoding and frame sampling. Use a general-purpose multimedia decoding library to decode video into image frames, then sample according to a strategy. Common strategies include uniform sampling (taking N frames at equal intervals), fixed frame rate sampling (e.g., 1 frame per second), and truncating long videos by duration before sampling. Strategy parameters should be deployment-level configuration rather than hardcoded, because different business requirements vary greatly in temporal granularity—event localization in surveillance video needs denser sampling, while meeting recording summaries can accept sparse sampling.

    Preserve temporal order. Extracted frames must carry their temporal position in the original video (frame number or timestamp) and must not be shuffled. This is the essential difference between video and “a batch of images.”

    Temporal chunking. Organize sampled frames into chunks according to configuration, with each chunk serving as an input unit for visual encoding. The chunking method determines how temporal position information is injected: one approach attaches embedding vectors corresponding to temporal positions to each frame; another allows inter-frame features to interact through attention mechanisms within a chunk. Either way, the goal is to let the downstream language model perceive “what happens first and what happens later.”

    3.3 Multi-Frame Visual Encoding Adaptation

    The organized frame sequence and image pixels enter the shared image preprocessing flow (resizing, padding, normalization, patch splitting), then enter the visual encoder. There are two adaptation points here:

    • Input shape extension. The encoder originally handles [batch, channels, height, width] and now needs to handle an additional frame dimension [batch, frames, channels, height, width], ensuring that frame features within a chunk are correctly aggregated or that temporal structure is preserved.
    • Temporal position information injection. On top of reusing spatial position embeddings, add position encoding along the temporal dimension so that the encoder’s output features contain both visual content and the temporal order of frames.

    After encoding, video features—like image features—pass through the projection module to the language model’s hidden dimension and enter the unified sequence assembly stage. From the language model’s perspective, video is just another segment of “visual tokens” and requires no special handling.

    3.4 Unified Sequence Assembly and Generation

    The final step is identical to the text-image pipeline: tokenized text vectors and projected visual vectors are concatenated into an input sequence according to placeholder positions in the prompt, then passed to the language model for autoregressive generation. One engineering detail to note: video token counts are typically several times those of images (number of frames × patches per frame). Reserve a sufficient context window and correctly account for and queue video requests by token volume at the scheduling layer to prevent individual large requests from degrading overall throughput.

    4. Engineering Recommendations

    1. Codify deployment configurations as recipes. Organize model weight versions, frame sampling parameters, chunking strategies, and resource limits into a deployment recipe that can be enabled with one click in production, avoiding behavioral inconsistencies caused by environment differences. On cloud container platforms and model service products such as Baidu AI Cloud, such recipes can be standardized for delivery and canary releases.
    2. Build an end-to-end validation set. Prepare video samples covering different durations and scenarios, and compare answer consistency between the self-hosted service and official APIs under the same prompts. Focus on validating temporal understanding questions (“what happened at second X” and “the order of events”).
    3. Provide observability. Connect decoding latency, frame count, video token proportion, and GPU memory usage to general logging and monitoring/alerting systems. Performance bottlenecks in the video pipeline often appear in decoding and preprocessing rather than in model forward computation.
    4. Define fallback strategies. When video decoding fails or exceeds length limits, the service should return a clear error message or fall back to keyframe image understanding rather than failing silently.

    5. Conclusion

    Adding video input to a self-hosted inference service essentially means connecting the missing path of “request protocol—temporal preprocessing—multi-frame encoding—sequence assembly” while maximizing reuse of existing visual models, projection modules, and language models. Through plugin-based incremental changes and recipe-based one-click deployment, teams can achieve video understanding capabilities equivalent to official APIs in local production environments without overturning the existing inference architecture. The lessons from this approach also apply to future integration of other modalities such as audio: by adhering to the principle of “reuse the backbone, consolidate the increment,” the cost of multimodal expansion remains controllable.