97 lines
2.7 KiB
Python
97 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
VideoLingo 使用示例
|
|
展示如何使用 run.py 脚本处理视频
|
|
"""
|
|
|
|
from run import VideoLingoProcessor
|
|
from core.utils.config_utils import update_key
|
|
|
|
def example_basic_usage():
|
|
"""基础使用示例 - 只生成字幕"""
|
|
print("=== 示例 1: 基础字幕生成 ===")
|
|
|
|
# 创建处理器
|
|
processor = VideoLingoProcessor(
|
|
input_path="path/to/your/video.mp4", # 替换为您的视频路径
|
|
output_dir="output_subtitles_only"
|
|
)
|
|
|
|
# 只处理字幕,不进行配音
|
|
processor.process_all(include_dubbing=False)
|
|
|
|
def example_full_processing():
|
|
"""完整处理示例 - 字幕 + 配音"""
|
|
print("=== 示例 2: 完整处理流程 ===")
|
|
|
|
# 创建处理器
|
|
processor = VideoLingoProcessor(
|
|
input_path="path/to/your/video.mp4", # 替换为您的视频路径
|
|
output_dir="output_full"
|
|
)
|
|
|
|
# 执行完整流程(字幕 + 配音)
|
|
processor.process_all(include_dubbing=True)
|
|
|
|
def example_custom_config():
|
|
"""自定义配置示例"""
|
|
print("=== 示例 3: 自定义配置 ===")
|
|
|
|
# 修改配置
|
|
update_key("target_language", "English") # 修改目标语言为英文
|
|
update_key("tts_method", "edge_tts") # 使用 Edge TTS
|
|
update_key("burn_subtitles", False) # 不烧录字幕到视频
|
|
|
|
# 创建处理器
|
|
processor = VideoLingoProcessor(
|
|
input_path="path/to/your/video.mp4",
|
|
output_dir="output_custom"
|
|
)
|
|
|
|
# 执行处理
|
|
processor.process_all(include_dubbing=True)
|
|
|
|
def example_step_by_step():
|
|
"""分步处理示例"""
|
|
print("=== 示例 4: 分步处理 ===")
|
|
|
|
processor = VideoLingoProcessor(
|
|
input_path="path/to/your/video.mp4",
|
|
output_dir="output_step_by_step"
|
|
)
|
|
|
|
# 设置视频文件
|
|
processor.setup_video_file()
|
|
|
|
# 先处理字幕
|
|
print("步骤 1: 处理字幕")
|
|
subtitle_success = processor.process_subtitles()
|
|
|
|
if subtitle_success:
|
|
print("字幕处理成功,继续配音处理")
|
|
|
|
# 再处理配音
|
|
print("步骤 2: 处理配音")
|
|
dubbing_success = processor.process_dubbing()
|
|
|
|
if dubbing_success:
|
|
print("全部处理完成!")
|
|
else:
|
|
print("配音处理失败")
|
|
else:
|
|
print("字幕处理失败")
|
|
|
|
if __name__ == "__main__":
|
|
print("VideoLingo 使用示例")
|
|
print("请根据需要取消注释并运行相应的示例函数")
|
|
print()
|
|
|
|
# 取消注释您想要运行的示例
|
|
# example_basic_usage()
|
|
# example_full_processing()
|
|
# example_custom_config()
|
|
# example_step_by_step()
|
|
|
|
print("请编辑此文件,取消注释相应的示例函数来运行")
|