Update main.py
Browse files
main.py
CHANGED
@@ -88,32 +88,31 @@ async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=
|
|
88 |
output_path
|
89 |
]
|
90 |
else:
|
91 |
-
#
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
"-
|
112 |
-
"-
|
|
|
113 |
"-c:a", "aac",
|
114 |
"-shortest",
|
115 |
-
"-y",
|
116 |
-
"-t", str(total_duration),
|
117 |
output_path
|
118 |
]
|
119 |
|
|
|
88 |
output_path
|
89 |
]
|
90 |
else:
|
91 |
+
# Build separate inputs looping each image with a fixed display time and apply zoom effect
|
92 |
+
cmd_inputs = []
|
93 |
+
for img in image_paths:
|
94 |
+
cmd_inputs += ["-loop", "1", "-t", str(duration), "-i", img]
|
95 |
+
# Add the audio input at the end
|
96 |
+
cmd_inputs += ["-i", audio_path]
|
97 |
+
|
98 |
+
# Create filter_complex applying zoompan on each image (assuming 25 fps)
|
99 |
+
num_images = len(image_paths)
|
100 |
+
filter_parts = []
|
101 |
+
for i in range(num_images):
|
102 |
+
filter_parts.append(
|
103 |
+
f"[{i}:v]zoompan=z='min(zoom+{zoom_ratio},1.5)':d={duration * 25}:s=hd720,setsar=1[v{i}]"
|
104 |
+
)
|
105 |
+
# Concatenate all processed clips
|
106 |
+
concat_inputs = "".join(f"[v{i}]" for i in range(num_images))
|
107 |
+
filter_complex = "; ".join(filter_parts) + f"; {concat_inputs}concat=n={num_images}:v=1:a=0,format=yuv420p[v]"
|
108 |
+
|
109 |
+
# Build the ffmpeg command with proper mapping for video and audio (audio is after the images)
|
110 |
+
cmd = ["ffmpeg", "-y"] + cmd_inputs + [
|
111 |
+
"-filter_complex", filter_complex,
|
112 |
+
"-map", "[v]",
|
113 |
+
"-map", f"{num_images}:a",
|
114 |
"-c:a", "aac",
|
115 |
"-shortest",
|
|
|
|
|
116 |
output_path
|
117 |
]
|
118 |
|