Adding Video Input to Self-Hosted Multimodal Inference Services

    As more teams deploy multimodal large models in their own machines and network environments, self-hosted inference services often support text and images but not video. This article outlines the engineering path from request handling to visual feature fusion, covering the capability gap, how text, image, and video inputs feed into the language model, the four key video-processing stages, unified sequence assembly, a plugin-based adaptation structure, deployment steps, validation methods, and common issues.

    Adding Video Input to Self-Hosted Multimodal Inference Services

    More and more teams want to deploy multimodal large models on their own machines and networks. Online APIs from model providers often already support video input, but self-hosted services usually only cover text and images. To give a local service the same capability, the entire processing chain from request reception to visual feature fusion must be completed. This article examines that chain from an engineering perspective and explains how to implement the adaptation in a plugin-based way.

    1. Where Does the Capability Gap Come From?

    Early inference frameworks were mostly designed around text generation, and image input was added later. An image is single-frame pixel data, and its processing pipeline is relatively short: read, decode, preprocess, visual encode, and feature projection. Video is a sequence with a temporal dimension, which adds three stages: video decoding and frame sampling, temporal organization, and multi-frame feature fusion. If any one of these is missing, the service will either reject video requests or treat the video as a set of unordered images, losing temporal order.

    Therefore, when deploying an open-source model with a particular version of an inference framework, a common situation is this: the visual encoder and projection module in the model weights are already available, but the framework layer has no video reading or sampling logic. The problem is mainly on the input side; the model architecture itself usually does not lack the ability to process multiple frames.

    2. How Three Input Types Feed Into the Language Model

    To understand how video is processed, it helps to first see the final form of the three input types.

    Input type Decoded product Key processing Form entering the language model
    Text Token sequence Tokenization and embedding lookup Text embeddings
    Image Single-frame pixel matrix Resize, padding, normalization, patch splitting Visual embeddings
    Video Ordered frame sequence Frame sampling, temporal chunking, per-frame preprocessing Temporally organized visual embeddings

    Before an image enters the language model, it goes through a shared preprocessing pipeline, and then the visual encoder outputs features. The feature projection module (Projector) maps visual features into the hidden dimension of the language model so that they share the same vector space as text embeddings.

    Video can reuse this image pipeline. Each frame is preprocessed and encoded in the same way as an image. The new work for video is concentrated on the temporal dimension: deciding which frames to take and how to organize those frames into units with a clear order. This reuse avoids training a separate encoder for video and allows improvements in image capability to benefit video directly.

    3. Four Key Stages on the Video Side

    3.1 Reading and Decoding

    A video file is essentially a compressed bitstream packaged in a container format. It must first be demuxed and then decoded into image frames. This step needs to handle inconsistent frame rates, resolutions, and durations, as well as corrupted files.

    From an engineering perspective, validation should be performed at the entry point: limit file size and duration, allowlist container formats, and return clear errors early for abnormal files. If the video is passed in through a remote URL, timeouts and size limits should also be set, and the URL should be checked to ensure it is within an allowed range to prevent the service from being tricked into accessing internal network resources.

    3.2 Frame Sampling Strategy

    Frame sampling determines how many frames the model ultimately sees. It is the main trade-off between cost and information.

    • Fixed frame-rate sampling: Temporal resolution is stable, but the longer the video, the more frames and visual tokens are produced, and GPU memory usage and latency grow accordingly.
    • Fixed frame-count sampling: Resource cost has an upper bound, but actions that occur within a short period may be skipped.

    A common approach is to combine both: estimate the frame count based on a target frame rate, cap it with a maximum frame count, and sample uniformly across the full duration. This can be expressed as:

    1. actual_frames = min(ceil(video_duration * sample_fps), max_frames)

    The timestamps of the sampling points need to be retained for later use in generating time markers.

    3.3 Temporal Chunking

    Temporal chunking divides the sampled frames into several groups in chronological order; each group is called a chunk. Chunking serves two purposes: first, it preserves local temporal context so that adjacent frames can form representations of actions and changes; second, it controls the input size per encoding pass and avoids processing too many frames at once.

    Chunk size is a key parameter. The larger the chunk, the longer the time span within a single chunk, but the higher the encoding cost. The order between chunks must be strictly preserved, and the start and end times of each chunk should be carried as metadata into subsequent steps; otherwise, the model cannot determine the order of events.

    3.4 Per-Frame Encoding, Projection, and Optional Compression

    Each frame goes through the shared image preprocessing and is then fed into the visual encoder. The output features are mapped by the projection module into the language model dimension. When the number of visual tokens is large, pooling or merging can be performed along the temporal dimension to reduce the number of tokens entering the language model.

    This step must remain consistent with the settings used during model training, including input resolution, patch size, whether compression is used, and the compression method. When settings are inconsistent, output quality can degrade noticeably, and such problems usually do not raise direct errors, so they must be found through validation.

    4. Assembling a Unified Input Sequence

    The three input types ultimately need to be concatenated into a single sequence. The prompt template reserves visual placeholder positions, and during assembly, text embeddings and visual embeddings are filled into the corresponding positions in order.

    1. def build_inputs(segments):
    2. embeds = []
    3. for seg in segments:
    4. if seg.kind == "text":
    5. embeds.append(text_embedding(seg.token_ids))
    6. elif seg.kind == "image":
    7. pixels = preprocess(seg.pixels)
    8. embeds.append(project(encode(pixels)))
    9. elif seg.kind == "video":
    10. frames = sample_frames(seg.source, config)
    11. chunks = temporal_chunk(frames, config.chunk_size)
    12. for chunk in chunks:
    13. tokens = project(encode(preprocess(chunk.frames)))
    14. embeds.append(add_time_marker(tokens, chunk.timestamps))
    15. return concat(embeds)

    The code above is illustrative pseudocode; the function names are only used to explain the flow, and the actual implementation needs to align with the interfaces of the inference framework in use. The assembly stage also needs to handle three things: record the start and end positions of each visual segment in the sequence, ensure that the attention mask covers all visual tokens, and confirm that positional encoding is continuous across temporal chunks. Context length also needs to be estimated in advance. The number of video tokens grows linearly with the number of frames; when it exceeds the context window, the service should reject the request directly rather than silently truncating it.

    5. Engineering Structure for Plugin-Based Adaptation

    Making video capability an independent plugin is easier to maintain than modifying the core code of the framework directly. It is recommended to split the adaptation work into four modules:

    1. Request reception and validation: Identify the video content type and check format, size, and duration.
    2. Video preprocessing: Handle decoding, frame sampling, and chunking, and output frame groups with timestamps.
    3. Visual fusion interface: Call the shared image preprocessing, encoding, and projection, and return visual embeddings.
    4. Sequence assembly: Merge with text embeddings and generate the unified input.

    The modules interact through clear data structures. The benefits are that when the framework is upgraded, only the interface layer needs compatibility adjustments; each module can be unit-tested independently; and when problems occur, the service can quickly roll back to a state where the video plugin is disabled.

    6. Deployment Steps

    The implementation process can follow this order.

    1. Confirm version compatibility: Check whether the model weights include the visual encoder and projection module, and confirm that the inference framework version supports the required input structure.
    2. Install the adapter plugin: Follow the plugin instructions to complete installation and enable video input in the service configuration.
    3. Set frame sampling and chunking parameters: Refer to the sampling settings in model training or the official documentation; do not choose values arbitrarily based on experience.
    4. Run smoke tests: Cover short videos, long videos, videos without an audio track, corrupted files, oversized files, and invalid URLs, and confirm that each case returns the expected result.
    5. Monitor resource metrics: Record GPU memory usage, time to first token, and the number of visual tokens per request, and adjust parameters accordingly.

    An example configuration is shown below. The specific field names should follow the actual plugin documentation:

    1. video_input:
    2. enabled: true
    3. sample_fps: 1.0 # Target sampling frame rate
    4. max_frames: 32 # Maximum number of frames per request
    5. chunk_size: 4 # Number of frames per temporal chunk
    6. max_file_mb: 100 # Maximum size per file
    7. url_allowlist:
    8. - "<internal-storage-domain>" # Only remote addresses in this allowed range

    7. Validation Methods and Common Issues

    When validating video capability, do not only check whether the service returns a result; also confirm whether the model truly understands the visual content and temporal order. Prepare a set of samples with ground-truth answers, including descriptive questions (what appears in the scene), counting questions (how many times a certain object appears), and temporal questions (which of two events happened first). Temporal questions are the best way to expose problems with chunking and time markers.

    Common issues and handling approaches are as follows.

    Phenomenon Possible cause Handling approach
    Insufficient GPU memory Frame count or resolution too high Reduce the maximum frame count or lower the input resolution
    Temporal questions answered incorrectly Timestamps lost or chunk order scrambled Check the order and temporal metadata of the chunk output
    Decoding takes too long Original resolution too high Downsample during decoding or use hardware decoding
    Request rejected Visual tokens exceed the context window Reduce the frame count or adjust the chunking strategy
    Output quality noticeably degraded Preprocessing parameters inconsistent with training settings Check resolution and patch settings against the model documentation

    8. Conclusion

    Video input can be understood as adding a temporal dimension to the image pipeline. Reusing the visual encoder and projection module helps control the scope of changes. The parts that truly require effort are the frame sampling strategy, temporal chunking, retention of temporal information, and sequence assembly; these stages determine whether the model can correctly understand the content of a video and the order of events. Making video processing an independent plugin makes upgrades easier and also enables fast diagnosis and rollback when problems occur.