Extract Audio Above Volume Threshold with FFmpeg aselect

This article explains how to use FFmpeg’s aselect filter in combination with audio statistics to isolate and extract audio segments that exceed a specific volume threshold. You will learn the exact command-line syntax, how to measure real-time volume metadata, and how to export the resulting loud audio clips while discarding the quiet parts.


The Command

To select audio frames based on volume, you must first generate volume metadata for each frame and then pass that metadata to the aselect filter. The most reliable way to do this is by combining the astats filter (to measure volume) with aselect (to filter it).

Use the following template command:

ffmpeg -i input.mp3 -af "astats=metadata=1,aselect='gt(metadata:lavfi.astats.Overall.RMS_level,-20)',asetpts=N/SR/TB" output.mp3

How It Works

The audio filter chain (-af) performs three distinct steps to filter the audio:

  1. astats=metadata=1
    This injects statistical metadata into each audio frame in real-time. It calculates properties like RMS (Root Mean Square) power and peak levels.

  2. aselect='gt(metadata:lavfi.astats.Overall.RMS_level,-20)'
    The aselect filter evaluates an expression for every audio frame.

    • metadata:lavfi.astats.Overall.RMS_level reads the overall RMS volume (in decibels) of the current frame calculated by astats.
    • gt(..., -20) stands for “greater than.” This tells FFmpeg to only keep audio frames where the volume is louder than -20 dB. Anything quieter than -20 dB is discarded.
  3. asetpts=N/SR/TB
    When frames are discarded, gaps are left in the audio timeline. This filter regenerates clean Presentation Timestamps (PTS) for the remaining frames, stitching them back together into a continuous, gapless audio file.

Customizing the Threshold

Alternative: Filtering by Peak Volume

If you prefer to extract segments based on peak volume rather than average RMS volume, change the metadata key to Peak_level:

ffmpeg -i input.mp3 -af "astats=metadata=1,aselect='gt(metadata:lavfi.astats.Overall.Peak_level,-10)',asetpts=N/SR/TB" output.mp3