203 lines
4.8 KiB
Markdown
203 lines
4.8 KiB
Markdown
# VideoLingo 命令行版本使用说明
|
||
|
||
本文档介绍如何使用 VideoLingo 的命令行版本(`run.py`),无需图形界面即可处理视频。
|
||
|
||
## 快速开始
|
||
|
||
### 1. 基本使用
|
||
|
||
编辑 `run.py` 文件中的参数:
|
||
|
||
```python
|
||
# 在 main() 函数中修改这些参数
|
||
INPUT_VIDEO_PATH = "path/to/your/video.mp4" # 您的视频路径
|
||
OUTPUT_DIR = "output" # 输出目录
|
||
INCLUDE_DUBBING = True # 是否包含配音
|
||
```
|
||
|
||
然后运行:
|
||
|
||
```bash
|
||
python run.py
|
||
```
|
||
|
||
### 2. 使用 VideoLingoProcessor 类
|
||
|
||
```python
|
||
from run import VideoLingoProcessor
|
||
|
||
# 创建处理器实例
|
||
processor = VideoLingoProcessor(
|
||
input_path="my_video.mp4",
|
||
output_dir="my_output"
|
||
)
|
||
|
||
# 执行完整处理(字幕 + 配音)
|
||
processor.process_all(include_dubbing=True)
|
||
|
||
# 或者只生成字幕
|
||
processor.process_all(include_dubbing=False)
|
||
```
|
||
|
||
## 核心功能
|
||
|
||
### VideoLingoProcessor 类
|
||
|
||
主要的处理器类,提供以下方法:
|
||
|
||
#### 初始化参数
|
||
|
||
- `input_path`: 输入视频文件路径(必需)
|
||
- `output_dir`: 输出目录路径(默认 "output")
|
||
|
||
#### 主要方法
|
||
|
||
- `process_all(include_dubbing=True)`: 执行完整处理流程
|
||
- `process_subtitles()`: 只处理字幕生成
|
||
- `process_dubbing()`: 只处理配音生成(需要先生成字幕)
|
||
- `cleanup_files()`: 清理临时文件
|
||
- `delete_dubbing_files()`: 删除配音相关文件
|
||
|
||
## 配置参数
|
||
|
||
### 修改配置文件
|
||
|
||
您可以直接编辑 `config.yaml` 文件,或在代码中使用 `update_key()` 函数:
|
||
|
||
```python
|
||
from core.utils.config_utils import update_key
|
||
|
||
# 修改目标语言
|
||
update_key("target_language", "简体中文")
|
||
|
||
# 修改 TTS 方法
|
||
update_key("tts_method", "azure_tts")
|
||
|
||
# 禁用字幕烧录
|
||
update_key("burn_subtitles", False)
|
||
```
|
||
|
||
### 常用配置项
|
||
|
||
| 配置项 | 描述 | 示例值 |
|
||
|--------|------|--------|
|
||
| `target_language` | 目标翻译语言 | `"简体中文"`, `"English"` |
|
||
| `tts_method` | TTS 方法 | `"azure_tts"`, `"edge_tts"`, `"openai_tts"` |
|
||
| `burn_subtitles` | 是否烧录字幕到视频 | `true`, `false` |
|
||
| `whisper.model` | Whisper 模型 | `"large-v3"`, `"medium"` |
|
||
| `whisper.language` | 原始语言 | `"en"`, `"zh"`, `"ja"` |
|
||
|
||
## 使用示例
|
||
|
||
### 示例 1: 基础字幕生成
|
||
|
||
```python
|
||
from run import VideoLingoProcessor
|
||
|
||
processor = VideoLingoProcessor(
|
||
input_path="english_video.mp4",
|
||
output_dir="chinese_subtitles"
|
||
)
|
||
|
||
# 只生成字幕,不配音
|
||
processor.process_all(include_dubbing=False)
|
||
```
|
||
|
||
### 示例 2: 完整处理(字幕+配音)
|
||
|
||
```python
|
||
from run import VideoLingoProcessor
|
||
|
||
processor = VideoLingoProcessor(
|
||
input_path="english_video.mp4",
|
||
output_dir="full_output"
|
||
)
|
||
|
||
# 生成字幕和配音
|
||
processor.process_all(include_dubbing=True)
|
||
```
|
||
|
||
### 示例 3: 自定义配置
|
||
|
||
```python
|
||
from run import VideoLingoProcessor
|
||
from core.utils.config_utils import update_key
|
||
|
||
# 自定义配置
|
||
update_key("target_language", "日本語")
|
||
update_key("tts_method", "edge_tts")
|
||
update_key("whisper.model", "large-v3")
|
||
|
||
processor = VideoLingoProcessor(
|
||
input_path="english_video.mp4",
|
||
output_dir="japanese_output"
|
||
)
|
||
|
||
processor.process_all(include_dubbing=True)
|
||
```
|
||
|
||
### 示例 4: 分步处理
|
||
|
||
```python
|
||
from run import VideoLingoProcessor
|
||
|
||
processor = VideoLingoProcessor(
|
||
input_path="video.mp4",
|
||
output_dir="output"
|
||
)
|
||
|
||
# 设置视频文件
|
||
processor.setup_video_file()
|
||
|
||
# 步骤 1: 生成字幕
|
||
if processor.process_subtitles():
|
||
print("字幕生成成功!")
|
||
|
||
# 步骤 2: 生成配音
|
||
if processor.process_dubbing():
|
||
print("配音生成成功!")
|
||
```
|
||
|
||
## 输出文件
|
||
|
||
处理完成后,输出目录将包含:
|
||
|
||
- `output_sub.mp4`: 带字幕的视频(如果启用字幕烧录)
|
||
- `output_dub.mp4`: 带配音的视频(如果执行了配音处理)
|
||
- `*.srt` 文件: 字幕文件
|
||
- `dub.wav`: 配音音频文件
|
||
- `log/` 目录: 处理日志和中间文件
|
||
|
||
## 错误处理
|
||
|
||
脚本包含基本的错误处理:
|
||
|
||
- 输入文件不存在时会报错
|
||
- 处理失败时会显示错误信息
|
||
- 每个步骤都有独立的错误捕获
|
||
|
||
## 注意事项
|
||
|
||
1. **输入文件格式**: 支持常见视频格式(mp4, mov, avi, mkv 等)
|
||
2. **API 密钥**: 确保在 `config.yaml` 中正确配置了所需的 API 密钥
|
||
3. **硬件要求**:
|
||
- GPU 推荐(用于 Whisper 和 TTS)
|
||
- 足够的磁盘空间存储中间文件
|
||
4. **网络要求**: 某些 TTS 服务需要网络连接
|
||
|
||
## 疑难解答
|
||
|
||
### 常见问题
|
||
|
||
1. **模块导入错误**: 确保在 VideoLingo 项目根目录下运行脚本
|
||
2. **API 调用失败**: 检查 API 密钥和网络连接
|
||
3. **内存不足**: 对于大文件,考虑使用较小的 Whisper 模型
|
||
|
||
### 日志查看
|
||
|
||
处理过程中的详细日志保存在 `output/log/` 目录中,可以查看具体的错误信息。
|
||
|
||
---
|
||
|
||
更多信息请参考项目主页和原版 Streamlit 界面的说明。
|