Update main.py
Browse files56 unmodified lines5758596061626325 unmodified lines899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412556 unmodified linesasync def create_slideshow(image_paths, audio_path, output_path, duration, zoom=False, zoom_ratio=0.04):"""Generate slideshow from images and audio using ffmpeg asynchronously"""# Create temporary file list for ffmpeg concatconcat_file = "temp_concat.txt"if not zoom:25 unmodified lines]else:# Complex implementation with zoom effect# Create a filter for each image that zooms infilters = []inputs = []for i, img in enumerate(image_paths):# Add input for each imageinputs.extend(["-loop", "1", "-t", str(duration), "-i", img])# Create zoom effect filter for each imagefilter_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}];"filters.append(filter_str)# Create the filter complex stringfilter_complex = "".join(filters)# Add concat to combine all zoompan videosfilter_complex += ""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]"# Run ffmpeg command to create slideshow with zoom and audiocmd = ["ffmpeg","-y"]# Add inputsfor img in image_paths:cmd.extend(["-loop", "1", "-t", str(duration), "-i", img])cmd.extend(["-i", audio_path,"-filter_complex", filter_complex,56 unmodified lines5758596061626325 unmodified lines899091929394959697989910010110210310410510610710810911011111211311411511611756 unmodified linesasync def create_slideshow(image_paths, audio_path, output_path, duration, zoom=False, zoom_ratio=0.04):"""Generate slideshow from images and audio using ffmpeg asynchronously"""# Create temporary file list for ffmpeg concat (used in non-zoom mode)concat_file = "temp_concat.txt"if not zoom:25 unmodified lines]else:# Complex implementation with zoom effect# For each image, we remove the per-input duration and instead do a trimmed zoompan.filters = []for i, img in enumerate(image_paths):filter_str = (f"[{i}:v]scale=1920:1080:force_original_aspect_ratio=decrease,"f"pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,"f"zoompan=z='min(zoom+0.0015,1.5)':d={duration*25}:"f"x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)',"f"trim=duration={duration},setpts=PTS-STARTPTS[v{i}];")filters.append(filter_str)# Concatenate all zoompan outputsfilter_complex = "".join(filters)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]"cmd = ["ffmpeg", "-y"]# Remove duration here; let zoompan+trim control each clip's length.for img in image_paths:cmd.extend(["-loop", "1", "-i", img])cmd.extend(["-i", audio_path,"-filter_complex", filter_complex,
main.py+16-24