How to Use the FFmpeg colorcontrast Filter

The FFmpeg colorcontrast filter is a powerful tool for adjusting the color relationships between the red, green, and blue channels of a video. This article explains how to use the colorcontrast filter to adjust the red-green (rg), green-blue (gb), and blue-red (br) contrast levels, including step-by-step command examples and parameter explanations to help you achieve the perfect color balance in your videos.

Understanding the colorcontrast Parameters

The colorcontrast filter uses three primary parameters to control the color contrast axes, alongside three corresponding weight parameters to control the strength of the effect.

Contrast Adjustments

Note: Positive values increase the contrast between the respective colors, making them more distinct, while negative values reduce the contrast, blending them closer together.

Contrast Weights

You can fine-tune how aggressively these changes are applied using weight parameters: * rgw (Red-Green weight): Sets the weight for the red-green contrast. The range is 0.0 to 1.0. * gbw (Green-Blue weight): Sets the weight for the green-blue contrast. The range is 0.0 to 1.0. * brw (Blue-Red weight): Sets the weight for the blue-red contrast. The range is 0.0 to 1.0.


Basic FFmpeg Command Syntax

To apply the colorcontrast filter, use the -vf (video filter) flag in your FFmpeg command. The basic syntax is:

ffmpeg -i input.mp4 -vf "colorcontrast=rg=VALUE:gb=VALUE:br=VALUE" output.mp4

Practical Examples

1. Enhancing Red-Green and Green-Blue Contrast

To boost the contrast between reds and greens, and slightly increase the contrast between greens and blues, use positive values:

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

2. Muting Blue-Red Contrast

To reduce the harshness between blue and red elements in your video, apply a negative value to the br parameter:

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

3. Adjusting All Axes with Fine-Tuned Weights

If you want to apply high contrast values but limit their intensity to prevent color clipping, use the weight (rgw, gbw, brw) parameters:

ffmpeg -i input.mp4 -vf "colorcontrast=rg=0.8:gb=-0.5:br=0.3:rgw=0.5:gbw=0.5:brw=0.5" -c:a copy output.mp4

This command significantly shifts the red-green axis and reduces green-blue contrast, but limits the overall effect to 50% strength via the 0.5 weight values.