Update main.py
Browse files
main.py
CHANGED
@@ -88,42 +88,26 @@ 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 |
-
for i, img in enumerate(image_paths):
|
98 |
-
inputs.extend(["-loop", "1", "-t", str(duration), "-i", img])
|
99 |
-
|
100 |
-
# Calculate frames based on duration (assuming 25fps)
|
101 |
-
frames = duration * 25
|
102 |
|
103 |
-
#
|
104 |
-
|
105 |
-
|
106 |
-
filter_complex += (
|
107 |
-
f"[{i}:v]scale=1920:1080:force_original_aspect_ratio=decrease,setsar=1,"
|
108 |
-
f"pad=1920:1080:(ow-iw)/2:(oh-ih)/2,"
|
109 |
-
f"zoompan=z='1+(on/{frames})*{zoom_ratio}*{frames}':"
|
110 |
-
f"x='iw/2-(iw/zoom/2)':"
|
111 |
-
f"y='ih/2-(ih/zoom/2)':"
|
112 |
-
f"d={frames}:s=1920x1080[v{i}];"
|
113 |
-
)
|
114 |
-
|
115 |
-
# Concatenate all video segments
|
116 |
-
for i in range(len(image_paths)):
|
117 |
-
filter_complex += f"[v{i}]"
|
118 |
-
filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]"
|
119 |
|
|
|
|
|
120 |
cmd = [
|
121 |
"ffmpeg",
|
122 |
-
|
|
|
|
|
123 |
"-i", audio_path,
|
124 |
-
"-
|
125 |
-
"-map", "[outv]",
|
126 |
-
"-map", f"{len(image_paths)}:a",
|
127 |
"-c:v", "libx264",
|
128 |
"-pix_fmt", "yuv420p",
|
129 |
"-c:a", "aac",
|
|
|
88 |
output_path
|
89 |
]
|
90 |
else:
|
91 |
+
# Implementation with zoom effect
|
92 |
+
async with aiofiles.open(concat_file, "w") as f:
|
93 |
+
for img in image_paths:
|
94 |
+
await f.write(f"file '{img}'\n")
|
95 |
+
await f.write(f"duration {duration}\n")
|
96 |
+
await f.write(f"zoompan=z='min(zoom+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':s=1280x720,framerate=25:interp_start=0:interp_end=255:scene=100\n")
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
# Add the last image again without duration (required by ffmpeg)
|
99 |
+
if image_paths:
|
100 |
+
await f.write(f"file '{image_paths[-1]}'\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
+
# Run ffmpeg command to create slideshow with audio
|
103 |
+
total_duration = len(image_paths) * duration
|
104 |
cmd = [
|
105 |
"ffmpeg",
|
106 |
+
"-f", "concat",
|
107 |
+
"-safe", "0",
|
108 |
+
"-i", concat_file,
|
109 |
"-i", audio_path,
|
110 |
+
"-vf", f"zoompan=z='min(zoom+{zoom_ratio},1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':s=1280x720,framerate=25:interp_start=0:interp_end=255:scene=100",
|
|
|
|
|
111 |
"-c:v", "libx264",
|
112 |
"-pix_fmt", "yuv420p",
|
113 |
"-c:a", "aac",
|