Repair Audio Clipping with FFmpeg adeclip Filter
Digital audio clipping occurs when an audio signal exceeds its
maximum limit, resulting in harsh distortion. This article provides a
straightforward guide on how to use FFmpeg’s adeclip filter
to repair clipped audio, explaining the key parameters and providing
practical command-line examples to restore your sound quality.
Understanding the adeclip Filter
The adeclip filter in FFmpeg is an audio de-clipping
filter that reconstructs clipped sample peaks. It works by detecting
samples that have reached the maximum threshold and interpolating the
missing data to round out the flat, distorted peaks.
The Importance of Headroom
Before repairing clipped audio, it is crucial to lower the input
volume. Because the adeclip filter reconstructs the peaks
of the waveform, the restored peaks will naturally rise above 0 dB (the
clipping threshold). If you do not lower the volume first, the
reconstructed audio will clip again during output.
You can apply gain reduction and de-clipping in a single command by
chaining the volume filter before the adeclip
filter.
Basic Command Syntax
The simplest way to use the adeclip filter with volume
attenuation is as follows:
ffmpeg -i input.wav -af "volume=-3dB,adeclip" output.wavIn this command: * -i input.wav: Specifies the distorted
input audio file. * -af "volume=-3dB,adeclip": Applies an
audio filter chain. First, it lowers the volume by 3 decibels to create
headroom, then it applies the adeclip filter. *
output.wav: The repaired output audio file.
Fine-Tuning adeclip Parameters
For severely distorted audio, the default settings of
adeclip might not be enough. You can customize the filter
using several parameters:
1. Threshold (threshold
or a)
This parameter sets the detection threshold for clipped samples. It
ranges from 0.0 to 1.0. The default is
0.55. If your audio clipped at a lower level due to prior
processing, you can lower this value to force the filter to detect lower
peaks.
ffmpeg -i input.wav -af "volume=-3dB,adeclip=threshold=0.4" output.wav2. Window Size (window or
w)
This sets the size of the window in milliseconds used for
double-precision processing. The default is 55
milliseconds. A larger window can produce better results for
low-frequency clipping but requires more processing power.
ffmpeg -i input.wav -af "volume=-3dB,adeclip=window=80" output.wav3. Overlap (overlap or
o)
This defines the window overlap percentage, ranging from
50 to 95. The default is 75.
Higher overlap values can smooth out transitions but increase rendering
times.
ffmpeg -i input.wav -af "volume=-3dB,adeclip=overlap=90" output.wav4. Method (method or
m)
This specifies the interpolation method used to reconstruct the
clipped samples. * a: Auto (default) * l:
Linear * c: Cubic
ffmpeg -i input.wav -af "volume=-3dB,adeclip=method=c" output.wavCombining Multiple Parameters
For optimal results on a heavily clipped audio file, you can combine these parameters into a single command:
ffmpeg -i input.wav -af "volume=-6dB,adeclip=threshold=0.5:window=100:overlap=85:method=c" output.wavIn this advanced example, the volume is reduced by 6dB to ensure
ample headroom, the threshold is lowered to 0.5, the window
size is increased to 100ms with an 85%
overlap, and cubic interpolation is utilized to reconstruct the peaks
smoothly.