FFMPEG:将视频过滤器与复杂过滤器结合使用

时间:2019-04-01 13:08:55

标签: node.js ffmpeg video-processing fluent-ffmpeg

我正在使用fluent-ffmpeg Node.js库对视频文件执行批处理。裁剪16:9输入的视频过滤器,添加填充并将字幕刻录到填充中。

在下一步中,我想使用复杂的滤镜将图像叠加为水印。

ff.input(video.mp4)
ff.input(watermark.png)
ff.videoFilter([
  'crop=in_w-2*150:in_h',
  'pad=980:980:x=0:y=0:color=black',
  'subtitles=subtitles.ass'
])
ff.complexFilter([
  'overlay=0:0'
])
ff.output(output.mp4)

但是,运行此命令时,出现以下错误:

Filtergraph 'crop=in_w-2*150:in_h,pad=980:980:x=0:y=0:color=black,subtitles=subtitles.ass' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a comple.
-vf/-af/-filter and -filter_complex cannot be used together for the same stream.

据我了解,视频过滤器和复杂的过滤器选项不能一起使用。如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

通过学习有关过滤器图的一些基础知识来解决此问题。这是完整的ffmpeg命令。我发现逐行写出过滤器字符串时更容易阅读。

ffmpeg \
-i video.mp4 \
-i watermark.png \
-filter_complex " \
  [0]crop = \
    w = in_w-2*150 : \
    h = in_h \
    [a] ;
  [a]pad = \
    width = 980 : \
    height = 980 : \
    x = 0 :
    y = 0 :
    color = black
    [b] ;
  [b]subtitles = 
    filename = subtitles.ass
    [c] ;
  [c][1]overlay = \
    x = 0 :
    y = 0
  " \
output.mp4

说明:

[0]crop=...[a]; =>首先将裁剪过滤器应用于视频输入0。将结果命名为a

[a]pad=...[b]; =>将填充滤镜应用于a流。将结果命名为b

[b]subtitles=...[c] =>将字幕过滤器应用于b流。将结果命名为c

[c][1]overlay... =>使用输入c(png文件)将覆盖过滤器应用于流1

希望这可以帮助那些在过滤器图上苦苦挣扎的人。

答案 1 :(得分:0)

带有3个徽标和1个文本滚动的简单语法

ffmpeg
    .complexFilter([

        {
            filter: 'overlay',
            options: { x: 100, y: 100 },
            inputs: 0, outputs: '1'

        },
        {
            filter: 'overlay',
            options: { x: 200, y: 200 },
            inputs: '1', outputs: '2'

        },
        {
            filter: 'overlay',
            options: { x: 300, y: 300 },
            inputs: '2', outputs: '3'

        },
        {
            filter: 'drawtext',
            options: {
            // outputs: 1,
            fontfile:'/usr/share/fonts/dejavu/DejaVuSans.ttf',
            text: 'some text',
            fontsize: 40,
            fontcolor: 'white',
            x: 'w-w/10*mod(t,10*(w+tw)/w)',
            y: 'h-line_h',
            shadowcolor: 'black',
            shadowx: 3,
            shadowy: 3,
            },
            inputs: '3',
          },
        ])