FFmpeg astats: Get Detailed Audio Track Statistics

Analyzing audio files for peak levels, RMS amplitude, DC offset, and dynamic range is crucial for audio mastering, broadcasting, and quality control. This guide demonstrates how to use the FFmpeg astats (audio statistics) filter to extract detailed technical data from any audio track, explaining the essential command syntax, key output metrics, and practical use cases.

The Basic Command

To measure the statistics of an audio file without producing a new output file, use the astats filter with the null muxer (-f null -). This processes the audio and prints the statistical report directly to your terminal.

Run the following command in your terminal:

ffmpeg -i input.wav -af astats -f null -

Because FFmpeg outputs diagnostic information to the standard error (stderr) stream, you can redirect the statistics to a text file for easier reading:

ffmpeg -i input.wav -af astats -f null - 2> audio_stats.txt

Understanding the Output Metrics

The astats filter outputs values for each individual audio channel (e.g., Channel 1, Channel 2) as well as cumulative overall statistics. Here are the most critical parameters provided in the report:

  • DC offset: The deviation of the audio waveform's center from zero. High DC offset reduces headroom and can cause audible clicks.
  • Min/Max level: The lowest and highest numerical sample values in the track.
  • Peak DB (Peak amplitude): The loudest point in the audio file, measured in decibels relative to full scale (dBFS). A value of 0 dB means the audio is peaking/clipping.
  • RMS DB (Root Mean Square amplitude): The average power of the audio signal, which closely represents the perceived loudness of the track.
  • Crest factor: The ratio between the peak value and the RMS value. A higher crest factor indicates a highly dynamic audio track, while a low crest factor indicates heavy compression.
  • Bit depth: The calculated bit depth of the audio file based on the actual sample resolution used.

Advanced Usage Examples

1. Measure Peak and RMS Levels Only

If you want to filter out the noise and only view specific parameters, you can use the metadata filter or parse the output. However, to configure the interval at which astats updates its measurements, use the metadata option:

ffmpeg -i input.wav -af astats=metadata=1 -f null -

This injects the statistical values into the frame metadata, which is useful for downstream filters or custom scripts.

2. Reset Statistics at Specific Intervals

By default, astats calculates cumulative statistics for the entire file. If you want to measure statistics for shorter windowed intervals (e.g., every 30 seconds), use the reset parameter:

ffmpeg -i input.wav -af astats=reset=30 -f null -

This tells the filter to recalculate and output statistics fresh after every 30-second block of audio.