Adjust Image Overlay Transparency in FFmpeg
This article provides a straightforward guide on how to change the transparency (opacity) of an image overlay using FFmpeg. You will learn the exact command-line arguments and video filters required to adjust the alpha channel of an overlay image before merging it onto a background video.
To adjust the transparency of an image overlay, you must use FFmpeg’s
filter_complex toolset. This process involves converting
the image to a format that supports transparency (RGBA), modifying its
alpha channel value, and then overlaying it onto the main video.
The Standard FFmpeg Command
The most efficient way to change overlay opacity is by using the
colorchannelmixer filter. Use the following command
structure:
ffmpeg -i input.mp4 -i overlay.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[ol];[0:v][ol]overlay=10:10" output.mp4Command Breakdown
-i input.mp4: Defines the primary background video.-i overlay.png: Defines the image you want to overlay.[1:v]: Selects the video stream of the second input (the image).format=rgba: Converts the image pixel format to RGBA to ensure it has an alpha (transparency) channel.colorchannelmixer=aa=0.5: Adjusts the alpha channel. Theaaparameter controls the alpha output. A value of0.5sets the transparency to 50%. You can adjust this value from0.0(completely invisible) to1.0(fully opaque).[ol]: Labels this modified image stream as “ol” (overlay).[0:v][ol]overlay=10:10: Places the modified image stream ([ol]) on top of the main video stream ([0:v]) at the coordinates X=10, Y=10.
Alternative Method: Using the LUT Filter
You can also use the lut filter to achieve the same
result by multiplying the existing alpha channel value:
ffmpeg -i input.mp4 -i overlay.png -filter_complex "[1:v]format=rgba,lut=a='val*0.5'[ol];[0:v][ol]overlay=W-w-10:H-h-10" output.mp4In this command, lut=a='val*0.5' multiplies the original
alpha value of the image by 0.5. This method is particularly useful if
your source image already has varying transparency levels that you want
to scale down proportionally. This example also places the overlay in
the bottom-right corner using W-w-10:H-h-10.