FFmpeg Overlay PNG with Transparency Over Time
This article explains how to overlay a transparent PNG image onto a video and dynamically control its opacity over time using FFmpeg. You will learn the exact command-line syntax needed to fade a logo or watermark in and out, apply constant custom transparency, or create advanced pulsing opacity effects using FFmpeg’s powerful filtering tools.
Method 1: Fading a PNG In and Out (Time-Based Opacity)
To make a transparent PNG fade in at a specific time and fade out
later, you can combine the fade filter (targeting the alpha
channel) with the overlay filter inside a
filter_complex graph.
Use the following command:
ffmpeg -i input.mp4 -loop 1 -i logo.png -filter_complex \
"[1:v]format=rgba,fade=in:st=2:d=1:alpha=1,fade=out:st=7:d=1:alpha=1[logo]; \
[0:v][logo]overlay=x=10:y=10:shortest=1" \
-c:a copy output.mp4How This Command Works:
-loop 1 -i logo.png: Loops the single PNG image indefinitely so it can exist for the duration of the video.format=rgba: Ensures the image is processed with an alpha (transparency) channel.fade=in:st=2:d=1:alpha=1: Fades the image in starting at second 2 (st=2) for a duration of 1 second (d=1). Thealpha=1parameter tells FFmpeg to apply the fade to the transparency channel rather than fading to black.fade=out:st=7:d=1:alpha=1: Fades the image out starting at second 7 (st=7) for a duration of 1 second (d=1).overlay=x=10:y=10:shortest=1: Overlays the processed logo at the coordinates X=10, Y=10. Theshortest=1parameter is crucial; it forces the output to stop encoding when the main video input ends, preventing an infinite loop caused by the looped PNG.
Method 2: Applying a Constant Custom Transparency
If you want the PNG overlay to have a fixed, semi-transparent opacity
(for example, 50% opacity) throughout the entire video, you can use the
colorchannelmixer filter to adjust the alpha channel.
Use this command:
ffmpeg -i input.mp4 -i logo.png -filter_complex \
"[1:v]format=rgba,colorchannelmixer=aa=0.5[logo]; \
[0:v][logo]overlay=10:10" \
-c:a copy output.mp4How This Command Works:
colorchannelmixer=aa=0.5: Modifies the input’s alpha channel. The value foraa(Alpha-Alpha) ranges from0.0(fully invisible) to1.0(fully opaque). Setting it to0.5gives the PNG 50% opacity.
Method 3: Advanced Dynamic Transparency (Pulsing Effect)
For advanced scenarios where transparency needs to fluctuate
continuously over time (such as a pulsing watermark), you can pass
mathematical expressions using the time variable (t) to the
colorchannelmixer filter.
Use this command to create a pulsing opacity effect:
ffmpeg -i input.mp4 -loop 1 -i logo.png -filter_complex \
"[1:v]format=rgba,colorchannelmixer=aa='0.5+0.5*sin(2*PI*t/3)'[logo]; \
[0:v][logo]overlay=10:10:shortest=1" \
-c:a copy output.mp4How This Command Works:
aa='0.5+0.5*sin(2*PI*t/3)': This expression continuously calculates the alpha value based on the current video timestamp (t).- It uses a sine wave (
sin) to oscillate the opacity smoothly. - The opacity will wave back and forth between
0.0(invisible) and1.0(fully opaque) every 3 seconds.
- It uses a sine wave (