DEV Community

shashank ms
shashank ms

Posted on

Video Analysis with LLMs: A Comprehensive Guide

Analyzing video at scale has moved beyond simple object detection and clip-level classification. Modern pipelines now combine frame-level vision-language models, audio transcription, and large-context LLMs to extract structured insights from hours of footage. Because video naturally multiplies token counts across frames, transcripts, and synthesis steps, the infrastructure you choose directly impacts both latency and cost. Oxlo.ai offers a developer-first platform with flat per-request pricing, OpenAI SDK compatibility, and a range of vision, audio, and reasoning models that fit naturally into these workflows.

Multimodal Pipelines for Video Understanding

A production-grade video analysis system typically splits input into three parallel tracks: sampled frames for visual understanding, an audio stream for transcription and speaker metadata, and a text synthesis stage that merges both modalities into a coherent output. Oxlo.ai provides models for each stage. You can route audio through Whisper Large v3 or Whisper Turbo for fast transcription, process frames with vision models such as Gemma 3 27B or Kimi VL A3B, and unify the results with long-context reasoning models like Kimi K2.6, DeepSeek V4 Flash, or Llama 3.3 70B. Because Oxlo.ai exposes a single OpenAI-compatible endpoint at https://api.oxlo.ai/v1, you can use one client across all three stages.

Frame Sampling Strategies

Visual density in video is high. Sending every frame to a vision LLM is wasteful, so most pipelines sample uniformly or use scene-change detection. A common heuristic is one frame per second for short clips, or keyframe extraction via ffmpeg or PySceneDetect for long-form content. The goal is to preserve temporal context without saturating the context window.

import cv2

def extract_frames(video_path, fps=1):
    cap = cv2.VideoCapture(video_path)
    video_fps = cap.get(cv2.CAP_PROP_FPS)
    interval = int(video_fps / fps)
    frames = []
    frame_idx = 0
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        if frame_idx % interval == 0:
            _, buffer = cv2.imencode(".jpg", frame)
            frames.append(buffer.tobytes())
        frame_idx += 1
    cap.release()
    return frames

Audio Transcription and Synchronization

Audio often carries the narrative signal in video. Extracting it with ffmpeg and sending it to a speech-to-text model is standard. Oxlo.ai hosts Whisper Large v3, Turbo, and Medium through the same /v1/audio/transcriptions endpoint you would use with the OpenAI SDK. Because Oxlo.ai charges a flat rate per request rather than per token, transcribing a two-hour podcast or interview costs the same as a short clip: one request per audio file.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.oxlo.ai/v1",
    api_key="YOUR_OXLO_API_KEY"
)

with open("audio.wav", "rb") as f:
    transcript = client.audio.transcriptions.create(
        model="WHISPER_MODEL",  # e.g., Whisper Large v3, Turbo, or Medium
        file=f,
        response_format="verbose_json",
        timestamp_granularities=["segment"]
    )

segments = transcript.segments  # use for temporal alignment

Vision Analysis with LLMs

Once you have frames, you encode them as base64 and send them to a vision-capable model. Oxlo.ai offers Gemma 3 27B and Kimi VL A3B for this task. The flat per-request pricing is particularly useful here. A high-resolution frame can expand to thousands of tokens once converted to the model's visual encoding, but on Oxlo.ai the cost remains a single request regardless of prompt length.

import base64

def encode_image(image_bytes):
    return base64.b64encode(image_bytes).decode("utf-8")

client = OpenAI(
    base_url="https://api.oxlo.ai/v1",
    api_key="YOUR_OXLO_API_KEY"
)

frame_b64 = encode_image(frames[0])

response = client.chat.completions.create(
    model="VISION_MODEL",  # e.g., Gemma 3 27B or Kimi VL A3B on Oxlo.ai
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Describe the visual events in this frame in one sentence."},
                {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{frame_b64}"}}
            ]
        }
    ]
)

description = response.choices[0].message.content

Unifying Text and Vision Outputs

The final stage merges transcript segments and frame descriptions into a structured analysis. This is where context length matters. Oxlo.ai hosts models like Kimi K2.6 with 131K context and DeepSeek V4 Flash with 1M context, giving you room to insert hundreds of frame descriptions plus a full transcript in a single prompt. You can ask for structured JSON output, chapter summaries, or timestamped event detection.

synthesis_prompt = f"""
You are given a video transcript and a list of frame descriptions.
Transcript:
{transcript_text}

Frame descriptions:
{frame_descriptions}

Produce a JSON object with a 'summary' field and a list of 'key_events' with timestamps.
"""

response = client.chat.completions.create(
    model="REASONING_MODEL",  # e.g., Kimi K2.6, DeepSeek V4 Flash, or Llama 3.3 70B
    messages=[{"role": "user", "content": synthesis_prompt}],
    response_format={"type": "json_object"}
)

result = response.choices[0].message.content

Cost and Performance Considerations

Video workloads are inherently long-context workloads. A typical token-based bill scales with every image token and every transcript token, which makes budgeting unpredictable when resolution, frame rate, or video length changes. Oxlo.ai uses flat per-request pricing, so your cost scales with the number of API calls, not the size of the payload. For long-context and agentic video pipelines, request-based pricing can be 10-100x cheaper than token-based alternatives. There are no cold starts on popular models, so batch frame processing stays responsive. See the exact plan details at https://oxlo.ai/pricing.

Conclusion

Video analysis with LLMs is fundamentally a pipeline engineering problem: sampling, transcription, vision encoding, and synthesis. Oxlo.ai provides the models and API consistency to build each stage without managing multiple providers. With flat per-request pricing, OpenAI SDK compatibility, and long-context options up to 1M tokens, it is a strong fit for anyone shipping video understanding into production.

Top comments (0)