Adjust RGB Shadows Midtones Highlights in FFmpeg
This article provides a quick and practical guide on how to use the
FFmpeg colorbalance filter to adjust the shadows, midtones,
and highlights of the red, green, and blue channels independently. You
will learn the exact syntax, the meaning of each parameter, and how to
apply these color grading adjustments to your video files via the
command line.
The FFmpeg colorbalance filter adjusts the color balance
of an input video by modifying the intensity of the red, green, and blue
(RGB) channels across three distinct tonal ranges: shadows, midtones,
and highlights.
The Filter Parameters
The filter uses specific two-letter codes to target each channel and tonal range. The syntax is structured as follows:
- Shadows (s): Adjusts the darkest areas of the
image.
rs: Red shadowsgs: Green shadowsbs: Blue shadows
- Midtones (m): Adjusts the mid-range grays and skin
tones.
rm: Red midtonesgm: Green midtonesbm: Blue midtones
- Highlights (h): Adjusts the brightest areas of the
image.
rh: Red highlightsgh: Green highlightsbh: Blue highlights
Value Ranges and Behavior
Each parameter accepts a float value between
-1.0 and 1.0.
0.0represents no change (the default).- Positive values shift the balance toward the chosen color (Red, Green, or Blue).
- Negative values shift the balance toward the
complementary color (Cyan, Magenta, or Yellow). For example, decreasing
red (
-1.0) increases cyan.
Command Example
To apply these adjustments, use the -vf (video filter)
flag in your FFmpeg command. Below is an example that warms up the
highlights (increases red and yellow/decreases blue) and cools down the
shadows (increases blue):
ffmpeg -i input.mp4 -vf "colorbalance=rh=0.3:bh=-0.2:bs=0.4" -c:a copy output.mp4In this command:
rh=0.3increases the red color in the highlights.bh=-0.2decreases the blue color in the highlights (adding a yellow tint).bs=0.4increases the blue color in the shadows.-c:a copycopies the audio stream without re-encoding to save processing time.