Update main.py
Browse files
main.py
CHANGED
@@ -88,65 +88,42 @@ 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 |
-
# First create individual video clips with zoom effect for each image
|
98 |
-
for i, img_path in enumerate(image_paths):
|
99 |
-
temp_video = os.path.join(os.path.dirname(output_path), f"temp_{i:03d}.mp4")
|
100 |
-
temp_videos.append(temp_video)
|
101 |
-
|
102 |
-
zoom_filter = f"scale=8000:-1,zoompan=z='min(zoom+0.001,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d={duration*framerate}:s={output_res}:fps={framerate}"
|
103 |
-
|
104 |
-
img_cmd = [
|
105 |
-
"ffmpeg",
|
106 |
-
"-loop", "1",
|
107 |
-
"-framerate", str(framerate),
|
108 |
-
"-i", img_path,
|
109 |
-
"-vf", zoom_filter,
|
110 |
-
"-t", str(duration),
|
111 |
-
"-c:v", "libx264",
|
112 |
-
"-pix_fmt", "yuv420p",
|
113 |
-
"-y",
|
114 |
-
temp_video
|
115 |
-
]
|
116 |
-
|
117 |
-
img_process = await asyncio.create_subprocess_exec(
|
118 |
-
*img_cmd,
|
119 |
-
stdout=asyncio.subprocess.PIPE,
|
120 |
-
stderr=asyncio.subprocess.PIPE
|
121 |
-
)
|
122 |
-
img_stdout, img_stderr = await img_process.communicate()
|
123 |
-
|
124 |
-
if img_process.returncode != 0:
|
125 |
-
print(f"FFmpeg error processing image {i}: {img_stderr.decode()}")
|
126 |
-
# Clean up already created temp videos
|
127 |
-
for vid in temp_videos:
|
128 |
-
if os.path.exists(vid):
|
129 |
-
os.remove(vid)
|
130 |
-
return False
|
131 |
|
132 |
-
# Create
|
133 |
-
|
134 |
-
for video in temp_videos:
|
135 |
-
await f.write(f"file '{video}'\n")
|
136 |
|
137 |
-
#
|
|
|
|
|
|
|
|
|
|
|
138 |
cmd = [
|
139 |
"ffmpeg",
|
140 |
-
"-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
143 |
"-i", audio_path,
|
|
|
|
|
|
|
144 |
"-c:v", "libx264",
|
|
|
145 |
"-c:a", "aac",
|
146 |
"-shortest",
|
147 |
-
"-y",
|
148 |
output_path
|
149 |
-
]
|
150 |
try:
|
151 |
process = await asyncio.create_subprocess_exec(
|
152 |
*cmd,
|
|
|
88 |
output_path
|
89 |
]
|
90 |
else:
|
91 |
+
# Complex implementation with zoom effect
|
92 |
+
# Create a filter for each image that zooms in
|
93 |
+
filters = []
|
94 |
+
for i, img in enumerate(image_paths):
|
95 |
+
filter_str = f"[{i}:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,zoompan=z='min(zoom+0.0015,1.5)':d={duration*25}:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',setpts=PTS-STARTPTS[v{i}];"
|
96 |
+
filters.append(filter_str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
+
# Create the filter complex string
|
99 |
+
filter_complex = "".join(filters)
|
|
|
|
|
100 |
|
101 |
+
# Add concat to combine all zoompan videos
|
102 |
+
for i in range(len(image_paths)):
|
103 |
+
filter_complex += f"[v{i}]"
|
104 |
+
filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]"
|
105 |
+
|
106 |
+
# Run ffmpeg command to create slideshow with zoom and audio
|
107 |
cmd = [
|
108 |
"ffmpeg",
|
109 |
+
"-y"
|
110 |
+
]
|
111 |
+
|
112 |
+
# Add inputs
|
113 |
+
for img in image_paths:
|
114 |
+
cmd.extend(["-loop", "1", "-t", str(duration), "-i", img])
|
115 |
+
|
116 |
+
cmd.extend([
|
117 |
"-i", audio_path,
|
118 |
+
"-filter_complex", filter_complex,
|
119 |
+
"-map", "[outv]",
|
120 |
+
"-map", f"{len(image_paths)}:a",
|
121 |
"-c:v", "libx264",
|
122 |
+
"-pix_fmt", "yuv420p",
|
123 |
"-c:a", "aac",
|
124 |
"-shortest",
|
|
|
125 |
output_path
|
126 |
+
])
|
127 |
try:
|
128 |
process = await asyncio.create_subprocess_exec(
|
129 |
*cmd,
|