Adjust Shadows, Midtones, and Highlights in FFmpeg
This article provides a practical guide on using FFmpeg’s
colorbalance video filter to independently adjust the color
levels of shadows, midtones, and highlights. You will learn the filter's
syntax, parameter ranges, and how to apply targeted adjustments to
correct color casts or create stylized color grading directly from the
command line.
Understanding the
colorbalance Filter
The colorbalance filter operates by adjusting the red,
green, and blue components across three specific tonal ranges: shadows
(dark regions), midtones (intermediate regions), and highlights (bright
regions).
Each tonal band accepts values ranging from -1.0
to 1.0, where:
0.0represents no change (default).- Positive values add the respective color.
- Negative values subtract the respective color (adding its complementary color: subtracting red adds cyan, subtracting green adds magenta, subtracting blue adds yellow).
Parameter Reference
- Shadows:
rs: Red shadowsgs: Green shadowsbs: Blue shadows
- Midtones:
rm: Red midtonesgm: Green midtonesbm: Blue midtones
- Highlights:
rh: Red highlightsgh: Green highlightsbh: Blue highlights
- Lightness Preservation:
pl: Preserve lightness (0for disabled,1for enabled; default is0). Enabling this helps prevent overall brightness shifts when pushing intense color adjustments.
Practical Examples
1. Warming Highlights and Cooling Shadows (Teal and Orange Look)
To cool down the shadows by adding blue and subtract red/green, while simultaneously warming the highlights by adding red and subtracting blue:
ffmpeg -i input.mp4 -vf "colorbalance=rs=-0.1:gs=-0.05:bs=0.2:rh=0.2:gh=0.05:bh=-0.15" -c:a copy output.mp42. Removing a Green Tint in the Midtones
If your footage has an unwanted green cast primarily visible in the
mid-frequency tones, reduce the green midtone parameter
(gm):
ffmpeg -i input.mp4 -vf "colorbalance=gm=-0.2" -c:a copy output.mp43. Deepening Shadow Contrast Without Affecting Highlights
To push shadows toward a deeper, warmer tone while keeping highlights and midtones neutral:
ffmpeg -i input.mp4 -vf "colorbalance=rs=0.15:gs=-0.1:bs=-0.1" -c:a copy output.mp44. Preserving Luminance During Intense Color Grading
When applying strong adjustments across multiple bands, set
pl=1 to prevent changes to the overall exposure:
ffmpeg -i input.mp4 -vf "colorbalance=rs=-0.2:bs=0.2:rm=0.1:rh=0.3:bh=-0.2:pl=1" -c:a copy output.mp4