Update main.py
Browse files
main.py
CHANGED
@@ -57,7 +57,7 @@ async def download_file(url, local_path):
|
|
57 |
|
58 |
async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=False, zoom_ratio=0.04):
|
59 |
"""Generate slideshow from images and audio using ffmpeg asynchronously"""
|
60 |
-
# Create temporary file list for ffmpeg concat
|
61 |
concat_file = "temp_concat.txt"
|
62 |
|
63 |
if not zoom:
|
@@ -89,37 +89,29 @@ async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=
|
|
89 |
]
|
90 |
else:
|
91 |
# Complex implementation with zoom effect
|
92 |
-
#
|
93 |
filters = []
|
94 |
-
inputs = []
|
95 |
-
|
96 |
for i, img in enumerate(image_paths):
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
102 |
filters.append(filter_str)
|
103 |
-
|
104 |
-
#
|
105 |
filter_complex = "".join(filters)
|
106 |
-
|
107 |
-
# Add concat to combine all zoompan videos
|
108 |
-
filter_complex += ""
|
109 |
for i in range(len(image_paths)):
|
110 |
filter_complex += f"[v{i}]"
|
111 |
filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]"
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
"ffmpeg",
|
116 |
-
"-y"
|
117 |
-
]
|
118 |
-
|
119 |
-
# Add inputs
|
120 |
for img in image_paths:
|
121 |
-
cmd.extend(["-loop", "1", "-
|
122 |
-
|
123 |
cmd.extend([
|
124 |
"-i", audio_path,
|
125 |
"-filter_complex", filter_complex,
|
|
|
57 |
|
58 |
async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=False, zoom_ratio=0.04):
|
59 |
"""Generate slideshow from images and audio using ffmpeg asynchronously"""
|
60 |
+
# Create temporary file list for ffmpeg concat (used in non-zoom mode)
|
61 |
concat_file = "temp_concat.txt"
|
62 |
|
63 |
if not zoom:
|
|
|
89 |
]
|
90 |
else:
|
91 |
# Complex implementation with zoom effect
|
92 |
+
# For each image, we remove the per-input duration and instead do a trimmed zoompan.
|
93 |
filters = []
|
|
|
|
|
94 |
for i, img in enumerate(image_paths):
|
95 |
+
filter_str = (
|
96 |
+
f"[{i}:v]scale=1920:1080:force_original_aspect_ratio=decrease,"
|
97 |
+
f"pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,"
|
98 |
+
f"zoompan=z='min(zoom+0.0015,1.5)':d={duration*25}:"
|
99 |
+
f"x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',"
|
100 |
+
f"trim=duration={duration},setpts=PTS-STARTPTS[v{i}];"
|
101 |
+
)
|
102 |
filters.append(filter_str)
|
103 |
+
|
104 |
+
# Concatenate all zoompan outputs
|
105 |
filter_complex = "".join(filters)
|
|
|
|
|
|
|
106 |
for i in range(len(image_paths)):
|
107 |
filter_complex += f"[v{i}]"
|
108 |
filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]"
|
109 |
+
|
110 |
+
cmd = ["ffmpeg", "-y"]
|
111 |
+
# Remove duration here; let zoompan+trim control each clip's length.
|
|
|
|
|
|
|
|
|
|
|
112 |
for img in image_paths:
|
113 |
+
cmd.extend(["-loop", "1", "-i", img])
|
114 |
+
|
115 |
cmd.extend([
|
116 |
"-i", audio_path,
|
117 |
"-filter_complex", filter_complex,
|