如何在不将图像蒙版应用于视频的情况下创建圆形视频视频顶部的透明区域效果

问题描述

基本上我在谷歌上搜索了很多,解决方案建议应用一些 PNG 掩码或不提供所需的解决方案。

我发现了什么。

ffmpeg -i main.mkv -i facecloseup.mkv
 -filter_complex "[1]trim=end_frame=1,geq='st(3,pow(X-(W/2),2)+pow(Y-(H/2),2));if(lte(ld(3),pow(min(W/2,H/2),2)),255,0)':128:128,loop=-1:1,setpts=N/FRAME_RATE/TB[mask];
  [1][mask]alphamerge[cutout];
  [0][cutout]overlay=x=W-w:y=0[v];
  [0][1]amix=2[a]"
 -map "[v]" -map "[a]"  out.mp4
command = "-i " + this.video1Path.getPath() + " -i " + this.video2Path.getPath() + " -filter_complex [1]trim=end_frame=1,geq=lum_expr='st(3," + (this.mZoomLayout.getZoomedWidth()/2) + "*" + (this.mZoomLayout.getZoomedWidth()/2) + "),format=gray,setpts=N/FRAME_RATE/TB[mask];[1][mask]alphamerge,format=rgba,lutrgb=a=if(gte(val\\,16)\\,val)[cutout];[0][cutout]overlay=" + this.mZoomLayout.getCircleX() + ":" + this.mZoomLayout.getCircleY() + ":enable='between(t," + this.videoTwoDuration + ") -c:v libx264 -crf 24 -preset ultrafast " + videoPath.getPath(); 

所以我试图从它们中提取需要的东西,但我不明白我到底需要怎么做,我这样做了:

ffmpeg -i video.mp4 -filter_complex "[0]geq='st(3,0)':H:W; [0:v][mask]alphamerge" out.mp4
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001f761dd8e40] Invalid stream specifier: mask.
    Last message repeated 1 times
Stream specifier 'mask' in filtergraph description [0]geq='st(3,0)':H:W; [0:v][mask]alphamerge matches no streams.
ffmpeg -i video.mp4 -filter_complex "[0]geq=lum_expr='st(3,mj2 @ 000001bfd9218e80] Invalid stream specifier: mask.
    Last message repeated 1 times
Stream specifier 'mask' in filtergraph description [0]geq=lum_expr='st(3,0)':H:W; [0:v][mask]alphamerge matches no streams.

还有一次,伙计们,如果您要发布一些“准备好的图像蒙版解决方案 - 离开吧,问题是关于在空中创建蒙版

所以,假设我们有红色方块(是的,比率是静态的,始终为 1:1),是的,我不能发布它,因为我没有 10 代表。 (...).

https://i.stack.imgur.com/MsL71.png - 红色方块。

https://i.stack.imgur.com/aIFEV.png - 圈子

https://i.stack.imgur.com/R8EAx.png - 结果

https://i.stack.imgur.com/WtqQg.png - 最终结果

我实际上想从@Gyan 或 @llogan 那里得到答案,因为我搜索了很多,只有这两个人知道如何以编程方式制作东西。

更多技术细节: 纵横比固定 - 1:1,宽度和高度应以自动方式从视频中获取,我们需要创建一个内部带有透明圆圈的白色正方形,最终结果必须包含带有白色背景的“圆形”视频。>

解决方法

您可以使用以下图像复制您的“最终结果”:

2 个输入

red vignette over blue circle

height 变量的值应与源文件的高度匹配。在本例中为 600 像素。

red="red.png"
blue="blue.png"

height=600

ffmpeg \
-loop 1 -i "${red}" \
-loop 1 -i "${blue}" \
-filter_complex "\
[1]format=yuva444p,geq=lum='p(X,Y)':a='st(1,pow(min(W/2,H/2),2))+st(3,pow(X-(W/2),2)+pow(Y-(H/2),2));if(lte(ld(3),ld(1)),255,0)'[circular shaped video];\
[circular shaped video]scale=w=-1:h=${height}[circular shaped video small];\
[0][circular shaped video small]overlay" \
-filter_complex_threads 1 \
-c:v libx264 \
-preset ultrafast \
-t 5 \
"final_result.mp4"

使用图像时,您只需要输入前面的 -loop 1 选项。

如果您使用的是视频,您可以决定使用哪种音频。

您可以在我原来的 post 中详细查看所有内容。

仅 1 个输入

red vignette over blue circle

在这里您只需选择圆形小插图的颜色。

颜色名称列在 documentation 中。

in="blue.png"

vignette_color="red"

ffmpeg \
-loop 1 -i "${in}" \
-filter_complex "\
[0]setsar=1:1,format=yuva444p,drawbox=color=${vignette_color}@1:t=fill[vignette];\
[0]format=yuva444p,0)'[circular shaped video];\
[vignette][circular shaped video]overlay" \
-filter_complex_threads 1 \
-c:v libx264 \
-preset ultrafast \
-t 5 \
"result.mp4"

1 个视频自动平方

包括音频。抗锯齿晕影边缘。

enter image description here

in="snowboarder.mp4"

vignette_color="black"

# edge of vignette can be jagged. 
# use value between 1 - 2 (e.g. 1.2). 1 doesn't do anything.
anti_aliasing=2

ffmpeg \
-i "${in}" \
-filter_complex "\
[0:v]crop=ih:ih[video square];[video square]split=2[video square 1][video square 2];\
[video square 1]setsar=1:1,drawbox=color=${vignette_color}@1:t=fill[vignette];\
[video square 2]scale=w=iw*"${anti_aliasing}":h=iw*"${anti_aliasing}",0)'[scaled up circular shaped video];\
[scaled up circular shaped video]scale=w=iw/"${anti_aliasing}":h=iw/"${anti_aliasing}"[circular shaped video];\
[vignette][circular shaped video]overlay" \
-filter_complex_threads 1 \
-c:v libx264 \
-c:a aac \
-preset ultrafast \
"result_square.mp4"