saq1b commited on
Commit
2eead49
·
verified ·
1 Parent(s): 7f5d68f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -24
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
- # Create a filter for each image that zooms in
93
  filters = []
94
- inputs = []
95
-
96
  for i, img in enumerate(image_paths):
97
- # Add input for each image
98
- inputs.extend(["-loop", "1", "-t", str(duration), "-i", img])
99
-
100
- # Create zoom effect filter for each image
101
- 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}];"
 
 
102
  filters.append(filter_str)
103
-
104
- # Create the filter complex string
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
- # Run ffmpeg command to create slideshow with zoom and audio
114
- cmd = [
115
- "ffmpeg",
116
- "-y"
117
- ]
118
-
119
- # Add inputs
120
  for img in image_paths:
121
- cmd.extend(["-loop", "1", "-t", str(duration), "-i", img])
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,