首页 > 解决方案 > FFMPEG:使用带有复杂过滤器的视频过滤器

问题描述

我正在使用fluent-ffmpegNode.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.

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

标签: node.jsffmpegvideo-processingfluent-ffmpeg

解决方案


通过学习一些关于过滤器图的基础知识解决了这个问题。这是完整的 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=>使用输入1(png 文件)将覆盖过滤器应用于流。

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


推荐阅读