'ffmpeg - overlay filter alpha premultiplied performs brighter on transparent images

Description

I'm using ffmpeg's overlay filter with alpha premultiplied parameter. I noticed that when a completely transparent image was overlay to the background video, the output video was much brighter.

In the following demo, I will use RGBA8888 format images for overlay. Its use of RGBA (255,255,255,0) indicates full transparency (aka completely transparent white), and the result demonstrates a very noticeable brightening (the expected result should be unchanged, since the image is completely transparent). ps: Using RGBA (0,0,0,0) (aka completely transparent black) also results in a brightened image.

Code (overlay transparent white)

ffmpeg.exe  -loglevel debug -i a1.mp4 -i a1.png -filter_complex "[0:v][1:v]overlay=x=0:y=0:alpha=premultiplied[v]" -map "[v]"  -c:v:0 libx264 -f mp4  output.mp4

result_img_white

Code (overlay transparent black)

This command uses lavfi to simulate the transparent black output of RGBA. For demonstration purposes only, you may need ctrl+c to prevent infinite output.

ffmpeg.exe -y -i a1.mp4 -f lavfi -i "[email protected]:size=1920x540,format=rgba" -filter_complex "[0:v][1:v]overlay=x=0:y=0:alpha=premultiplied[v]" -map "[v]"  -c:v:0 libx264 -f mp4  output.mp4

result_black_img

The results show that the upper part is more whitish (brighter).

Related files can be downloaded here: https://gist.github.com/windowsair/5315437a97dadf3f74f886486657183d


Back to the question, I had to use premultiplied to get the correct overlay result: Using the straight option will have a darkening effect in areas that are not fully transparent, which is why I insisted on premultiplied . Is this a ffmpeg problem? How should I avoid the undesirable effect of brighter images from transparent image overlays? Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source