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).
h(Hue): Specifies the hue rotation angle. You can define this in degrees (e.g.,90) or in radians (using theHvariable).s(Saturation): Controls the color intensity. The value ranges from-10to10, with1being the default. A value of0removes all color, resulting in a grayscale video.b(Brightness): Adjusts the brightness level. The value ranges from-10to10, with0being the default.
The basic syntax for applying the filter is:
ffmpeg -i input.mp4 -vf "hue=h=HUE_VAL:s=SAT_VAL:b=BRIGHT_VAL" output.mp4Practical 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.mp4Alternatively, 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.mp42. 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.mp4To 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.mp43. 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.mp4To darken the video, use a negative value:
ffmpeg -i input.mp4 -vf "hue=b=-1.5" output.mp44. 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.mp4Creating 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.mp4Pulsing 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