node.js - 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.
据我了解,视频过滤器和复杂过滤器选项不能一起使用。如何解决这个问题?
解决方案
通过学习一些关于过滤器图的基础知识解决了这个问题。这是完整的 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 文件)将覆盖过滤器应用于流。
希望这可以帮助那些在过滤图上苦苦挣扎的人。
推荐阅读
- sql - 将 SQL 查询转换为 Pig 查询
- c++ - C++ 函数以退出代码退出循环无
- android - 如何以及需要做什么才能在 android 上使用 CAN?
- c# - 如何在 xamarin Android 中裁剪旋转的图像?
- flexbox - Angular Material Flex Layout - 使 div 宽度适合内容
- python - 有没有办法对 BeautifulSoup 进行逆向工程?将csv内容转换为html?
- c# - 支架后的实体框架核心导航属性命名约定
- python - 大地理空间数据技术解决方案
- node.js - 共享主机上的 Angular SSR,
- azure - 从 Azure SQL 仓库中清除或删除旧数据