> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-codex-docs-audit-20260719-0149.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Video Caption Agent

> Extract audio, transcribe it to timed SRT captions with OpenAI, and embed captions with MoviePyVideoTools.

Create an agent that extracts audio from a video, generates timestamped SRT captions, and embeds them into the output video.

```python video_caption.py theme={null}
from pathlib import Path
from sys import argv

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.moviepy_video import MoviePyVideoTools
from openai import OpenAI

video_tools = MoviePyVideoTools(
    enable_process_video=True,
    enable_generate_captions=False,
    enable_embed_captions=True,
)


def transcribe_audio_to_srt(audio_path: str, output_path: str) -> str:
    """Transcribe an audio file to a timestamped SRT file."""
    with open(audio_path, "rb") as audio_file:
        captions = OpenAI().audio.transcriptions.create(
            model="whisper-1",
            file=audio_file,
            response_format="srt",
        )

    Path(output_path).write_text(captions, encoding="utf-8")
    return output_path


video_caption_agent = Agent(
    name="Video Caption Generator Agent",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[video_tools, transcribe_audio_to_srt],
    instructions=[
        "Follow the requested file paths exactly.",
        "Call extract_audio, then transcribe_audio_to_srt, then embed_captions.",
        "Return the captioned video path.",
    ],
)


if __name__ == "__main__":
    if len(argv) != 2:
        raise SystemExit("Usage: python video_caption.py /path/to/input.mp4")

    video_path = Path(argv[1]).expanduser().resolve()
    if not video_path.is_file():
        raise SystemExit(f"Video not found: {video_path}")

    audio_path = video_path.with_suffix(".wav")
    srt_path = video_path.with_suffix(".srt")
    output_path = video_path.with_name(f"{video_path.stem}_captioned.mp4")

    video_caption_agent.print_response(
        f"""Process this video using the exact paths below.
Video: {video_path}
Audio: {audio_path}
SRT: {srt_path}
Captioned video: {output_path}"""
    )
```

<Note>
  Agno v2.7.4 uses Arial for embedded caption text. Install Arial before running this example on a system that does not include it.
</Note>

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno moviepy openai
    ```
  </Step>

  <Step title="Install FFmpeg">
    Install [FFmpeg](https://ffmpeg.org/download.html), then verify the executable:

    ```bash theme={null}
    ffmpeg -version
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    ```bash theme={null}
    export OPENAI_API_KEY="your_openai_api_key"
    ```
  </Step>

  <Step title="Run the agent">
    ```bash theme={null}
    python video_caption.py /absolute/path/to/input.mp4
    ```
  </Step>
</Steps>
