Match Video Black Levels Using FFmpeg Colorlevels

This article explains how to use the FFmpeg colorlevels filter to match the black levels of two different video clips. By analyzing the color profiles of a source and a reference video, you can precisely adjust the shadow and black points of your target video to ensure visual consistency across your footage.

Step 1: Analyze the Black Levels

Before applying the filter, you must determine the black level values of both the source video (the one you want to change) and the reference video (the one you want to match).

You can identify these levels by visual inspection using a histogram or by running FFmpeg’s signalstats filter to output the minimum luma/color values:

ffmpeg -i reference.mp4 -vf signalstats -f null -

Look for the minimum channel values (Red, Green, and Blue). FFmpeg’s colorlevels filter expects these values on a scale from 0.0 (pure black) to 1.0 (pure white). If your analysis tool provides values in 8-bit format (0–255), divide those numbers by 255 to get the decimal value.

Step 2: Understand the colorlevels Parameters

To match the blacks, you will map the black points of your source video to the black points of your reference video using the following colorlevels parameters:

By setting the input minimums to your source’s current black levels and the output minimums to the reference’s black levels, FFmpeg will remap the shadow range.

Step 3: Apply the FFmpeg Command

Use the analyzed values in the colorlevels filter. Based on the example values from Step 1, the command to adjust the source video is:

ffmpeg -i source.mp4 -vf "colorlevels=rimin=0.08:gimin=0.08:bimin=0.10:romin=0.02:gomin=0.02:bomin=0.02" -c:a copy output.mp4

Step 4: Fine-Tuning (Optional)

If the overall midtones of the video become too dark after adjusting the black levels, you can adjust the gamma parameters (rimax, gimax, bimax for white points, or use the eq filter subsequently) to restore brightness to the highlights while keeping the new, matched black levels intact.