我修改了这个示例代码(https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos):
ffmpeg
-i 1.avi -i 2.avi -i 3.avi -i 4.avi
-filter_complex "
nullsrc=size=640x480 [base];
[0:v] setpts=PTS-STARTPTS, scale=320x240 [upperleft];
[1:v] setpts=PTS-STARTPTS, scale=320x240 [upperright];
[2:v] setpts=PTS-STARTPTS, scale=320x240 [lowerleft];
[3:v] setpts=PTS-STARTPTS, scale=320x240 [lowerright];
[base][upperleft] overlay=shortest=1 [tmp1];
[tmp1][upperright] overlay=shortest=1:x=320 [tmp2];
[tmp2][lowerleft] overlay=shortest=1:y=240 [tmp3];
[tmp3][lowerright] overlay=shortest=1:x=320:y=240
"
-c:v libx264 output.mkv
仅使用两个视频(左、右):
./ffmpeg -i 1.avi -i 2.avi -filter_complex "nullsrc=size=1856x578 [base]; [0:v] setpts=PTS-STARTPTS, scale=928x578 [upperleft];[1:v] setpts=PTS-STARTPTS, scale=928x578 [upperright];[base][upperleft] overlay=shortest=1 [tmp1]; [tmp1][upperright]overlay=shortest=1:x=320 [tmp2] " -c:v libx264 combo.avi
但我总是收到以下错误:
Filter overlay has an unconnected output
任何帮助都非常感谢。
答案1
使用您改编的代码,它应该是
ffmpeg -i 1.avi -i 2.avi -filter_complex "nullsrc=size=1856x578[base];[0:v] setpts=PTS-STARTPTS,scale=928x578[upperleft];[1:v]setpts=PTS-STARTPTS, scale=928x578[upperright];[base][upperleft] overlay=shortest=1 [tmp1]; [tmp1][upperright]overlay=shortest=1:x=320 [tmp2] " -map "[tmp2]" -c:v libx264 combo.avi
您可能需要确认x
覆盖层中的值。我将其保持不变,但可能应该是928
。
但更好的方法是
ffmpeg -i 1.avi -i 2.avi -filter_complex "[0:v][1:v]hstack" -c:v libx264 combo.avi