Update main.py
Browse files87 unmodified lines88899091929394959697989910010191929394959697103104105106107108109110111112113114115116117118989910010110210310410512210610710810912412512611011111211387 unmodified lines output_path ] else: # With improved zoom effect inspired by the zoom_in_effect function total_duration = len(image_paths) * duration filter_complex = "" inputs = [] # Add each image with enhanced zoompan effect for i, img in enumerate(image_paths): inputs.extend(["-loop", "1", "-t", str(duration), "-i", img]) # Calculate frames based on duration (assuming 25fps) frames = duration * 25 # Implementation with zoom effect async with aiofiles.open(concat_file, "w") as f: for img in image_paths: await f.write(f"file '{img}'\n") await f.write(f"duration {duration}\n") 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") # Create zoompan filter that mimics the provided zoom_in_effect function # z: zoom factor increases over time based on zoom_ratio # x/y: center the zoom effect by adjusting the position based on zoom filter_complex += ( f"[{i}:v]scale=1920:1080:force_original_aspect_ratio=decrease,setsar=1," f"pad=1920:1080:(ow-iw)/2:(oh-ih)/2," f"zoompan=z='1+(on/{frames})*{zoom_ratio}*{frames}':" f"x='iw/2-(iw/zoom/2)':" f"y='ih/2-(ih/zoom/2)':" f"d={frames}:s=1920x1080[v{i}];" ) # Concatenate all video segments for i in range(len(image_paths)): filter_complex += f"[v{i}]" filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]" # Add the last image again without duration (required by ffmpeg) if image_paths: await f.write(f"file '{image_paths[-1]}'\n") # Run ffmpeg command to create slideshow with audio total_duration = len(image_paths) * duration cmd = [ "ffmpeg", *inputs, "-f", "concat", "-safe", "0", "-i", concat_file, "-i", audio_path, "-filter_complex", filter_complex, "-map", "[outv]", "-map", f"{len(image_paths)}:a", "-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", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac",main.py+15-31