Video Caption Generation

Demonstrates team-based video caption generation and embedding workflow.

video_caption_generation.py
"""
Video Caption Generation
========================

Demonstrates team-based video caption generation and embedding workflow.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.team import Team
from agno.tools.moviepy_video import MoviePyVideoTools
from agno.tools.openai import OpenAITools

# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------
video_processor = Agent(
    name="Video Processor",
    role="Handle video processing and audio extraction",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[MoviePyVideoTools(enable_process_video=True, enable_generate_captions=True)],
    instructions=[
        "Extract audio from videos for processing",
        "Handle video file operations efficiently",
    ],
)

caption_generator = Agent(
    name="Caption Generator",
    role="Generate and embed captions in videos",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[MoviePyVideoTools(enable_embed_captions=True), OpenAITools()],
    instructions=[
        "Transcribe audio to create accurate captions",
        "Generate SRT format captions with proper timing",
        "Embed captions seamlessly into videos",
    ],
)

# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
caption_team = Team(
    name="Video Caption Team",
    members=[video_processor, caption_generator],
    model=OpenAIResponses(id="gpt-5.2"),
    description="Team that generates and embeds captions for videos",
    instructions=[
        "Process videos to generate captions in this sequence:",
        "1. Extract audio from the video using extract_audio",
        "2. Transcribe the audio using transcribe_audio",
        "3. Generate SRT captions using create_srt",
        "4. Embed captions into the video using embed_captions",
    ],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Team
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    caption_team.print_response(
        "Generate captions for {video with location} and embed them in the video"
    )

Before running

OpenAITools.transcribe_audio returns plain text, while MoviePyVideoTools.create_srt only writes the string it receives. It does not calculate timestamps or convert plain text into valid SRT. Replace OpenAITools() on the caption generator with this timestamped transcription tool, defined before constructing the members:

from openai import OpenAI

def transcribe_audio(audio_path: str) -> str:
    """Transcribe local audio into timestamped SRT captions."""
    with open(audio_path, "rb") as audio_file:
        return OpenAI().audio.transcriptions.create(
            model="whisper-1", file=audio_file, response_format="srt"
        )

Use tools=[MoviePyVideoTools(enable_embed_captions=True), transcribe_audio] on caption_generator. Pass the resulting SRT text unchanged to create_srt.

Install MoviePy 2.x and ensure its FFmpeg executable and a usable caption font are available. Both MoviePy toolkit instances enable all three video tools by default; setting one flag to True does not disable the others. The tool derives approximate word timings from SRT segments. For a deterministic local pipeline with input and output checks, use Video Caption.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno "moviepy>=2" openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Set the video path

Replace {video with location} in the prompt with the path to a local video file.

Run the example

Save the code above as video_caption_generation.py, then run:

python video_caption_generation.py

Full source: cookbook/03_teams/19_multimodal/video_caption_generation.py