# Moviepy Video Tools (/examples/tools/moviepy-video-tools)



The source pipeline needs timestamped transcription and a usable caption font. `OpenAITools.transcribe_audio` returns plain text, while `create_srt` only writes the string it receives. Apply the changes below to produce timed captions.

```python title="moviepy_video_tools.py"
"""
Moviepy Video Tools
=============================

Demonstrates moviepy video tools.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.moviepy_video import MoviePyVideoTools
from agno.tools.openai import OpenAITools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


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

openai_tools = OpenAITools()

video_caption_agent = Agent(
    name="Video Caption Generator Agent",
    model=OpenAIChat(
        id="gpt-5.6-luna",
    ),
    tools=[video_tools, openai_tools],
    description="You are an AI agent that can generate and embed captions for videos.",
    instructions=[
        "When a user provides a video, process it to generate captions.",
        "Use the video processing tools 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 Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    video_caption_agent.print_response(
        "Generate captions for {video with location} and embed them in the video"
    )
```

## Run the Example [#run-the-example]

<Steps>
    <Step title="Set up your virtual environment">
      <CodeBlockTabs defaultValue="Mac">
        <CodeBlockTabsList>
          <CodeBlockTabsTrigger value="Mac">
            Mac
          </CodeBlockTabsTrigger>

          <CodeBlockTabsTrigger value="Windows">
            Windows
          </CodeBlockTabsTrigger>
        </CodeBlockTabsList>

        <CodeBlockTab value="Mac">
          ```bash
          uv venv --python 3.12
          source .venv/bin/activate
          ```
        </CodeBlockTab>

        <CodeBlockTab value="Windows">
          ```bash
          uv venv --python 3.12
          .venv\Scripts\activate
          ```
        </CodeBlockTab>
      </CodeBlockTabs>
    </Step>

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

  <Step title="Export your OpenAI API key">
    <CodeBlockTabs defaultValue="Mac/Linux">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Mac/Linux">
          Mac/Linux
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Windows">
          Windows
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Mac/Linux">
        ```bash
        export OPENAI_API_KEY="your_openai_api_key_here"
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Windows">
        ```bash
        $Env:OPENAI_API_KEY="your_openai_api_key_here"
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </Step>

  <Step title="Prepare the video and font">
    Provide a local video with an audio track, an existing writable output directory, and an installed `.ttf` or `.otf` font. Install the FFmpeg executable with your system package manager and verify `ffmpeg -version` works. Replace `{video with location}` with the actual input path and specify the output directory in the prompt.
  </Step>

  <Step title="Request timed transcription">
    Replace `openai_tools = OpenAITools()` with this function and use `tools=[video_tools, transcribe_srt]` in the agent. Update instruction 2 to call `transcribe_srt`, and instruct the agent to stop on a failed tool result instead of writing an error as captions.

    ```python
    from openai import OpenAI

    def transcribe_srt(audio_path: str) -> str:
        """Return timestamped SRT for a local audio file."""
        with open(audio_path, "rb") as audio_file:
            return OpenAI().audio.transcriptions.create(
                model="whisper-1", file=audio_file, response_format="srt"
            )
    ```
  </Step>

  <Step title="Configure the caption font">
    Add this after constructing `video_tools`, replacing the font path with your own. The adapter does not forward the styling arguments of `embed_captions` to its renderer.

    ```python
    from functools import partial
    from pathlib import Path

    font_path = Path("/absolute/path/to/your/font.ttf")
    if not font_path.is_file():
        raise FileNotFoundError(font_path)
    video_tools.create_caption_clips = partial(
        video_tools.create_caption_clips, font=str(font_path)
    )
    ```
  </Step>

  <Step title="Run the example">
    Save the code above as `moviepy_video_tools.py`, then run:

    ```bash
    python moviepy_video_tools.py
    ```
  </Step>
</Steps>

Word highlighting divides each SRT cue evenly among its words; it is not measured word-level speech timing. See the [complete captioning example](/tools/toolkits/others/moviepy) for the assembled workflow.

Full source: [cookbook/91\_tools/moviepy\_video\_tools.py](https://github.com/agno-agi/agno/blob/8f36eaf2d18e91afa7b327eec66a3cd3685dcb87/cookbook/91_tools/moviepy_video_tools.py)
