Overlay Logo Over Video With Transparency

This is typically used to burn in a video logo or copyright. You typically want to have a transparent PNG file to begin with.

ffmpeg -i video.mkv -i image.png -filter_complex "[1:v] scale=75:75 [scaled]; [scaled] format=argb,colorchannelmixer=aa=0.5 [logo];  [0:v][logo] overlay=x=20:y=main_h-overlay_h-(20) [out]" -map "[out]" -map 0:a -c:v libx264 -c:a copy -crf 18 -threads 4 output.mkv

Of course, this can be chained with other filters as well.

First, the incoming video is on 0:v, the image to overlay is on 1:v, the audio is on 0:a and copied through.
The complex filter graph scales the logo to a smaller size, in this case 75×75. This should depend on your video resolution, this is ok for 1080p, but you'll want smaller for lower resolutions.
Next, the image format is set to argb (which includes an alpha layer) and then then alpha layer is set to 0.5 for opacity. This makes the logo half transparent. You can change this depending on how 'faded' you want it to look.
Finally, the overlay positions the logo at the bottom left, with 20 px from the left and 20px from the bottom. This can be changes depending on which corner you want.
Note the use of main_h and overlay_h (or main_w and overlay_w) to be able to easily position in bottom or right corners.

The output from the filtergraph is mapped as the video track (and needs to be re-encoded), whereas the audio can be copied.

There is no need to use parameters like -shortest like when combining an image and audio.

  • scripts/ffmpeg/overlay_transparent_logo_over_video.txt
  • Last modified: 2023-03-27 02:04
  • by Tony