FFmpeg Dynamic Range Compression with dynaudnorm

This article explains how to use the dynaudnorm (Dynamic Audio Normalizer) filter in FFmpeg to apply dynamic range compression to your audio files. You will learn the basic command syntax, understand the key parameters for fine-tuning the filter, and see practical examples of how to balance loud and quiet sections of your audio without introducing clipping or distortion.

Understanding the dynaudnorm Filter

The dynaudnorm filter is an advanced tool in FFmpeg designed for dynamic range compression and audio normalization. Unlike standard peak normalization, which applies a single gain factor to the entire file, dynaudnorm analyzes the audio in small, overlapping windows (frames) and applies a changing amount of gain over time. This boosts quiet passages (like whispered dialogue) and tames loud spikes (like explosions) to create a more consistent and comfortable listening volume.

Basic Usage

To apply the Dynamic Audio Normalizer with its default settings, use the -af (audio filter) flag in your FFmpeg command:

ffmpeg -i input.mp3 -af dynaudnorm output.mp3

This default command is highly effective for most general audio files, podcasts, and video soundtracks.

Key Parameters for Fine-Tuning

You can customize the behavior of the dynaudnorm filter by passing specific parameters in a key-value format: dynaudnorm=parameter1=value1:parameter2=value2.

  • f (Frame Length): Sets the frame length in milliseconds. The default is 250. Smaller values make the filter react faster to volume changes, while larger values result in smoother transitions.
  • g (Filter Window Size): Sets the size of the filter window in frames. It must be an odd number (default is 31). A larger window size creates a more natural-sounding, gradual compression.
  • p (Peak Value): Defines the target maximum peak amplitude. The value ranges from 0.0 to 1.0. The default is 0.95 (which keeps the audio just below clipping).
  • m (Maximum Gain): Sets the maximum amplification factor (gain) allowed for quiet sections, expressed as a factor. The default is 10.0 (which is equal to +20dB). Lowering this prevents the background noise in silent parts from being boosted too much.
  • s (Target RMS): Controls the target Root Mean Square (RMS) energy. It ranges from 0.0 to 1.0. The default is 0.0, which automatically determines the target RMS based on the input.

Practical Examples

1. Gentle Compression for Music

For music, you want to avoid abrupt changes in volume to preserve the artistic dynamics of the track. A larger window size and lower maximum gain work best:

ffmpeg -i music.wav -af "dynaudnorm=g=51:m=5:p=0.98" output.wav

2. Aggressive Compression for Dialogue and Podcasts

If you are processing a podcast or movie dialogue where some speakers are very quiet and others are very loud, you can use a smaller window and higher gain limit to level out the voices:

ffmpeg -i podcast.mp3 -af "dynaudnorm=f=150:g=15:m=15" output.mp3

3. Preventing Background Noise Boost

If your audio has silent gaps where you do not want background hiss or room tone to be amplified, reduce the maximum gain parameter (m):

ffmpeg -i interview.wav -af "dynaudnorm=m=3.0" output.wav