A Reusable LLM Pipeline for Automatic Visual Matching in Narrated Videos

    This article describes an engineering-oriented, reusable pipeline that uses large language models and multimodal models to assign visuals to narrated video scripts. It covers the four-layer architecture, semantic segmentation, intent extraction, retrieval and generation paths for visual assets, timeline alignment and rendering, modular interfaces, model evaluation, and practical constraints such as copyright, privacy, factual accuracy, and accessibility.

    1. Problem Background

    Narrated videos are a content format centered on a presenter on camera or a voice-over, supported by a limited amount of visuals. For this type of video, production cost is concentrated mainly in “finding visuals.” After writing a script, the creator must find a matching image, diagram, chart, or clip for each line of narration. This step depends heavily on experience, takes a long time, and the same asset set is difficult to reuse across different topics.

    If this process is handled collaboratively by large language models and multimodal models, the problem becomes a data pipeline. The input is timestamped text, and the output is visual descriptions or asset references aligned with the timeline. The following sections break down this pipeline from an engineering perspective.

    2. Overall Architecture: A Four-Layer Pipeline

    • Input layer: reads the narrated script or speech transcription result and preserves the start and end time of each sentence.
    • Semantic layer: splits the script into semantic units and extracts the core intent of each unit.
    • Visual layer: retrieves existing assets based on intent, or generates new visual descriptions.
    • Composition layer: inserts visuals into the narrated video according to the timeline and outputs an editable project file.

    The layers communicate through structured data. Any layer can be replaced or tested independently without affecting the operation of the other layers.

    3. Semantic Segmentation: Defining the Minimum Unit for a Visual

    Splitting directly by periods is often inappropriate. One line of narration may contain two independent concepts, while two lines may express only one concept. A more reliable approach is to use “one meaning that can be illustrated independently” as the segmentation unit, while limiting unit duration, for example to no more than 6 seconds.

    Segmentation can be performed by a model, but the output format must be constrained for downstream parsing. An example is shown below:

    1. {
    2. "segment_id": "s_012",
    3. "start_ms": 18400,
    4. "end_ms": 21150,
    5. "text": "Teams often slow down because processes are not transparent.",
    6. "intent": "Emphasize the impact of process transparency on efficiency",
    7. "visual_type": "process_diagram"
    8. }

    Field meanings need to be standardized within the team. visual_type should use a fixed enumeration, such as presenter on camera, data chart, process diagram, live-action photo, and abstract concept image. Once the enumeration values are fixed, downstream modules can dispatch tasks by type and avoid failures caused by unconstrained model output.

    4. Visual Intent Extraction

    Intent extraction determines the final result. For the same line, “we need to reduce costs,” a visual of gold coins gives the audience very little information; a before-and-after bar chart has a much higher information density.

    In practice, the model can be asked to output three types of information at the same time:

    1. Core concept: summarize the judgment this passage conveys in one sentence;
    2. Visualization mode: metaphor, comparison, process, data, or scene;
    3. Forbidden items: for example, avoid specific human faces and avoid numbers that could be misleading.

    Writing forbidden items explicitly can significantly reduce visuals that are noncompliant or conflict with the narration.

    5. Asset Acquisition: Retrieval and Generation Paths

    Visual sources fall into two categories.

    The retrieval path searches the existing asset library by tags, vector similarity, or keywords. Its advantages are controllable asset quality and clear licensing scope. Its disadvantage is limited coverage, especially for long-tail concepts. When assets are added to the library, the source, licensing scope, and tags should be recorded; otherwise, reuse later becomes difficult.

    The generation path calls image or video generation capabilities based on intent. Its advantage is broad coverage. Its disadvantage is unstable detail; text rendering, numbers, and logo-like elements are especially error-prone. Generated results need rule-based or manual validation, for example checking whether unwanted text appears in the visual.

    The recommended default strategy is: retrieve first, and generate only when retrieval confidence is below a threshold. Both types of results are kept in a candidate list for human confirmation before final composition.

    6. Timeline Alignment and Rendering

    Aligning visuals with narration depends on timestamps provided by speech transcription. Three points require attention during implementation:

    • Visual cuts should fall at pauses between sentences or at semantic boundaries, not in the middle of a word;
    • Adjacent visuals with similar content should be merged to avoid frequent jumps that cause visual fatigue;
    • Each visual should remain stable for at least 1 second so viewers can read the information.

    For rendering, it is advisable to output an editable project file rather than only a final video. Creators can then adjust an individual visual segment without rerunning the entire pipeline.

    7. Modular Design and Reuse

    Reusability comes from stable interfaces. Below is a simplified organization, intended only to illustrate the structure:

    1. class SegmentPlanner:
    2. def split(self, transcript: list[dict]) -> list[dict]:
    3. """Split the script according to semantic and duration constraints"""
    4. ...
    5. class IntentExtractor:
    6. def __init__(self, llm_client):
    7. self.llm = llm_client
    8. def extract(self, segment: dict) -> dict:
    9. """Return structured fields such as intent, visual_type, and forbidden"""
    10. ...
    11. class VisualResolver:
    12. def resolve(self, intent: dict) -> list[dict]:
    13. """Search the asset library first; use generation when confidence is insufficient"""
    14. ...
    15. class TimelineComposer:
    16. def compose(self, segments, visuals) -> str:
    17. """Output the path to an editable timeline project file"""
    18. ...

    Each class is responsible for one thing, and the model client is injected through constructor parameters. When changing the model, asset library, or rendering method, the main workflow code generally does not need to be modified. During testing, test cases can also be written for each class independently, using fixed inputs to check the output structure.

    8. Evaluation Method for Comparing Multiple Models

    Model selection should not rely on subjective impressions. It is advisable to build a fixed evaluation set containing dozens of real narrated scripts, covering different domains, sentence styles, and lengths. Run the same batch of inputs against each candidate model, then score along the following dimensions:

    1. Structural compliance rate: whether the output passes format validation and whether fields are complete;
    2. Intent accuracy: whether the core concept matches the original text, as judged independently by two annotators;
    3. Visual relevance: whether the visual matches the semantics of the narration;
    4. Forbidden-item compliance rate: whether prohibited elements appear;
    5. Cost and latency: token consumption and response time for processing a single segment.

    Evaluation records should include the model version, parameter settings, and evaluation date. Models iterate quickly, and behavior under the same name may change, so reproducible records are more valuable than a single conclusion.

    9. Common Issues and Considerations

    • Copyright: retrieved assets must retain licensing information, and generated assets must be checked against terms that permit commercial use.
    • People and privacy: unless authorized, avoid generating portraits of real people.
    • Factuality: for narration involving data, numbers in the visuals must be checked against the original text and must not be filled in by the model on its own.
    • Accessibility: important information should not rely solely on visuals; it should also be presented with captions.

    10. Summary

    Visual matching for narrated videos can be broken down into four stages: semantic segmentation, intent extraction, asset resolution, and timeline composition. The key to implementation lies in three points: connecting the layers with structured data, constraining model output with fixed enumerations, and comparing models with a unified evaluation set while retaining a human confirmation step. Once implemented in a modular way, the same pipeline can serve different topics and can also replace components incrementally as model capabilities improve.