Making LLMs Understand Video: Local Preprocessing and Multimodal Practices

    Analyzing videos with Large Language Models (LLMs) goes beyond simply uploading full video files. This article explores a robust engineering approach using local preprocessing to convert continuous video into time-aligned images, text, and indexes. By building a verifiable "evidence package," developers can effectively manage resource consumption and enable accurate multimodal analysis. Key steps discussed include media integrity checks, keyframe extraction with sliding window deduplication, audio and subtitle synchronization, temporal alignment, and long video handling, ensuring that every AI-generated conclusion is traceable back to the original source.

    1. Define the Goal: Building a Verifiable Evidence Package, Not Just Playing Videos

    Analyzing video with Large Language Models (LLMs) doesn’t necessarily mean feeding the entire video file directly to the model. A more controllable approach for managing resource consumption and inspecting intermediate results is to use local preprocessing to convert continuous video into time-stamped images, text, and indexes, which are then analyzed by a model with appropriate input capabilities.

    This process can be summarized as:

    Video input → Media inspection → Visual and audio processing → Temporal alignment → Evidence package generation → Model analysis → Result verification.

    It is crucial to distinguish between two scenarios: models with visual input capabilities can analyze keyframe images, while text-only models cannot directly recognize images and require additional image captioning or OCR. Simply placing images into a folder does not mean the model can automatically read them; they must be loaded by the calling program or interactive environment.

    Therefore, the engineering goal is not simply to “compress a video into a few images,” but to preserve task-relevant evidence within the allowed budget so that every conclusion can be traced back to the original video.

    2. Input Inspection: Addressing Media Integrity First

    The first step in video preprocessing should be inspecting the file, not immediately extracting frames. Common risks include missing audio tracks, timestamp anomalies, variable frame rates (VFR), unhandled orientation tags, and subtitle desync.

    It is recommended to record the following information:

    • Total video duration, resolution, frame rate, and orientation;
    • Number of audio tracks, channel configurations, and audio duration;
    • Presence of subtitle tracks, their languages, and coverage;
    • Whether the file can be fully decoded and if there are obviously damaged segments;
    • The start times of the video, audio, and subtitles respectively.

    These metadata dictate how different modalities are aligned. For example, if the audio track starts at a non-zero point, using the transcript time directly as the video time will cause a global offset in the referenced locations. For VFR videos, frames should be located using media timestamps rather than estimating time by dividing the frame number by a fixed frame rate.

    If the input comes from external sources, access permissions, content licensing, and data retention requirements should be confirmed. For videos containing meeting discussions, customer data, or personal information, local processing helps reduce the exposure of raw materials but does not automatically eliminate the privacy risks associated with sending images and text to the model later.

    3. Keyframe Extraction: Balancing Scene Changes and Task Relevance

    3.1 Why Not Just Fixed-Interval Sampling

    Fixed-interval sampling is simple to implement and serves as a solid baseline coverage mechanism, but it may miss briefly appearing important information. For example, an error message in a UI might only flash momentarily, or a key button click in an operational demo might occur between two sampling intervals.

    Relying solely on scene detection also has limitations. Long, static scenes in tutorials, screen recordings, and fixed-camera videos may have stable overall compositions while their internal information continuously changes.

    A more robust approach is to combine methods:

    • Scene change detection: to capture obvious camera cuts;
    • Periodic sampling: to cover long, stable scenes;
    • Task-oriented supplementary sampling: to focus on text updates, UI state changes, or local actions.

    These three methods do not need to be enabled simultaneously; they should be selected based on content type. Interview videos focus more on the correspondence between speech and time, while operational demos typically require denser visual evidence.

    3.2 Scene Change ≠ Semantic Change

    Sudden brightness changes, fast panning, or transition effects might be detected as scene changes, but they don’t necessarily mean the content has substantively changed. Conversely, a small icon change on a static background might correspond to an important business state.

    Therefore, scene detection can only provide candidate timestamps and cannot replace task-specific judgment. For information-dense videos, necessary surrounding context should be retained alongside candidate frames to avoid capturing only transition screens.

    4. Sliding Window Deduplication: Controlling Redundancy Without Breaking Temporal Structure

    After keyframe extraction, a large number of similar images are usually generated. If not deduplicated, repetitive frames will consume the input budget and distract the model’s attention from key information.

    A basic method is to scale candidate images to a uniform size, calculate the pixel difference, and determine if they are duplicates. The Normalized Mean Absolute Difference can be expressed as:

    D(A,B) = Sum of absolute pixel differences ÷ Total number of pixels ÷ Pixel value range.

    A smaller difference indicates the two images are closer at the pixel level. However, pixel similarity does not equal semantic equality: cursor blinks, scrolling subtitles, and compression noise will increase the difference, while local digit changes might be diluted by the average of the whole image.

    4.1 Why Use a Sliding Window

    If you only compare with the previously retained image, oscillating between several similar states might result in a large number of duplicates being retained. A sliding window allows the current candidate frame to be compared against several recently retained frames, reducing local redundancy.

    However, it is not advisable to apply strict global deduplication across the entire video by default. The same frame reappearing at a different time might carry new contextual meaning. Deleting the latter occurrence can easily break the sequence of events.

    A more reasonable rule is: deduplicate within a local window while preserving the original timestamp, candidate frame source, and filter reason. For repetitive frames spaced far apart, whether to retain them should be decided by task requirements.

    4.2 Thresholds Must Be Validated by Samples

    There is no universal difference threshold suitable for all videos. Screen recordings, natural scenes, and animations have vastly different variation patterns. You should select representative segments to check for false deletions and missed deletions.

    If the task involves minor text changes, you can lower the deduplication intensity or separately compare important regions. The key principle is: saving input cost should not come at the expense of deleting core evidence.

    5. Audio and Subtitles: Prioritize Reuse, But Always Check Quality

    5.1 Evaluate Existing Subtitles First

    Existing subtitles can usually save the computational overhead of redundant transcription, but they should not be directly treated as an accurate ground truth. You need to check whether the subtitles are complete, contain reasonable timestamps, and have obvious typos, language mismatches, or content delays.

    Additionally, subtitles might be translations, summaries, or even edited. If the task requires verbatim verification of speech, you should clearly distinguish between “subtitle content” and “audio-generated transcript content” to avoid mixing them as the same type of raw evidence.

    When subtitles are missing or their quality does not meet requirements, use Automatic Speech Recognition (ASR) to generate transcripts. For segments with dense terminology, overlapping speakers, or strong background noise, uncertainty should be annotated in the results rather than filling in unheard content based on context.

    5.2 Retain Full Audio Tracks; Avoid Trimming Speech by Visual Changes

    Visual deduplication and audio retention should be independent of each other. No visual change does not mean no new speech; deleting duplicate images should not result in deleting the audio for that time period.

    Long audio tracks can be processed in segments, but it is recommended to keep a moderate overlap at segment boundaries to reduce the risk of sentences being cut off. When merging transcripts, the internal time of the segments needs to be converted back to the global video time, and duplicate text in overlapping areas must be cleaned up.

    It should also be recognized that transcription only preserves partial sound information. Tone, alerts, equipment anomalies, and ambient noise may not be accurately conveyed through text. If the analysis task relies on this information, additional audio analysis capabilities are required, and conclusions cannot be drawn solely from subtitles.

    6. Temporal Alignment: Organizing Images and Text into a Single Evidence Chain

    Having just images and transcript text is still insufficient to form a reliable input for video analysis. The key is to establish a unified timeline.

    Each keyframe should at least record the timestamp, image location, and extraction source; each text segment should record the start and end times, content source, and necessary quality notes. If the processing step does not provide reliable confidence scores, you should not fabricate seemingly precise numbers.

    When organizing the input, keyframes can be associated with subtitles within a nearby time range. However, this association only indicates temporal proximity, not that the text is necessarily describing the objects in the image. For example, a presenter might introduce the next step in advance or review previous content.

    Therefore, the model output should clearly distinguish:

    • Facts directly visible in the image;
    • Information explicitly stated in subtitles or transcripts;
    • Inferences formed by combining multiple pieces of evidence.

    For conflicting segments, the conflict should be preserved rather than forcefully generating a seemingly coherent explanation.

    7. Continuous Frame Stitching: Saving Input Organization Cost at the Risk of Detail Loss

    Stitching continuous keyframes into a grid in chronological order helps the model observe event progression and reduces the workload of organizing images individually. However, stitching does not guarantee a reduction in model-side processing costs; actual consumption depends on the input image size, tiling method, and the processing mechanism of the model used.

    When stitching, it is recommended to follow these principles:

    1. Label the timestamp and order on each sub-image to avoid unclear reading directions.
    2. Try to maintain the original aspect ratio to prevent UI and text distortion.
    3. Control the number of frames in a single grid to avoid text becoming illegible after shrinking.
    4. Retain independent keyframes for later zooming and verification.
    5. For text-dense content, prioritize using a few clear images rather than trying to fit more frames into a single image.

    Grid images are more suitable for observing stage changes and are not suitable as the sole basis for accurately reading small text. If the task involves continuous action judgment, sparse keyframes may also be insufficient to prove the complete action process, requiring a return to a denser frame sequence or the original clip.

    8. Evidence Package Design: Readable, Traceable, and Reproducible

    A practical output directory can contain four types of content: media metadata, keyframe images, time-stamped transcripts, and a unified manifest.

    The manifest is responsible for describing the relationships between files and recording preprocessing strategies. For example, which keyframes came from periodic sampling, which from scene change detection, whether image scaling and deduplication were applied, and what source was used for the transcript.

    This is a suggested data organization method, not a fixed interface for any existing system. In actual implementation, structured text or other common formats can be chosen based on the model’s calling environment.

    To facilitate troubleshooting, processing versions and task configurations should also be recorded. The same video might produce different results under different frame extraction strategies. Without configuration records, it is difficult to determine whether differences stem from the raw material, the preprocessing pipeline, or the model analysis stage.

    9. Long Video Processing: Build a Global Index First, Then Refine by Question

    Long videos should not be submitted by simply dumping all keyframes and text at once. A more controllable approach is hierarchical analysis:

    First, split segments by time or content boundaries and generate summaries and evidence indexes for each. Second, build a global structure based on these indexes. Finally, re-read high-resolution images and detailed transcripts from relevant segments based on specific questions.

    The hierarchical process should always retain the original evidence entry points. Summaries are secondary processed results; if only summaries are read later, omissions and misjudgments from the previous stage may be continuously amplified.

    For cross-segment questions, such as how an operation gradually evolved into an anomaly, multiple time periods need to be checked simultaneously rather than just selecting the segment with the best keyword match.

    10. Quality Assessment and Security Boundaries

    Evaluation cannot just look at whether the final summary is fluent. At least the following aspects need attention:

    • Information coverage: Are important frames, key speech, and brief events retained?
    • Temporal accuracy: Can the referenced location point to the corresponding evidence?
    • Deduplication quality: Were frames that look similar but have different meanings mistakenly deleted?
    • Conclusion verifiability: Did the model write speculation as fact?
    • Processing cost: Does the time, storage, and input size meet the budget?

    You can select a set of manually labeled segments to test different sampling and deduplication strategies and compare the retention of key events. Without actual testing, one should not claim that a certain solution has a fixed accuracy or cost advantage.

    Meanwhile, subtitles, on-screen text, and speech in the video should be treated as data to be analyzed, not as system instructions. Even if the content contains text demanding task changes, information leakage, or operation execution, it should not be granted instruction permissions. Steps involving external file reading, content uploading, or automatic execution should be completed through explicit authorization and access control.

    Conclusion

    Video understanding based on preprocessing essentially establishes a verifiable information conversion mechanism between continuous media and model inputs. Its value lies not only in reducing input size but also in preserving temporal relationships, clarifying evidence sources, and enabling the review of analytical conclusions.

    A reliable implementation requires simultaneously handling visual coverage, audio integrity, local deduplication, temporal alignment, and privacy boundaries. Only by linking these steps into a closed loop can video analysis be elevated from a one-time content summary to an engineering capability suitable for technical documentation compilation, teaching reviews, operational audits, and knowledge retrieval.