Upload app.py
Browse files
app.py
CHANGED
|
@@ -274,35 +274,26 @@ def create_video(project_dir, image_paths, caption_subtitle_file, speech_subtitl
|
|
| 274 |
"-async", "1", # 音频同步
|
| 275 |
temp_video
|
| 276 |
]
|
| 277 |
-
|
| 278 |
subprocess.run(cmd1, check=True)
|
| 279 |
-
|
| 280 |
-
temp_video2 = os.path.join(project_dir, "temp_video2.mp4")
|
| 281 |
-
|
| 282 |
-
subtitle_path = caption_subtitle_file.replace(os.sep, '/')
|
| 283 |
-
subtitle_path = subtitle_path.replace(':', '\\:')
|
| 284 |
-
|
| 285 |
-
# 然后添加字幕 - 先添加caption字幕(底部)
|
| 286 |
-
caption_filter = f"subtitles='{subtitle_path}':force_style='Alignment=2,WrapStyle=1,Fontsize=15,MarginV=30'"
|
| 287 |
-
|
| 288 |
-
# 再添加speech字幕(顶部)
|
| 289 |
-
speech_filter = f"subtitles='{subtitle_path}':force_style='Alignment=8,WrapStyle=1,Fontsize=15,MarginV=30'"
|
| 290 |
|
| 291 |
-
#
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
cmd_combined = [
|
| 294 |
"ffmpeg", "-y",
|
| 295 |
"-i", temp_video,
|
| 296 |
"-vf", combined_filter,
|
| 297 |
"-c:a", "copy",
|
| 298 |
-
output_video
|
| 299 |
]
|
| 300 |
|
| 301 |
subprocess.run(cmd_combined, check=True)
|
| 302 |
|
| 303 |
-
#
|
| 304 |
os.remove(temp_video)
|
| 305 |
-
os.remove(temp_video2)
|
| 306 |
|
| 307 |
return output_video
|
| 308 |
except Exception as e:
|
|
|
|
| 274 |
"-async", "1", # 音频同步
|
| 275 |
temp_video
|
| 276 |
]
|
|
|
|
| 277 |
subprocess.run(cmd1, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
+
# 处理字幕路径转义(两个不同的字幕文件)
|
| 280 |
+
caption_path = caption_subtitle_file.replace(os.sep, '/').replace(':', '\\:')
|
| 281 |
+
speech_path = speech_subtitle_file.replace(os.sep, '/').replace(':', '\\:')
|
| 282 |
+
# 合并滤镜的正确写法(使用两个subtitles滤镜)
|
| 283 |
+
combined_filter = f"subtitles='{caption_path}':force_style='Alignment=2,WrapStyle=1,Fontsize=15,MarginV=30'," \
|
| 284 |
+
f"subtitles='{speech_path}':force_style='Alignment=8,WrapStyle=1,Fontsize=15,MarginV=30'"
|
| 285 |
cmd_combined = [
|
| 286 |
"ffmpeg", "-y",
|
| 287 |
"-i", temp_video,
|
| 288 |
"-vf", combined_filter,
|
| 289 |
"-c:a", "copy",
|
| 290 |
+
output_video # 直接输出到最终文件,无需temp_video2
|
| 291 |
]
|
| 292 |
|
| 293 |
subprocess.run(cmd_combined, check=True)
|
| 294 |
|
| 295 |
+
# 删除临时文件(只需删除temp_video)
|
| 296 |
os.remove(temp_video)
|
|
|
|
| 297 |
|
| 298 |
return output_video
|
| 299 |
except Exception as e:
|