Update main.py
Browse files87 unmodified lines88899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812987 unmodified linesoutput_path]else:# With improved zoom effect inspired by the zoom_in_effect functiontotal_duration = len(image_paths) * durationfilter_complex = ""inputs = []# Add each image with enhanced zoompan effectfor 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# 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 zoomfilter_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 segmentsfor i in range(len(image_paths)):filter_complex += f"[v{i}]"filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]"cmd = ["ffmpeg",*inputs,"-i", audio_path,"-filter_complex", filter_complex,"-map", "[outv]","-map", f"{len(image_paths)}:a","-c:v", "libx264","-pix_fmt", "yuv420p","-c:a", "aac",87 unmodified lines88899091929394959697989910010110210310410510610710810911011111211387 unmodified linesoutput_path]else:# Implementation with zoom effectasync 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")# 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 audiototal_duration = len(image_paths) * durationcmd = ["ffmpeg","-f", "concat","-safe", "0","-i", concat_file,"-i", audio_path,"-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