How to Use FFmpeg anlmdn Filter for Audio Denoising
This article provides a practical guide on how to use the
anlmdn (Audio Non-Local Means Denoise) filter in FFmpeg to
reduce unwanted background noise from audio tracks. You will learn the
basic syntax, understand the key parameters that control the denoising
strength and quality, and see real-world command-line examples to help
you achieve clean audio outputs.
Understanding the anlmdn Filter
The anlmdn filter uses a non-local means algorithm
adapted for audio signals. Unlike traditional spectral subtraction
methods that can introduce musical noise artifacts, non-local means
looks for similar patterns across the audio frame to distinguish between
noise and actual audio. This results in a more natural-sounding noise
reduction, especially for constant background hums, hissing, or
static.
Basic Command Syntax
To apply the anlmdn filter with its default settings,
use the following FFmpeg command:
ffmpeg -i input.wav -af anlmdn output.wavKey Parameters
You can fine-tune the denoising process by adjusting the filter’s
parameters. The syntax for passing parameters is
-af anlmdn=parameter1=value1:parameter2=value2.
s(strength): Controls the denoising strength. A higher value removes more noise but may introduce distortion or muffle the audio. The default is0.00001.p(patch): Sets the patch duration in milliseconds. This is the size of the audio segments compared by the algorithm. The default is0.002seconds (2 ms). Larger patches can improve accuracy but increase processing time.r(research): Sets the research duration in milliseconds. This defines the search window size where the algorithm looks for similar patches. The default is0.006seconds (6 ms).o(output mode): Specifies what the filter outputs.o: Output the denoised audio (default).n: Output only the noise that was removed (useful for monitoring what is being cut).
Practical Examples
1. Moderate Denoising for Voice Recordings
For standard voice recordings with moderate background hiss, slightly
increasing the strength (s) and patch size (p)
can yield cleaner results:
ffmpeg -i input.mp3 -af "anlmdn=s=0.0005:p=0.004:r=0.01" output.mp32. Heavy Noise Reduction
If you are dealing with a very noisy audio track, you can increase the strength further. Be careful, as setting this too high can make speech sound robotic or muffled.
ffmpeg -i input.wav -af "anlmdn=s=0.005:p=0.002:r=0.006" output.wav3. Isolating and Listening to the Removed Noise
To verify that you are not accidentally removing vital parts of your
audio (like vocals or instruments), you can output only the noise
profile using the o=n parameter:
ffmpeg -i input.wav -af "anlmdn=s=0.0005:o=n" removed_noise.wavIf you hear clear speech in the removed_noise.wav file,
your strength parameter (s) is too high and should be
lowered.