deeme commited on
Commit
42eec4c
·
verified ·
1 Parent(s): 755d9b6

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -18
app.py CHANGED
@@ -292,30 +292,43 @@ def process_sub_path(path):
292
  def create_video(project_dir, image_paths, caption_subtitle_file, speech_subtitle_file,
293
  audio_file, output_video, audio_durations, panel_start_times, panel_durations):
294
  try:
295
- # 创建帧列表文件 - 使用精确的面板持续时间
296
- frames_list = os.path.join(project_dir, "frames.txt")
297
- with open(frames_list, "w") as f:
298
- for i, (img, duration) in enumerate(zip(image_paths, panel_durations)):
299
- f.write(f"file '{img.replace(os.sep, '/')}'\n")
300
- f.write(f"duration {duration}\n")
301
 
302
- # 最后一张图片需要单独添加,否则会被忽略
303
- f.write(f"file '{image_paths[-1].replace(os.sep, '/')}'\n")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
- # 先创建无字幕的视频 - 使用更精确的同步选项
306
  temp_video = os.path.join(project_dir, "temp_video.mp4")
307
- cmd1 = [
308
  "ffmpeg", "-y",
309
- "-f", "concat", "-safe", "0", "-i", frames_list,
 
 
310
  "-i", audio_file,
311
- "-vf", "zoompan=z='1.0+0.02*sin(2*PI*on/25/5)':d=1", # 正弦波动缩放
312
- "-c:v", "libx264", "-pix_fmt", "yuv420p",
313
- "-c:a", "aac", "-strict", "experimental",
314
- "-vsync", "vfr", # 确保视频帧率与时间轴匹配
315
- "-async", "1", # 音频同步
316
  temp_video
317
- ]
318
- subprocess.run(cmd1, check=True)
319
 
320
  # 构建滤镜链
321
  combined_filter = (
 
292
  def create_video(project_dir, image_paths, caption_subtitle_file, speech_subtitle_file,
293
  audio_file, output_video, audio_durations, panel_start_times, panel_durations):
294
  try:
295
+ # 为每个面板生成动态片段
296
+ video_clips = []
297
+ for idx, (img_path, duration) in enumerate(zip(image_paths, panel_durations)):
298
+ output_clip = os.path.join(clip_dir, f"clip_{idx}.mp4")
 
 
299
 
300
+ # FFmpeg命令生成缩放效果
301
+ zoom_cmd = [
302
+ "ffmpeg", "-y",
303
+ "-loop", "1",
304
+ "-i", img_path,
305
+ "-vf",
306
+ f"zoompan=z='1.0+0.1*(on/({duration}*25))':d={duration}*25",
307
+ "-t", str(duration),
308
+ "-pix_fmt", "yuv420p",
309
+ output_clip
310
+ ]
311
+ subprocess.run(zoom_cmd, check=True)
312
+ video_clips.append(output_clip)
313
+ # 合并所有动态片段
314
+ concat_list = os.path.join(project_dir, "concat_list.txt")
315
+ with open(concat_list, "w") as f:
316
+ for clip in video_clips:
317
+ f.write(f"file '{clip}'\n")
318
 
 
319
  temp_video = os.path.join(project_dir, "temp_video.mp4")
320
+ subprocess.run([
321
  "ffmpeg", "-y",
322
+ "-f", "concat",
323
+ "-safe", "0",
324
+ "-i", concat_list,
325
  "-i", audio_file,
326
+ "-c:v", "libx264",
327
+ "-c:a", "aac",
328
+ "-vsync", "vfr",
329
+ "-async", "1",
 
330
  temp_video
331
+ ], check=True)
 
332
 
333
  # 构建滤镜链
334
  combined_filter = (