I have the below script to generate a video slider with FFmpeg
You can see example here (first 10 seconds) : https://youtu.be/F_wf1uHqZRA
I am trying to replicate effect of imgsli like a person is moving the slider smoothly
Here below the code I used to generate first 10 seconds of above video
import subprocess
def create_comparison_video(image_a, image_b, output_video, duration=5, frame_rate=30, video_width=1920, video_height=1080):
ffmpeg_cmd = [
'ffmpeg',
'-y', # Overwrite output file if it exists
'-loop', '1', # Loop input images
'-i', image_a,
'-loop', '1',
'-i', image_b,
'-filter_complex',
f"[0]scale={video_width}:{video_height}[img1];" # Scale image A
f"[1]scale={video_width}:{video_height}[img2];" # Scale image B
f"[img1][img2]blend=all_expr='if(gte(X,W*T/{duration}),A,B)':shortest=1," # Slide comparison
f"format=yuv420p,scale={video_width}:{video_height}", # Format and scale output
'-t', str(duration), # Duration of the video
'-r', str(frame_rate), # Frame rate
'-c:v', 'libx264', # Video codec
'-preset', 'slow', # Encoding preset
'-crf', '12', # Constant rate factor (quality)
output_video
]
subprocess.run(ffmpeg_cmd, check=True)
So I want to have a slider like in below image which will move in the video
You have to create a thin line video and then overlay it with same expression as blend.
'-filter_complex',
f"color=c=white:s=4x{video_height}[slider];"
f"[0]scale={video_width}:{video_height}[img1];"
f"[1]scale={video_width}:{video_height}[img2];"
f"[img1][img2]blend=all_expr='if(gte(X,W*T/{duration}),A,B)':shortest=1[comp];"
f"[comp][slider]overlay=x=W*t/{duration}:y=0,"
f"format=yuv420p,scale={video_width}:{video_height}",