ffmpeg的视频滤镜: 抠图-chromakey

滤镜简述

chromakey

官网链接 =》 https://ffmpeg.org/ffmpeg-filters.html#chromakey-1

这个滤镜主要用于抠图,并且背景要是纯色背景,比如绿幕、蓝幕。

滤镜的使用

参数
   color             <color>      ..FV.....T. set the chromakey key color (default "black")
   similarity        <float>      ..FV.....T. set the chromakey similarity value (from 1e-05 to 1) (default 0.01)
   blend             <float>      ..FV.....T. set the chromakey key blend value (from 0 to 1) (default 0)
   yuv               <boolean>    ..FV.....T. color parameter is in yuv instead of rgb (default false)
  • color,要被过滤的颜色,可以写英文比如green(英文名称需要再`ffmpeg -colors` 能找到) ,也可以使用十六进制的字符串,比如"#ffefd5"
  • similarity,设置这个值可以过滤掉和color相似的颜色
  • blend, 这个值没有理解太透。 不过设置这个值会让图片变透明,一般也就在0.1-0.2之间。
  • yuv, 使用yuv格式的颜色,这是个布尔值。

color如果使用颜色的英文名字,效果不太好,也很麻烦,建议你使用十六进制字符串。如果你不清楚十六进制字符串,可以打开电脑上的画图软件,用吸管吸一下:

使用

原图

如果需要原图可以加群(结尾有群号)找我要一下哈。

ffmpeg -y -i ffm_media/snail.jpg -filter_complex "chromakey=#02fa03:0.2:0.1" result/chromakey/chromakey_test_2.png

大致看一下效果还不错,放大了看边缘还有些绿色,总体上还算不错了,如果进一步去除边缘的绿色,可以加大blend值,但是会出现锯齿:

ffmpeg -y -i ffm_media/snail.jpg -filter_complex "chromakey=#02fa03:0.2:0.5" result/chromakey/chromakey_test_3.png

 blend值比较大的时候就会变透明

下面是使用yuv格式的命令

ffmpeg -y -i ffm_media/snail.jpg -filter_complex "chromakey=0x962B15:0.2:0.1:true" result/chromakey/chromakey_test_yuv.png

rgb颜色值可以和yuv格式互换,具体操作可以百度一下哈,并且命令行只接受十六进制的值。

## 祝你好运
 
hope("大神多多指点")
topic("有问题可以交流呀")
concat("求求QUN", "61480", "9646")

猜你喜欢

转载自blog.csdn.net/u014686399/article/details/143190046
今日推荐