Adjust Color Contrast in FFmpeg with colorcontrast

This article explains how to use FFmpeg's colorcontrast video filter to alter cross-channel color dynamics by adjusting red-green, green-blue, and blue-red contrast levels. You will learn the specific syntax, parameter ranges, and practical command-line examples to fine-tune color separation or achieve creative grading effects in video files.

Understanding the colorcontrast Filter

The colorcontrast filter modifies the relationship between pairs of primary color channels. Rather than simply boosting individual color saturations uniformly, it shifts the balance across opposing channel pairs.

The filter accepts four primary options:

  • rc: Adjusts the red-green contrast. Values range from -1.0 to 1.0 (default is 0.0).
  • gb: Adjusts the green-blue contrast. Values range from -1.0 to 1.0 (default is 0.0).
  • br: Adjusts the blue-red contrast. Values range from -1.0 to 1.0 (default is 0.0).
  • pl: Determines the amount of preserving lightness. Values range from 0.0 to 1.0 (default is 0.0). Setting this higher helps retain the original luminance of the image as color intensities shift.

Basic Syntax

To use the filter, apply it via the -vf (video filter) flag:

ffmpeg -i input.mp4 -vf "colorcontrast=rc=VALUE:gb=VALUE:br=VALUE:pl=VALUE" -c:a copy output.mp4

How the Parameters Behave

  • Positive values push the contrast toward the first color in the pair. For instance, setting rc=0.5 increases the intensity of red relative to green.
  • Negative values push the contrast toward the second color in the pair. For example, setting rc=-0.5 increases the intensity of green relative to red.
  • The same logic applies to gb (positive favors green, negative favors blue) and br (positive favors blue, negative favors red).

Practical Examples

1. Enhancing Red Tones Against Green

To enhance autumn foliage or separate warm subjects from green backgrounds, increase the red-green contrast:

ffmpeg -i input.mp4 -vf "colorcontrast=rc=0.4" -c:a copy output.mp4

2. Enhancing Blue Against Red with Lightness Preservation

To cool down warm tones and accentuate blues (such as sky or water) while maintaining balanced brightness:

ffmpeg -i input.mp4 -vf "colorcontrast=br=0.3:pl=0.5" -c:a copy output.mp4

3. Combining All Three Color Pairs

You can simultaneously adjust all channel contrasts to create custom stylized grades:

ffmpeg -i input.mp4 -vf "colorcontrast=rc=0.25:gb=-0.15:br=0.1:pl=0.3" -c:a copy output.mp4

In this setup:

  • rc=0.25 pushes the balance toward red over green.
  • gb=-0.15 pulls the balance toward blue over green.
  • br=0.1 slightly favors blue over red.
  • pl=0.3 retains 30% of the original luminance to prevent overexposure or severe darkening.