我有以下脚本使用 FFmpeg 生成视频滑块
您可以在此处查看示例(前 10 秒):https://youtu.be/F_wf1uHqZRA
我正在尝试复制 imgsli 的效果,就像一个人平稳地移动滑块一样
下面是我用来生成上述视频前 10 秒的代码
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)
所以我想要一个像下图这样的滑块,它会在视频中移动