saq1b commited on
Commit
9b13a7b
·
verified ·
1 Parent(s): c8573d3

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -24
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
- # 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",
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