FFmpeg Peak Normalization with Volume Filter
This article explains how to prevent audio clipping by using the
FFmpeg volume filter to perform peak normalization. You
will learn how to analyze an audio file to find its current peak level,
calculate the adjustment needed to reach maximum volume without
distortion, and apply the filter to achieve a perfectly normalized
output.
Step 1: Analyze the Audio to Find the Peak Volume
Before you can normalize the audio, you must determine its current maximum volume (peak). If you increase the volume too much, the audio will exceed 0 dB, resulting in digital clipping.
Run the following command using the volumedetect filter
to analyze your audio stream. The -f null - argument tells
FFmpeg to process the file without writing an output file:
ffmpeg -i input.mp4 -filter:a volumedetect -f null -Look at the terminal output for the max_volume line,
which will look similar to this:
[parsed_volumedetect_0 @ 0x55bc8f04bc00] max_volume: -6.4 dB
This output indicates that the loudest point in the audio file is currently at -6.4 dB.
Step 2: Calculate the Volume Adjustment
To perform peak normalization, you must calculate how much you can increase the volume before the peak reaches your target level (usually 0 dB, or slightly lower to prevent downstream playback distortion, such as -1.0 dB).
Use this formula:
Target Peak - Current Max Volume = Required Adjustment
- To normalize to 0 dB (maximum limit):
0 - (-6.4) = +6.4 dB - To normalize to -1.0 dB (safer limit to prevent
clipping):
-1.0 - (-6.4) = +5.4 dB
Step 3: Apply the Volume Filter
Once you have calculated the adjustment, apply the
volume filter using your calculated decibel value.
To normalize the peak volume of the audio to 0 dB, run:
ffmpeg -i input.mp4 -filter:a "volume=6.4dB" output.mp4To normalize the peak volume to a safer limit of -1.0 dB using the second calculation, run:
ffmpeg -i input.mp4 -filter:a "volume=5.4dB" output.mp4By specifying the precise decibel increase based on the
volumedetect output, you ensure that the audio signal is
maximized to its highest possible volume without ever exceeding 0 dB,
preventing any clipping.