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.wav

Key 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.

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.mp3

2. 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.wav

3. 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.wav

If you hear clear speech in the removed_noise.wav file, your strength parameter (s) is too high and should be lowered.