How to Animate Vignette Size Over Time in FFmpeg
This article demonstrates how to animate the vignette effect in
FFmpeg by using mathematical expressions within the
vignette filter. You will learn how to leverage built-in
variables like time (t) and frame number (n)
to create dynamic visual effects, such as pulsing vignettes or gradual
fades, directly from the command line.
The FFmpeg vignette filter uses the angle
parameter to control the size and reach of the dark vignette border. By
default, this parameter is a static value (usually PI/5),
but you can pass an equation wrapped in quotes to make it change
dynamically as the video plays.
The Math behind the Animation
To animate the filter, you must write an expression using FFmpeg’s
internal evaluation variables: * t: The
current timestamp of the frame in seconds. *
n: The sequential frame number (starting
at 0). * w & h: The width
and height of the input video. * PI: The
mathematical constant Pi (~3.14159).
In the vignette filter, a larger angle
value increases the size of the dark vignette area (bringing the
darkness closer to the center), while a smaller value pushes the
darkness to the outer edges.
Practical Examples
1. The Pulsing “Breathing” Vignette
To make the vignette smoothly expand and contract over time, you can
use the sine wave function (sin). The following command
oscillates the vignette angle around a base value of
PI/5:
ffmpeg -i input.mp4 -vf "vignette='angle=PI/5+sin(t)*0.15'" -c:a copy output.mp4sin(t)fluctuates between -1 and 1 over time.- Multiplying by
0.15scales the intensity of the pulse so the effect remains subtle.
2. Gradual Fade-In Vignette
If you want the vignette to start completely invisible and slowly
darken the edges of the video over a set number of seconds, you can use
a linear multiplier paired with the min function to cap the
maximum darkness:
ffmpeg -i input.mp4 -vf "vignette='angle=min(PI/3, t*0.1)'" -c:a copy output.mp4t*0.1increases the angle by 0.1 radians every second.min(PI/3, ...)ensures that once the vignette reachesPI/3(a moderately strong vignette), it stops growing and remains constant.
3. Frame-Based Fast Flicker
For a more chaotic or high-energy look (such as a horror film or old
projector effect), you can base the math on the frame count
(n) instead of time. This creates rapid transitions on
every frame:
ffmpeg -i input.mp4 -vf "vignette='angle=PI/5+random(1)*0.05'" -c:a copy output.mp4By substituting these expressions into your FFmpeg commands, you can customize the timing, frequency, and intensity of your vignette animations without needing to use external video editing software.