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.0 represents 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 shadows
    • gs: Green shadows
    • bs: Blue shadows
  • Midtones:
    • rm: Red midtones
    • gm: Green midtones
    • bm: Blue midtones
  • Highlights:
    • rh: Red highlights
    • gh: Green highlights
    • bh: Blue highlights
  • Lightness Preservation:
    • pl: Preserve lightness (0 for disabled, 1 for enabled; default is 0). 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.mp4

2. 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.mp4

3. 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.mp4

4. 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