How to Pulse Saturation in FFmpeg Using Hue Filter
This article explains how to program the saturation of a video to
pulse rhythmically using the hue filter in FFmpeg. By
applying mathematical expressions containing sine waves and time
variables to the saturation parameter, you can create dynamic,
oscillating color effects without needing complex video editing
software.
To make the saturation pulse rhythmically, you must use the
s (saturation) parameter of FFmpeg’s hue
filter and assign it an expression that varies over time. The
mathematical formula for a rhythmic pulse relies on the sine
(sin) function, using the frame timestamp (t)
as the driving variable.
The Basic Command
Here is the standard FFmpeg command to apply a rhythmic saturation pulse:
ffmpeg -i input.mp4 -vf "hue=s='1 + 0.8*sin(2*PI*1*t)'" -c:a copy output.mp4Breakdown of the Saturation Expression
The expression '1 + 0.8*sin(2*PI*1*t)' controls how the
saturation behaves over time:
s=: Specifies that we are modifying the saturation.1(Baseline): The default saturation level. A value of1represents normal color,0is completely grayscale, and values above1are oversaturated.0.8(Amplitude): Controls the intensity of the pulse. With a baseline of1and an amplitude of0.8, the saturation will swing between0.2(nearly grayscale) and1.8(highly saturated).sin(...): The trigonometric sine function that creates the smooth, repeating wave.2*PI: A constant required to align the sine wave frequency with standard seconds.1(Frequency): The speed of the pulse in Hertz (cycles per second). In this example,1means the video will complete one full pulse cycle every second.t: The current timestamp of the frame in seconds. FFmpeg evaluates this variable for every frame to calculate the changing saturation.
Customizing the Pulse
You can adjust the math inside the expression to change the rhythm and style of the pulse:
Speed Up the Pulse: To make the saturation pulse twice as fast (two times per second), change the frequency multiplier from
1to2:hue=s='1 + 0.8*sin(2*PI*2*t)'Slow Down the Pulse: To make the pulse occur once every four seconds, change the frequency multiplier to
0.25:hue=s='1 + 0.8*sin(2*PI*0.25*t)'Prevent Grayscale (Subtle Pulse): If you want the video to remain colorful and only pulse slightly, lower the amplitude:
hue=s='1 + 0.3*sin(2*PI*1*t)'