Audio Processing in FFmpeg: AAC/MP3/Opus & Loudness (EBU R128)

Fri May 24 2024

Choose the right audio codec, resample with SoXr, and normalize loudness using a two‑pass EBU R128 workflow.

Whether you’re producing podcasts or exporting from a video edit, FFmpeg has excellent audio tools. Here’s how to pick codecs, resample cleanly, and normalize loudness.

Codec Choices

  • AAC: great for general delivery (M4A/MP4).
  • MP3: ubiquitous compatibility; VBR via -q:a works well.
  • Opus: speech and web‑friendly; excellent at low bitrates.
  • FLAC: lossless archival.

Resampling and Channels

# Convert to stereo AAC @ 128k ffmpeg -i in.wav -c:a aac -b:a 128k -ac 2 -ar 48000 out_aac.m4a # High-quality resampling (SoXr) ffmpeg -i in.wav -af "aresample=resampler=soxr:precision=33" -c:a flac out_48k.flac # Opus for voice @ 96k ffmpeg -i in.wav -c:a libopus -b:a 96k out.opus

Loudness Normalization (EBU R128)

Two‑pass approach: measure, then apply.

# Pass 1: measure ffmpeg -i in.wav -af loudnorm=I=-16:TP=-1.5:LRA=11:print_format=json -f null - # Pass 2: apply measured values ffmpeg -i in.wav -af loudnorm=I=-16:TP=-1.5:LRA=11:measured_I=-17.0:measured_TP=-2.1:measured_LRA=9.0:measured_thresh=-28.5:offset=1.2:linear=true:print_format=summary out_norm.wav

Pitfalls

  • Avoid clipping: set TP appropriately.
  • M4A vs MP4 file extensions when exporting AAC.

With a consistent loudness target and clean resampling, your audio will translate well across players.