MoviePy Video Tools

Kern MoviePyVideoTools enable an Agent to process videos, extract audio, generate SRT caption files, and embed rich, word-highlighted captions.

Prerequisites

To use MoviePyVideoTools, you need to install moviepy and its dependency ffmpeg:

1uv pip install moviepy ffmpeg

Important for Captioning Workflow: The create_srt and embed_captions tools require a transcription of the video's audio. MoviePyVideoTools itself does not perform speech-to-text. You'll typically use another tool, such as OpenAITools with its transcribe_audio function, to generate the transcription (often in SRT format) which is then used by these tools.

Example

The following example demonstrates a complete workflow where an agent uses MoviePyVideoTools in conjunction with OpenAITools to:

  1. Extract audio from a video file
  2. Transcribe the audio using OpenAI's speech-to-text
  3. Generate an SRT caption file from the transcription
  4. Embed the captions into the video with word-level highlighting
1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.moviepy_video import MoviePyVideoTools
4from kern.tools.openai import OpenAITools
5
6video_tools = MoviePyVideoTools(
7 process_video=True, generate_captions=True, embed_captions=True
8)
9
10openai_tools = OpenAITools()
11
12video_caption_agent = Agent(
13 name="Video Caption Generator Agent",
14 model=OpenAIResponses(
15 id="gpt-5.2",
16 ),
17 tools=[video_tools, openai_tools],
18 description="You are an AI agent that can generate and embed captions for videos.",
19 instructions=[
20 "When a user provides a video, process it to generate captions.",
21 "Use the video processing tools in this sequence:",
22 "1. Extract audio from the video using extract_audio",
23 "2. Transcribe the audio using transcribe_audio",
24 "3. Generate SRT captions using create_srt",
25 "4. Embed captions into the video using embed_captions",
26 ],
27 markdown=True,
28)
29
30video_caption_agent.print_response(
31 "Generate captions for {video with location} and embed them in the video"
32)

Toolkit Functions

These are the functions exposed by MoviePyVideoTools:

FunctionDescription
enable_extract_audioExtracts the audio track from a video file and saves it to a specified output path.
enable_create_srtSaves a given transcription (expected in SRT format) to a .srt file at the specified output path.
enable_embed_captionsEmbeds captions from an SRT file into a video, creating a new video file with word-level highlighting.

Toolkit Params

These parameters are passed to the MoviePyVideoTools constructor:

ParameterTypeDefaultDescription
process_videoboolTrueEnables the extract_audio tool.
generate_captionsboolTrueEnables the create_srt tool.
embed_captionsboolTrueEnables the embed_captions tool.

Developer Resources