> ## 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.

# 视频字幕代理

## 代码

```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="视频字幕生成代理",
    model=OpenAIChat(
        id="gpt-4o",
    ),
    tools=[video_tools, openai_tools],
    description="您是一个可以为视频生成和嵌入字幕的人工智能代理。",
    instructions=[
        "当用户提供视频时，请处理以生成字幕。",
        "请按以下顺序使用视频处理工具：",
        "1. 使用 extract_audio 从视频中提取音频",
        "2. 使用 transcribe_audio 转录音频",
        "3. 使用 create_srt 生成SRT字幕",
        "4. 使用 embed_captions 将字幕嵌入视频",
    ],
    markdown=True,
)

video_caption_agent.print_response(
    "为 {视频位置} 生成字幕并将其嵌入视频中"
)
```

## 用法

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

  <Step title="设置你的API密钥">
    ```bash theme={null}
    export OPENAI_API_KEY=xxx
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U openai moviepy ffmpeg agno
    ```
  </Step>

  <Step title="运行代理">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/agent_concepts/multimodal/video_caption_agent.py
      ```

      ```bash Windows theme={null}
      python cookbook/agent_concepts/multimodal/video_caption_agent.py
      ```
    </CodeGroup>
  </Step>
</Steps>
