优化 ost 新增状态

- 0: 只播放解说音频
- 1: 只播放视频原声
- 2: 播放解说同时保留原声
This commit is contained in:
linyq 2024-11-05 18:04:21 +08:00
parent 04c4406e24
commit 1d9b27bf46
2 changed files with 6 additions and 7 deletions

View File

@ -233,7 +233,7 @@ def generate_video_v2(
Returns: Returns:
""" """
total_steps = 4 # 总步 total_steps = 4 # 总步<EFBFBD><EFBFBD><EFBFBD>
current_step = 0 current_step = 0
def update_progress(step_name): def update_progress(step_name):
@ -436,7 +436,7 @@ def preprocess_video(materials: List[MaterialInfo], clip_duration=4):
def combine_clip_videos(combined_video_path: str, def combine_clip_videos(combined_video_path: str,
video_paths: List[str], video_paths: List[str],
video_ost_list: List[bool], video_ost_list: List[int],
list_script: list, list_script: list,
video_aspect: VideoAspect = VideoAspect.portrait, video_aspect: VideoAspect = VideoAspect.portrait,
threads: int = 2, threads: int = 2,
@ -446,7 +446,7 @@ def combine_clip_videos(combined_video_path: str,
Args: Args:
combined_video_path: 合并后的存储路径 combined_video_path: 合并后的存储路径
video_paths: 子视频路径列表 video_paths: 子视频路径列表
video_ost_list: 原声播放列表 video_ost_list: 原声播放列表 (0: 不保留原声, 1: 只保留原声, 2: 保留原声并保留解说)
list_script: 剪辑脚本 list_script: 剪辑脚本
video_aspect: 屏幕比例 video_aspect: 屏幕比例
threads: 线程数 threads: 线程数
@ -465,12 +465,11 @@ def combine_clip_videos(combined_video_path: str,
clips = [] clips = []
for video_path, video_ost in zip(video_paths, video_ost_list): for video_path, video_ost in zip(video_paths, video_ost_list):
try: try:
# 直接使用视频路径不再拼接root_dir
clip = VideoFileClip(video_path) clip = VideoFileClip(video_path)
# 通过 ost 字段判断是否播放原声 if video_ost == 0: # 不保留原声
if not video_ost:
clip = clip.without_audio() clip = clip.without_audio()
# video_ost 为 1 或 2 时都保留原声,不需要特殊处理
clip = clip.set_fps(30) clip = clip.set_fps(30)

View File

@ -1409,7 +1409,7 @@ def tts_multiple(task_id: str, list_script: list, voice_name: str, voice_rate: f
sub_maker_list = [] sub_maker_list = []
for item in list_script: for item in list_script:
if not item['OST']: if item['OST'] != 1:
# 将时间戳中的冒号替换为下划线 # 将时间戳中的冒号替换为下划线
timestamp = item['new_timestamp'].replace(':', '_') timestamp = item['new_timestamp'].replace(':', '_')
audio_file = os.path.join(output_dir, f"audio_{timestamp}.mp3") audio_file = os.path.join(output_dir, f"audio_{timestamp}.mp3")