Search code examples
videofilterffmpegtransparencyalpha

ffmpeg: overlay a png image on a video with custom transparency?


Suppose I have a video foo.mkv and an image bar.png (which happens to contains an alpha channel). I can blend this image over the video like this:

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

(using multiple lines here for readability, normally this is one command line).

Now, besides the png image having an alpha channel of its own, I would also apply a custom overall transparency when blending this image over the video.

In the above example, the image would be visible 100% on top of the video — or at least the parts where its alpha channel is fully opaque.

Is there a way to add a custom overall opacity or transparency blend factor, something like opacity=0.5 or whatever, which would make the image only 50% visible?


Solution

  • Another option besides geq is colorchannelmixer.

    [1:v]format=argb,colorchannelmixer=aa=0.5[zork]