使用 FFMPEG 根据具有不同 SAR 的图像创建视频

使用 FFMPEG 根据具有不同 SAR 的图像创建视频

我正在尝试运行ffmpeg命令:

ffmpeg -y -threads 2  -loop 1 -t 5 -i watermark-0.png -loop 1 -t 2.5 -i watermark-1.png -loop 1 -t 2.5 -iwatermark-2.png -loop 1 -t 2.5 -i watermark-3.png -loop 1 -t 2.5 -i4.png -loop 1 -t 2.5 -i watermark-5.png -loop 1 -t 2.5 -i watermark-6.png -loop 1 -t 2.5 -i watermark-7.png -filter_complex [1:v][0:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b1v];[2:v][1:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b2v];[3:v][2:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b3v];[4:v][3:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b4v];[5:v][4:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b5v];[6:v][5:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b6v];[7:v][6:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b7v];[0:v][b1v][1:v][b2v][2:v][b3v][3:v][b4v][4:v][b5v][5:v][b6v][6:v][b7v][7:v]concat=n=15:v=1:a=0,format=yuv420p[v] -map [v] -c:v libx264 -r 120 -s 1280x720 -aspect 16:9 -crf 1 -preset ultrafast output.mp4

但是,我收到了 ffmpeg 错误:第一个输入链接顶部参数(尺寸 1280x720,SAR 5689:5669)与相应的第二个输入链接底部参数不匹配(1280x720,SAR 1:1)

ffmpeg 标准输出是:

Input #0, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-0.png':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, rgb24, 1280x720 [SAR 72:72 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-1.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgb24, 1280x720 [SAR 5905:5905 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #2, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-2.png':
  Duration: N/A, bitrate: N/A
    Stream #2:0: Video: png, rgb24, 1280x720 [SAR 100:100 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #3, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-3.png':
  Duration: N/A, bitrate: N/A
    Stream #3:0: Video: png, rgb24, 1280x720 [SAR 11378:11338 DAR 91024:51021], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #4, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-4.png':
  Duration: N/A, bitrate: N/A
    Stream #4:0: Video: png, rgb24, 1280x720 [SAR 72:72 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #5, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-5.png':
  Duration: N/A, bitrate: N/A
    Stream #5:0: Video: png, rgb24, 1280x720 [SAR 3779:3779 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #6, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-6.png':
  Duration: N/A, bitrate: N/A
    Stream #6:0: Video: png, rgb24, 1280x720 [SAR 100:100 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #7, png_pipe, from '/media/test/a0201d256f97c39d4f05-watermark-7.png':
  Duration: N/A, bitrate: N/A
    Stream #7:0: Video: png, rgb24, 1280x720 [SAR 72:72 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
[Parsed_blend_2 @ 0x1d8ce80] First input link top parameters (size 1280x720, SAR 5689:5669) do not match the corresponding second input link bottom parameters (1280x720, SAR 1:1)
[Parsed_blend_2 @ 0x1d8ce80] Failed to configure output pad on Parsed_blend_2

因此,我尝试在以下命令中指定 SAR:

ffmpeg -y -threads 2  -loop 1 -t 5 -i watermark-0.png -loop 1 -t 2.5 -i watermark-1.png -loop 1 -t 2.5 -iwatermark-2.png -loop 1 -t 2.5 -i watermark-3.png -loop 1 -t 2.5 -i4.png -loop 1 -t 2.5 -i watermark-5.png -loop 1 -t 2.5 -i watermark-6.png -loop 1 -t 2.5 -i watermark-7.png -filter_complex [0:v]setsar=1[sar0];[1:v][sar0]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b1v];[1:v]setsar=1[sar1];[2:v][sar1]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b2v];[2:v]setsar=1[sar2];[3:v][sar2]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b3v];[3:v]setsar=1[sar3];[4:v][sar3]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b4v];[4:v]setsar=1[sar4];[5:v][sar4]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b5v];[5:v]setsar=1[sar5];[6:v][sar5]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b6v];[6:v]setsar=1[sar6];[7:v][sar6]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b7v];[0:v][b1v][1:v][b2v][2:v][b3v][3:v][b4v][4:v][b5v][5:v][b6v][6:v][b7v][7:v]concat=n=15:v=1:a=0,format=yuv420p[v] -map [v] -c:v libx264 -r 120 -s 1280x720 -aspect 16:9 -crf 1 -preset ultrafast output.mp4

但是,我仍然收到完全相同的错误:第一个输入链接顶部参数(尺寸 1280x720,SAR 5689:5669)与相应的第二个输入链接底部参数不匹配(1280x720,SAR 1:1)

这是第一个问题。第二个问题是我需要让这个命令与 zoompan 过滤器一起运行,但我不知道从哪里开始让这个额外的过滤器工作,也不知道把它放在命令的什么位置。

帮助??

答案1

您必须事先设置所有 SAR。因此,[1:v][sar0]blend=..将失败,因为1:v仍然会出现不同的 SAR。[sar1][sar0]blend=..“将起作用,等等。

为每个输入图像预先在单独的命令中执行此操作并使用输出可能会更容易:

ffmpeg -i watermark-5.png -vf setsar=1 watermark-5n.png

相关内容