Change Video Brightness and Contrast with FFmpeg
This article provides a quick overview and step-by-step guide on how
to adjust the brightness and contrast of a video using FFmpeg on Linux.
By utilizing the powerful eq (equalizer) video filter, you
can easily modify your video’s visual properties directly from the
command line. Whether you need a subtle correction or a dramatic shift,
FFmpeg offers precise controls to achieve the desired look without
needing a heavy graphical video editor.
To change these settings, you will use FFmpeg’s video filter flag
(-vf) paired with the eq filter. The basic
syntax requires you to specify values for brightness and
contrast as decimals or integers.
Here is the fundamental command structure:
ffmpeg -i input.mp4 -vf "eq=contrast=1.5:brightness=0.1" output.mp4Understanding the Parameters
When adjusting the equalizer filter, it helps to understand how FFmpeg calculates these values:
- Contrast: The default value is 1.0. Values below 1.0 reduce the contrast (making the image flatter), while values above 1.0 increase it. The allowable range is typically between -2.0 and 2.0.
- Brightness: The default value is 0.0. You can adjust this value between -1.0 and 1.0. Positive numbers make the video brighter, while negative numbers darken it.
Practical Examples
If you have a video that is slightly underexposed, you can boost both parameters to make the image pop. For instance, to slightly increase the brightness and add a bit of punchy contrast, use the following command:
ffmpeg -i twilight_clip.mp4 -vf "eq=contrast=1.2:brightness=0.05" enhanced_output.mp4Conversely, if your video is washed out and overly bright, you can lower the brightness and increase the contrast to recover some depth:
ffmpeg -i overexposed_clip.mp4 -vf "eq=contrast=1.3:brightness=-0.08" corrected_output.mp4Optimizing Encoding Speed and Quality
By default, FFmpeg will re-encode your video using standard settings.
To ensure you maintain high visual quality while managing file size, you
can specify a video codec and a Constant Rate Factor (CRF). Adding
-c:a copy will also allow you to pass the audio through
without re-encoding it, saving processing time:
ffmpeg -i input.mp4 -vf "eq=contrast=1.1:brightness=0.02" -c:v libx264 -crf 23 -c:a copy output.mp4Using these command-line adjustments allows for rapid, scriptable video corrections directly within your Linux terminal.