Moviepy Video Tools

Extract audio, transcribe it, and embed SRT captions into a video with MoviePyVideoTools.

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.

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

Set up your virtual environment

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

Install dependencies

uv pip install -U agno moviepy openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

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.

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.

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"
        )

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.

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)
)

Run the example

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

python moviepy_video_tools.py

Word highlighting divides each SRT cue evenly among its words; it is not measured word-level speech timing. See the complete captioning example for the assembled workflow.

Full source: cookbook/91_tools/moviepy_video_tools.py