根据examples https://ffmpeg.org/ffmpeg-filters.html#toc-Examples-41在文档中,我们可以将框架乘以评估条件。
示例(输入来自here https://superuser.com/a/1704747/635712):
ffmpeg -y -i in.mp4 -i in.gif -filter_complex "[1:v][0:v]scale2ref[v1][v0];[v0][v1]blend=all_expr='A*if(between(T, 2, 6), 0.3, 1)+B*if(between(T, 2, 6), 0.7, 0)'" -vcodec libx264 -pix_fmt yuv444p -crf 17 -acodec copy out.mp4
-
A
应用第一个视频流中的帧 -[v0]
.
-
B
应用第二个视频流中的帧 -[v1]
.
-
if(between(T, 2, 6), 0.3, 1)
被评估为0.3
当时间在 2 到 6 秒之间时,评估为1
否则。
-
if(between(T, 2, 6), 0.7, 0)
被评估为0.7
当时间在 2 到 6 秒之间时,评估为0
否则。
- 整个表达式计算为
0.3*A + 0.7*B
2 到 6 之间并且1*A + 0*B
否则。
Sample output (between 2 and 6 seconds):
Note:
我认为确切时间存在错误,但这可能与我的输入有关。
我们也可以链两个blend
如果需要的话可以过滤。
第一个混合应用一些混合效果,第二个混合选择何时使用该效果以及何时使用原始视频流。
例子:
ffmpeg -y -i in.mp4 -i in.gif -filter_complex "[1:v][0:v]scale2ref[v1][v0];[v0][v1]blend=all_mode=grainextract[b];[0:v][b]blend=all_expr='A*if(between(T, 2, 6), 0, 1)+B*if(between(T, 2, 6), 1, 0)'" -vcodec libx264 -pix_fmt yuv444p -crf 17 -acodec copy out.mp4
另一种选择是链接blend
with overlay
filter.