Upload app.py
Browse files
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 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
f.write(f"file '{img.replace(os.sep, '/')}'\n")
|
| 300 |
-
f.write(f"duration {duration}\n")
|
| 301 |
|
| 302 |
-
#
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
-
# 先创建无字幕的视频 - 使用更精确的同步选项
|
| 306 |
temp_video = os.path.join(project_dir, "temp_video.mp4")
|
| 307 |
-
|
| 308 |
"ffmpeg", "-y",
|
| 309 |
-
"-f", "concat",
|
|
|
|
|
|
|
| 310 |
"-i", audio_file,
|
| 311 |
-
"-
|
| 312 |
-
"-c:
|
| 313 |
-
"-
|
| 314 |
-
"-
|
| 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 = (
|