How to Shift Video Hue Over Time Using FFmpeg

This article explains how to use FFmpeg's hue video filter to animate and shift the color spectrum of a video continuously over its duration. By binding the filter's hue angle parameter to the video's playback timestamp, you can achieve smooth, psychedelic, or dynamic color-cycling effects without requiring complex video editing software.

Understanding the Hue Filter

FFmpeg includes a video filter named hue that adjusts hue, saturation, and brightness. To shift color over time, you manipulate the hue angle (h for degrees, or H for radians).

Instead of passing a static number, you pass a mathematical expression that evaluates dynamically for every frame. The filter provides built-in variables for this purpose:

  • t: The current presentation timestamp in seconds.
  • n: The sequential frame number, starting at 0.
  • r: The frame rate of the video.

Basic Command Syntax

To rotate the hue based on time, use the -vf (video filter) flag and define the h parameter inside quotes:

ffmpeg -i input.mp4 -vf "hue=h='60*t'" -c:a copy output.mp4

In this command:

  • -i input.mp4: Specifies the input file.
  • -vf "hue=h='60*t'": Shifts the hue angle by 60 degrees per second.
  • -c:a copy: Copies the audio stream without re-encoding to preserve quality and speed up processing.
  • output.mp4: The output file name.

Controlling the Speed of the Shift

Because a full color rotation spans 360 degrees, you can control the exact speed of the cycle by adjusting the formula:

One full rotation every 10 seconds:

ffmpeg -i input.mp4 -vf "hue=h='(360/10)*t'" -c:a copy output.mp4

One full rotation every 2 seconds (faster shift):

ffmpeg -i input.mp4 -vf "hue=h='180*t'" -c:a copy output.mp4

Advanced Examples

Modulo Cycling

To prevent the degree value from growing indefinitely, wrap the expression with the modulo operator (mod):

ffmpeg -i input.mp4 -vf "hue=h='mod(72*t, 360)'" -c:a copy output.mp4

This rotates the hue 72 degrees per second, completing a full spectrum cycle every 5 seconds, resetting cleanly at 360 degrees.

Frame-Based Rotation

If you want the shift tied strictly to the number of processed frames rather than wall-clock time:

ffmpeg -i input.mp4 -vf "hue=h='n*2'" -c:a copy output.mp4

This shifts the hue by 2 degrees for every processed video frame.

Combining Hue Shift with Saturation

You can alter saturation (s) simultaneously to prevent colors from washing out or to create high-contrast effects:

ffmpeg -i input.mp4 -vf "hue=h='60*t':s=1.5" -c:a copy output.mp4

This applies the continuous hue rotation while increasing the color saturation by 50%.