> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MoviePy 视频工具

> Agno MoviePyVideoTools 使代理能够处理视频、提取音频、生成 SRT 字幕文件，并嵌入丰富的单词高亮字幕。

## 先决条件

要使用 `MoviePyVideoTools`，您需要安装 `moviepy` 及其依赖项 `ffmpeg`：

```shell theme={null}
pip install moviepy ffmpeg
```

**对字幕工作流的重要性：**
`create_srt` 和 `embed_captions` 工具需要视频音频的转录。`MoviePyVideoTools` 本身不执行语音到文本的转换。您通常会使用另一个工具，例如带有 `transcribe_audio` 函数的 `OpenAITools`，来生成转录（通常是 SRT 格式），然后由这些工具使用。

## 示例

以下示例演示了一个完整的流程，代理将 `MoviePyVideoTools` 与 `OpenAITools` 结合使用来：

1. 从视频文件中提取音频
2. 使用 OpenAI 的语音到文本功能转录音频
3. 从转录生成 SRT 字幕文件
4. 将字幕嵌入到带有单词级别高亮的视频中

```python theme={null}
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.moviepy_video import MoviePyVideoTools
from agno.tools.openai import OpenAITools

video_tools = MoviePyVideoTools(
    process_video=True, generate_captions=True, embed_captions=True
)

openai_tools = OpenAITools()

video_caption_agent = Agent(
    name="Video Caption Generator Agent",
    model=OpenAIChat(
        id="gpt-4o",
    ),
    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,
)


video_caption_agent.print_response(
    "Generate captions for {video with location} and embed them in the video"
)
```

## 工具包功能

这些是 `MoviePyVideoTools` 提供的函数：

| Function         | Description                              |
| ---------------- | ---------------------------------------- |
| `extract_audio`  | 从视频文件中提取音频轨道并将其保存到指定的输出路径。               |
| `create_srt`     | 将给定的转录（预期为 SRT 格式）保存到指定输出路径的 `.srt` 文件。  |
| `embed_captions` | 将来自 SRT 文件的字幕嵌入到视频中，创建一个带有单词级别高亮的新的视频文件。 |

## 工具包参数

这些参数将传递给 `MoviePyVideoTools` 构造函数：

| Parameter           | Type   | Default | Description             |
| ------------------- | ------ | ------- | ----------------------- |
| `process_video`     | `bool` | `True`  | 启用 `extract_audio` 工具。  |
| `generate_captions` | `bool` | `True`  | 启用 `create_srt` 工具。     |
| `embed_captions`    | `bool` | `True`  | 启用 `embed_captions` 工具。 |

## 开发者资源

* 查看 [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/moviepy_video.py)
* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/tools/moviepy_video_tools.py)
