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.0to1.0(default is0.0).gb: Adjusts the green-blue contrast. Values range from-1.0to1.0(default is0.0).br: Adjusts the blue-red contrast. Values range from-1.0to1.0(default is0.0).pl: Determines the amount of preserving lightness. Values range from0.0to1.0(default is0.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.mp4How the Parameters Behave
- Positive values push the contrast toward the first
color in the pair. For instance, setting
rc=0.5increases the intensity of red relative to green. - Negative values push the contrast toward the second
color in the pair. For example, setting
rc=-0.5increases the intensity of green relative to red. - The same logic applies to
gb(positive favors green, negative favors blue) andbr(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.mp42. 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.mp43. 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.mp4In this setup:
rc=0.25pushes the balance toward red over green.gb=-0.15pulls the balance toward blue over green.br=0.1slightly favors blue over red.pl=0.3retains 30% of the original luminance to prevent overexposure or severe darkening.