Measure Audio Levels Using FFmpeg ASDR Filter

This guide explains how to use FFmpeg's asdr (Audio Signal-to-Distortion Ratio) filter to evaluate audio streams, compare signal levels against a reference, and measure distortion or signal deviation across channels. By feeding two synchronized audio sources into FFmpeg, you can extract precise signal-to-distortion metrics to assess audio quality, dynamic level changes, and active sound characteristics.

Understanding the ASDR Filter in FFmpeg

The asdr filter calculates the Signal-to-Distortion Ratio between two audio inputs: a reference signal and a modified or degraded signal. It operates channel-by-channel to assess how much the active content of the test audio deviates from the original source. The result is expressed in decibels (dB), where higher values indicate lower distortion and closer adherence to the reference signal level.

Because asdr requires two inputs, it must be executed using the -filter_complex option rather than simple audio filtering (-af).

Basic Command Syntax

To measure the audio level and distortion between a reference file and a processed file, use the following command:

ffmpeg -i reference.wav -i processed.wav -filter_complex "[0:a][1:a]asdr" -f null -

Command Breakdown

  • -i reference.wav: The primary input representing the clean, baseline audio.
  • -i processed.wav: The secondary input representing the audio being measured.
  • -filter_complex "[0:a][1:a]asdr": Directs the first audio stream [0:a] and the second audio stream [1:a] into the asdr filter.
  • -f null -: Discards the output media container since the relevant data is printed directly to the terminal output.

Ensuring Stream Compatibility

The asdr filter requires both audio streams to share the same sample rate, channel count, and channel layout. If the files differ, insert the aresample or aformat filter to normalize them before passing them to asdr:

ffmpeg -i reference.wav -i processed.wav -filter_complex "[0:a]aformat=sample_rates=48000:channel_layouts=stereo[a0];[1:a]aformat=sample_rates=48000:channel_layouts=stereo[a1];[a0][a1]asdr" -f null -

Reading the Output

Upon completion, FFmpeg prints a summary line to the console showing the results for each channel:

[Parsed_asdr_0 @ 0x7fa2b0405800] Ch0 SDR: 42.15 dB
[Parsed_asdr_0 @ 0x7fa2b0405800] Ch1 SDR: 41.89 dB
  • High SDR (e.g., > 40 dB): The active sound level of the target matches the reference with minimal distortion, compression, or noise.
  • Low SDR (e.g., < 20 dB): Significant signal loss, clipping, level attenuation, or added artifacts exist between the two streams.
  • Identical Streams: If the files are identical, the reported SDR approaches infinity (inf dB).