Configure FFmpeg aselect Filter Volume Threshold

This article explains how to configure the volume threshold in FFmpeg using the aselect filter. You will learn how to pair aselect with the astats filter to measure audio levels in real time and discard any audio frames that fall below a specified decibel (dB) threshold, effectively filtering out silence or quiet background noise.

To filter audio by volume using aselect, you must chain it with the astats filter. Because aselect cannot measure audio volume on its own, astats is used first to inject volume metadata into each audio frame. The aselect filter then reads this metadata and determines whether to keep or discard the frame based on your target threshold.

The Basic Command Syntax

The standard FFmpeg filtergraph for volume thresholding looks like this:

ffmpeg -i input.mp3 -af "astats=metadata=1,aselect='gt(metadata:lavfi.astats.Overall.RMS_level,-40)'" -acodec libmp3lame output.mp3

How It Works

  1. astats=metadata=1: This activates the audio statistics filter and instructs it to inject measurement metadata (such as RMS and peak levels) into each audio frame.
  2. aselect='...': This filters the audio frames. Only frames that evaluate to true (non-zero) are passed to the output.
  3. metadata:lavfi.astats.Overall.RMS_level: This extracts the overall Root Mean Square (RMS) volume level of the current frame in decibels (dB).
  4. gt(..., -40): This is the “greater than” function. In this example, it checks if the frame’s volume is louder than -40 dB. Any frame quieter than -40 dB (for example, -50 dB) evaluates to false and is discarded.

Adjusting the Threshold and Metrics

You can customize the filter behavior by changing the volume metric or the decibel threshold: