FFmpeg 视频叠加

FFmpeg 视频叠加

我正在尝试将输入视频与许多图像叠加,其中每个图像应显示一小段时间。我使用复杂过滤器(下面的命令)实现了这一点。问题是我有很多很多图像(>1000):-)

ffmpeg -y -i in.mp4 

-i logo1.png 
-i logo2.png 
-i logo3.png 

-filter_complex "

[0:v][1:v] overlay=10:10:enable='between(n,2,4)'    [tmp]; 
[tmp][2:v] overlay=30:30:enable='between(n,6,8)'    [tmp]; 
[tmp][3:v] overlay=50:50:enable='between(n,10,12)'; 

" out.mp4 

FFmpeg 是否允许用户通过文本文件传递这些数据?图像是在内存中生成的,因此管道也可以(实际上是首选)。

(如果不可能的话我可以将原始生成的视频传递到巴格拉格式?;但我不喜欢这样,因为混合操作更昂贵+更多 IO:必须尽可能快)


编辑:如果我使用以下配置,则只有最后发送的图像会被覆盖。

-i ski.mp4 
-f image2pipe -vcodec png -i -

-filter_complex "[0:v][1:v] overlay=10:10:enable='between(n,2,3)' [tmp]; 
                 [tmp][1:v] overlay=30:30:enable='between(n,6,7)'"

-f mp4", "out.mp4"

FFmpeg 输出(如果图像大小不同,它似乎会跳过它们):

 Input stream #1:0 frame changed from size:1417x665 fmt:rgba to size:1800x700 fmt:rgba
 Input stream #1:0 frame changed from size:1800x700 fmt:rgba to size:550x371 fmt:rgba
 Input stream #1:0 frame changed from size:550x371 fmt:rgba to size:256x256 fmt:rgba

我如何指示 FFmpeg,第一个过滤器使用第一幅图像,第二个过滤器使用管道中的第二幅图像,等等。(图像大小不同)?

答案1

如果您可以按序列输入图像,并指定叠加层xy时间限定符作为表达式,那么这可以作为可管理的命令。

-f image2pipe -vcodec png您可以使用作为输入选项通过管道输入图像。

此外,FFmpeg 可以从脚本中引用滤镜链

-filter_complex_script文件名(全球的)

该选项与 -filter_complex 类似,唯一的区别是其参数是要从中读取复杂过滤器图描述的文件的名称。

相关内容