saq1b commited on
Commit
0f1ea7e
·
verified ·
1 Parent(s): ebbe9c8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +22 -13
main.py CHANGED
@@ -96,14 +96,23 @@ async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=
96
  # Add each image with zoompan effect
97
  for i, img in enumerate(image_paths):
98
  inputs.extend(["-loop", "1", "-t", str(duration), "-i", img])
99
- # Apply zoom effect with custom formula
100
- zoompan_params = f"z='1+(0.04*{duration})*on/{duration*25}':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d={duration*25}:s=1920x1080"
101
- filter_complex += f"[{i}:v]zoompan={zoompan_params}[v{i}];"
 
 
 
102
 
103
- # Concatenate all video segments
104
- for i in range(len(image_paths)):
105
- filter_complex += f"[v{i}]"
106
- filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]"
 
 
 
 
 
 
107
 
108
  cmd = [
109
  "ffmpeg",
@@ -113,12 +122,12 @@ async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=
113
  "-map", "[outv]",
114
  "-map", f"{len(image_paths)}:a",
115
  "-c:v", "libx264",
116
- "-pix_fmt", "yuv420p",
117
- "-c:a", "aac",
118
- "-shortest",
119
- "-y",
120
- "-t", str(total_duration),
121
- output_path
122
  ]
123
 
124
  try:
 
96
  # Add each image with zoompan effect
97
  for i, img in enumerate(image_paths):
98
  inputs.extend(["-loop", "1", "-t", str(duration), "-i", img])
99
+ # Apply zoom effect with smoother formula - slower zoom factor and better stabilization
100
+ # Adjust zoom rate (0.02 instead of 0.04) for smoother effect
101
+ fps = 25
102
+ zoom_factor = 0.02
103
+ zoompan_params = f"z='if(lte(zoom,1.0),1.0,zoom-{zoom_factor}/{fps})':d={duration*fps}:s=1920x1080:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'"
104
+ filter_complex += f"[{i}:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,zoompan={zoompan_params}[v{i}];"
105
 
106
+ # Concatenate all video segments with crossfade transitions
107
+ if len(image_paths) > 1:
108
+ for i in range(len(image_paths) - 1):
109
+ filter_complex += f"[v{i}][v{i+1}]xfade=duration=0.5:offset={duration-0.5}[v{i+1}_xf];"
110
+
111
+ # Use the last crossfaded output
112
+ filter_complex += f"[v{len(image_paths)-1}_xf]copy[outv]"
113
+ else:
114
+ # If only one image, use it directly
115
+ filter_complex += "[v0]copy[outv]"
116
 
117
  cmd = [
118
  "ffmpeg",
 
122
  "-map", "[outv]",
123
  "-map", f"{len(image_paths)}:a",
124
  "-c:v", "libx264",
125
+ process = await asyncio.create_subprocess_exec(
126
+ *cmd,
127
+ stdout=asyncio.subprocess.PIPE,
128
+ stderr=asyncio.subprocess.PIPE
129
+ )
130
+ _, stderr = await process.communicate()
131
  ]
132
 
133
  try: