deeme commited on
Commit
65859e2
·
verified ·
1 Parent(s): d393c55

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -277,37 +277,28 @@ def create_video(project_dir, image_paths, caption_subtitle_file, speech_subtitl
277
 
278
  subprocess.run(cmd1, check=True)
279
 
280
- # 然后添加字幕 - 先添加caption字幕(底部)
281
  temp_video2 = os.path.join(project_dir, "temp_video2.mp4")
282
 
283
  subtitle_path = caption_subtitle_file.replace(os.sep, '/')
284
  subtitle_path = subtitle_path.replace(':', '\\:')
285
- caption_filter = f"subtitles='{subtitle_path}'"
286
-
287
- cmd2 = [
288
- "ffmpeg", "-y",
289
- "-i", temp_video,
290
- "-vf", caption_filter,
291
- "-c:a", "copy",
292
- temp_video2
293
- ]
294
-
295
- subprocess.run(cmd2, check=True)
296
 
297
  # 再添加speech字幕(顶部)
298
- subtitle_path = speech_subtitle_file.replace(os.sep, '/')
299
- subtitle_path = subtitle_path.replace(':', '\\:')
300
- speech_filter = f"subtitles='{subtitle_path}'"
301
 
302
- cmd3 = [
 
 
303
  "ffmpeg", "-y",
304
- "-i", temp_video2,
305
- "-vf", speech_filter,
306
  "-c:a", "copy",
307
  output_video
308
  ]
309
 
310
- subprocess.run(cmd3, check=True)
311
 
312
  # 删除临时文件
313
  os.remove(temp_video)
 
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
+ # 将两次字幕处理合并为单个FFmpeg命令(替换原来的cmd2和cmd3
292
+ combined_filter = f"subtitles='{caption_path}':force_style='Alignment=2,WrapStyle=1,Fontsize=24,MarginV=30 [with_captions]; [with_captions] subtitles='{speech_path}':force_style='Alignment=8,WrapStyle=1,Fontsize=24,MarginV=30'"
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)