[FFmpeg-user] how to blend/overlay a logo with transparent background and a video into a resulting video with transparent effect

qw applemax82 at 163.com
Sat Jun 27 18:29:10 CEST 2015


Hi,


My question is, how to blend or overlay transparent logo and video into video with transparent effect by ffmpeg.


Transparent logo image is like the image with the below link. There is no color in the background of the logo image, so the background is transparent.
http://image.baidu.com/i?ct=503316480&z=0&tn=baiduimagedetail&ipn=d&word=透明png&step_word=&pn=25&spn=0&di=80391552560&pi=&rn=1&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=10980&cl=2&lm=-1&st=undefined&cs=3251494354%2C2495550648&os=1774513887%2C3280806179&adpicid=0&ln=1000&fr=%2Cala&fmq=1435421414339_R&ic=undefined&s=undefined&se=1&sme=0&tab=0&width=&height=&face=undefined&ist=&jit=&cg=&bdtype=0&objurl=http%3A%2F%2Fwww.mobanwang.com%2Ficon%2FUploadFiles_8971%2F200910%2F20091002141637406.png&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3B45kwgowg2_z%26e3Bv54AzdH3Ftv5gAzdH3FdaalAzdH3Fda9_n_z%26e3Bip4s


If there is no transparent background in the logo image, I can use the below command line to blend the logo image and a video into a video with transparent effect:


ffmpeg -i ./video.mp4 -i ./logo.png -filter_complex "[1]pad=640:480:10:10:black[logo];[0][logo]blend=all_expr='A*(if(gte(X,10)*lt(X,256+10)*gte(Y,10)*lt(Y,256+10),0.5,1))+B*(1-(if(gte(X,10)*lt(X,256+10)*gte(Y,10)*lt(Y,256+10),0.5,1)))'" -strict -2 ./output.mp4


I use filtergraph to do it. First, the logo is sent to pad filter to change the size of logo image, then the changed logo image is sent to blend filter. In blend filter, position information is used to only blend the area of logo image.


But if there is transparent background in logo image, the resulting video is not good and I can see a clear rectangle around the logo. The transparent logo image is sent to pad filter first, in which the transparent background in the logo image is filled with unspecified color. Then a rectangular image where the logo centers is sent to blend filter. Therefore, there is a clear rectangle around the logo in the resulting video.


If I just use overaly filter to play a transparent logo on  a video, the resulting video is good. I can see the pixel of input video in the area of the background of the logo. But the logo area is not transparent in the resulting video.


ffmpeg -i ./video.mp4 -i ./logo.png -filter_complex overlay -strict -2 ./output.mp4


How to make a resulting video, in which the pxiel of input video can be seen in the area of the background of the logo, and the logo area is transparent in the resulting video?


Thanks!


B.R.


Andrew


More information about the ffmpeg-user mailing list