Shift Video Colors Over Time with FFmpeg Hue Filter

Shifting the color spectrum of a video over time is a great way to create psychedelic visual effects, transition elements, or dynamic color corrections. By utilizing FFmpeg's built-in hue filter paired with time-based expressions, you can continuously rotate the hue of a video as it plays. This guide will show you how to write the exact FFmpeg command required to achieve this effect and how to customize the speed of the color shift.

To shift the color spectrum over time, you must apply the hue filter and define the hue angle (h) using an expression containing the variable t, which represents the current timestamp of the video in seconds.

Here is the basic command to continuously shift the video colors:

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

How the Command Works

  • -i input.mp4: Specifies the input video file.
  • -vf "hue=h='t*90'": Applies the video filter. The hue filter modifies the color, and the h parameter defines the hue angle in degrees. By setting h to 't*90', the hue angle increases by 90 degrees for every second of video playback.
  • -c:a copy: Copies the audio stream directly without re-encoding to save time and preserve quality.
  • output.mp4: The resulting video file with the shifting color effect.

Controlling the Speed of the Color Shift

You can easily adjust how quickly the colors cycle through the spectrum by changing the multiplier in the math expression:

  • Fast Color Cycle: To cycle through the entire color spectrum (360 degrees) every second, use a multiplier of 360:

    ffmpeg -i input.mp4 -vf "hue=h='t*360'" -c:a copy output.mp4
  • Slow Color Cycle: For a very slow, subtle transition of colors, use a lower multiplier like 10 or 20:

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

Advanced: Oscillating Colors

If you want the colors to shift back and forth within a specific range rather than spinning infinitely through the spectrum, you can use the sine wave function (sin):

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

In this command, the hue angle will smoothly oscillate back and forth between -180 and 180 degrees over time.