Ffmpeg: overlay png image on video with custom transparency?

Suppose I have a video foo.mkv and an image bar.png (which has an alpha channel). I can mix this image over the video as follows:

 ffmpeg -i foo.mkv -i bar.png -filter_complex "[0:v][1:v]overlay" -vcodec libx264 myresult.mkv 

(using a few lines here for readability, usually one command line).

Now, in addition to the png image, which has its own alpha channel, I would also apply general transparency when blending this image on video.

In the example above, the image will be 100% visible on top of the video - or at least the part where its alpha channel is completely opaque.

Is there a way to add a custom general transparency or transparency ratio, something like opacity=0.5 or something else that would make the image only 50% visible?

+7
filter ffmpeg transparency video alpha
source share
2 answers

Another option besides geq is colorchannelmixer .

 [1:v]format=argb,colorchannelmixer=aa=0.5[zork] 
+8
source share

I think I get it:

 ffmpeg -i foo.mkv -i bar.png -filter_complex "[1:v]format=argb,geq=r='r(X,Y)':a='0.5*alpha(X,Y)'[zork]; [0:v][zork]overlay" -vcodec libx264 myresult.mkv 

Where 0.5 is the opacity coefficient. I turn on format=argb , so it also works with overlay images that don't have an alpha channel.

+6
source share

All Articles