FFmpeg Hue Filter Equation for Time-Based Shift
This article explains how to use the FFmpeg hue filter
with time-based expressions to dynamically shift the colors of a video
over time. You will learn the correct syntax, the difference between the
degree and radian parameters, and practical command-line examples to
create smooth, cycling color effects.
To shift the hue over time in FFmpeg, you must apply the
hue video filter and use the time variable t
(which represents the current timestamp in seconds) within the hue
expression.
Understanding the
Parameters: h vs H
The FFmpeg hue filter accepts two different parameters
to control the hue angle: * h (lowercase):
Sets the hue rotation angle in degrees (from -360 to
360). * H (uppercase): Sets the hue
rotation angle in radians (from -PI to PI).
Example 1: Shifting Hue in Degrees (Simplest Method)
To shift the hue continuously at a set rate of degrees per second,
use the lowercase h parameter.
The following command shifts the hue by 90 degrees every second:
ffmpeg -i input.mp4 -vf "hue=h='t*90'" -c:a copy output.mp4In this equation: * t is the current time in seconds. *
90 is the speed of the shift (degrees per second). At 4
seconds, the hue will have shifted by 360 degrees, completing one full
color cycle.
Example 2: Shifting Hue in Radians
If you prefer to work with radians, use the uppercase H
parameter. Since a full color rotation in radians is \(2\pi\) (approximately 6.28), you can define
a cycle based on time.
The following command completes one full hue rotation every 10 seconds:
ffmpeg -i input.mp4 -vf "hue=H='2*PI*t/10'" -c:a copy output.mp4In this equation: * 2*PI represents a full \(360^{\circ}\) rotation. * t is
the elapsed time. * /10 divides the rotation so it takes
exactly 10 seconds to complete one loop.
Adjusting Speed and Direction
You can easily customize the speed and direction of the color shift:
* Speed up the shift: Increase the multiplier (e.g.,
h='t*180' shifts twice as fast as h='t*90'). *
Slow down the shift: Decrease the multiplier (e.g.,
h='t*30'). * Reverse direction: Use a
negative value (e.g., h='-t*90').