How to Adjust Video Color with FFmpeg Hue Filter

This guide explains how to use the hue filter in FFmpeg to manipulate the color, saturation, and brightness of your videos. You will learn the basic syntax of the filter, explore practical examples for adjusting color tones, and discover how to apply dynamic color transitions over time using FFmpeg’s command-line interface.

Understanding the Hue Filter Syntax

The hue filter in FFmpeg accepts three primary parameters: hue (h), saturation (s), and brightness (b).

The basic syntax for applying the filter is:

ffmpeg -i input.mp4 -vf "hue=h=HUE_VAL:s=SAT_VAL:b=BRIGHT_VAL" output.mp4

Practical Examples

1. Rotating the Hue (Color Shift)

To shift the colors of your video, rotate the hue angle. For example, to shift the hue by 90 degrees:

ffmpeg -i input.mp4 -vf "hue=h=90" output.mp4

Alternatively, you can specify the angle in radians. To shift the hue by PI/2 radians (equivalent to 90 degrees):

ffmpeg -i input.mp4 -vf "hue=H=PI/2" output.mp4

2. Changing Video Saturation

To make a video black and white (grayscale), set the saturation to 0:

ffmpeg -i input.mp4 -vf "hue=s=0" output.mp4

To boost the color saturation and make the colors more vibrant, set the saturation to a value greater than 1 (e.g., 1.8):

ffmpeg -i input.mp4 -vf "hue=s=1.8" output.mp4

3. Adjusting Brightness

To increase the brightness of a video, set the b parameter to a positive value:

ffmpeg -i input.mp4 -vf "hue=b=2" output.mp4

To darken the video, use a negative value:

ffmpeg -i input.mp4 -vf "hue=b=-1.5" output.mp4

4. Combining Hue, Saturation, and Brightness

You can adjust all three parameters simultaneously. The following command shifts the hue by 45 degrees, increases saturation to 1.5, and raises brightness to 1:

ffmpeg -i input.mp4 -vf "hue=h=45:s=1.5:b=1" output.mp4

Creating Dynamic Effects

FFmpeg allows you to use mathematical expressions and time variables to change colors dynamically as the video plays. The variable t represents the current timestamp in seconds.

Creating a Rainbow Color Loop

To continuously rotate the hue angle over time, you can multiply the time variable t by the desired degrees of rotation per second. The following command rotates the hue by 90 degrees every second:

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

Pulsing Saturation Effect

You can use trigonometric functions like sin or cos to create pulsing effects. This command pulsates the saturation between normal and high intensity over time:

ffmpeg -i input.mp4 -vf "hue=s='1+sin(t)'" output.mp4