如何在 ffmpeg 的混合过滤器中使用多个 between 语句

How to use multiple between statements with the blend filter in ffmpeg

下面的命令使用具有 between 语句的 t 变量的 *if 表达式的二进制将 input2 混合到 input1 中。因此,output = input1,但 input200:00:03- 00:00:05:

ffmpeg -y -i input1.mkv -i input2.mkv -filter_complex "[1:v][0:v]scale2ref[v1][v0];[v0][v1]blend=all_expr='A*if(between(T, 3, 5), 0, 1)+B*if(between(T, 3, 5), 1, 0)'" -vcodec libx264 -pix_fmt yuv444p -crf 18 -acodec copy output.mkv

我的问题是在一组评估条件的情况下如何将这些链接在一起。我尝试了下面的 + 运算符,但 input1 不再相同。它似乎被视频的多层扭曲了。

ffmpeg -y -i input1.mkv -i input2.mkv -filter_complex "[1:v][0:v]scale2ref[v1][v0];[v0][v1]blend=all_expr='A*if(between(T, 3, 5), 0, 1)+B*if(between(T, 3, 5), 1, 0)'+'A*if(between(T, 7, 9), 0, 1)+B*if(between(T, 7, 9), 1, 0)'" -vcodec libx264 -pix_fmt yuv444p -crf 18 -acodec copy output.mkv

如何在不产生视觉伪影的情况下将这些链接在一起?

此问题是 的后续问题。

如果您只想在 [3, 5] 和 [7, 9] 之间 [v1],否则 [v0],请确保 B 乘以 [= {[3, 5], [7, 9]} 和 A 之间的 14=] 乘以 {[3, 5], [7, 9]} 之间的 0,反之亦然。

我们可以使用以下命令:

ffmpeg -y -i input1.mkv -i input2.mkv -filter_complex "[1:v][0:v]scale2ref[v1][v0];[v0][v1]blend=all_expr='A*not((between(T, 3, 5)+between(T, 7, 9)))+B*(between(T, 3, 5)+between(T, 7, 9))'" -vcodec libx264 -pix_fmt yuv444p -crf 18 -acodec copy output.mkv

因为只有 01,我们不必使用 if 表达式。

根据 Expression Evaluation 文档:

between(x, min, max)
Return 1 if x is greater than or equal to min and lesser than or equal to max, 0 otherwise.

not(expr)
Return 1.0 if expr is zero, 0.0 otherwise.

  • (between(T, 3, 5)+between(T, 7, 9)) 在 {[3, 5], [7, 9]} 范围内计算为 1,否则计算为 0
  • not(between(T, 3, 5)+between(T, 7, 9)) 在 {[3, 5], [7, 9]} 范围内计算为 0,否则计算为 1