How to Use FFmpeg Colorlevels Filter

This article provides a quick guide on how to use the FFmpeg colorlevels filter to adjust the black points, white points, and overall color balance of your videos. You will learn the basic syntax, key parameters, and practical command-line examples to enhance your video contrast and perform color correction.

The colorlevels filter in FFmpeg allows you to adjust video input and output levels for individual color channels (Red, Green, Blue, and Alpha). This functions similarly to the “Levels” tool found in image editing software like Photoshop or GIMP, making it highly effective for color grading and fixing exposure issues.

Understanding the Parameters

The filter works by mapping input color ranges to new output color ranges. The parameters are divided by color channel: r (Red), g (Green), b (Blue), and a (Alpha).

For each channel, you can configure four points: * imin (Input Minimum / Black Point): Values below this become black. (Range: 0.0 to 1.0, default 0.0) * imax (Input Maximum / White Point): Values above this become white. (Range: 0.0 to 1.0, default 1.0) * omin (Output Minimum): The lowest output intensity. (Range: 0.0 to 1.0, default 0.0) * omax (Output Maximum): The highest output intensity. (Range: 0.0 to 1.0, default 1.0)

To target specific channels, prefix the parameter with the channel letter (e.g., rimin for Red Input Minimum, gimax for Green Input Maximum).


Practical Examples

1. Increasing Video Contrast

To boost contrast, you can crush the blacks and highlight the whites by increasing the input minimums and decreasing the input maximums across all RGB channels.

ffmpeg -i input.mp4 -vf "colorlevels=rimin=0.05:gimin=0.05:bimin=0.05:rimax=0.95:gimax=0.95:bimax=0.95" -c:a copy output.mp4

In this command, any pixel values below 5% brightness are pushed to pure black, and values above 95% brightness are pushed to pure white.

2. Correcting a Color Cast (Warmth/Coolness)

If your video is too yellow (warm), you can compensate by increasing the blue channel’s output intensity or reducing the red and green channels.

To add a cool, blue tint:

ffmpeg -i input.mp4 -vf "colorlevels=bomin=0.1:bomax=1.0:romax=0.9:gomax=0.9" -c:a copy output.mp4

This increases the minimum blue level to 0.1 while capping the maximum red and green levels at 0.9.

3. Creating a Vintage or Faded Look

To create a faded, low-contrast look, raise the output minimums (so blacks become dark gray) and lower the output maximums (so whites become light gray).

ffmpeg -i input.mp4 -vf "colorlevels=romin=0.1:gomin=0.1:bomin=0.1:romax=0.9:gomax=0.9:bomax=0.9" -c:a copy output.mp4

Tips for Best Results