Why FFmpeg for Audio?

FFmpeg is the Swiss Army knife of digital media processing. It's free, open source, runs on every major operating system, and supports virtually every audio format and codec in existence. Whether you're converting a WAV file to AAC, extracting audio from a video, packaging a stream for HLS, or analyzing ADTS frame headers, FFmpeg can handle it — usually in a single command.

This guide covers the most essential FFmpeg operations for audio work, from basic conversions to more advanced streaming tasks.

Installation

FFmpeg is available through most package managers:

  • macOS: brew install ffmpeg
  • Ubuntu/Debian: sudo apt install ffmpeg
  • Windows: Download pre-built binaries from ffmpeg.org or use winget install ffmpeg

Verify the installation with ffmpeg -version. Pay attention to which codecs are listed as enabled — some builds omit certain codecs due to licensing.

Basic Format Conversion

Converting between common audio formats is straightforward:

# WAV to MP3 at 192 kbps
ffmpeg -i input.wav -codec:a libmp3lame -b:a 192k output.mp3

# WAV to AAC (ADTS format) at 128 kbps
ffmpeg -i input.wav -codec:a aac -b:a 128k output.aac

# WAV to AAC in M4A container
ffmpeg -i input.wav -codec:a aac -b:a 256k output.m4a

# MP3 to FLAC (lossless)
ffmpeg -i input.mp3 -codec:a flac output.flac

# Any format to Opus (highly efficient)
ffmpeg -i input.wav -codec:a libopus -b:a 96k output.opus

Controlling Quality with VBR

For AAC and MP3, variable bitrate encoding often gives better quality per file size than CBR:

# AAC VBR (quality scale: 1=lowest, 5=highest)
ffmpeg -i input.wav -codec:a aac -vbr 4 output.m4a

# MP3 VBR using LAME quality scale (0=best, 9=worst)
ffmpeg -i input.wav -codec:a libmp3lame -q:a 2 output.mp3

Channel and Sample Rate Manipulation

# Convert stereo to mono (for podcasts/voice)
ffmpeg -i input.wav -ac 1 output_mono.wav

# Resample to 44100 Hz
ffmpeg -i input.wav -ar 44100 output.wav

# Combine both: stereo to mono at 44.1 kHz, encode as AAC
ffmpeg -i input.wav -ac 1 -ar 44100 -codec:a aac -b:a 96k podcast.aac

Extracting Audio from Video

# Extract audio as AAC from MP4 (no re-encode — copy existing stream)
ffmpeg -i video.mp4 -vn -codec:a copy audio.aac

# Extract and re-encode to MP3
ffmpeg -i video.mp4 -vn -codec:a libmp3lame -b:a 192k audio.mp3

The -vn flag disables video output. Using -codec:a copy when the source is already AAC avoids a quality-degrading transcode.

Creating HLS Audio Streams

FFmpeg can output a complete HLS package — playlist and segments — with one command:

ffmpeg -i input.wav \
  -codec:a aac -b:a 128k \
  -hls_time 6 \
  -hls_list_size 0 \
  -hls_segment_filename 'segment_%03d.ts' \
  playlist.m3u8

This creates 6-second MPEG-TS segments containing ADTS-packaged AAC audio, plus an M3U8 playlist — everything needed to serve audio via HLS.

Working with ADTS Streams

# Wrap raw AAC in ADTS (output raw .aac file)
ffmpeg -i input.m4a -codec:a copy -f adts output.aac

# Convert ADTS .aac to M4A container
ffmpeg -i input.aac -codec:a copy output.m4a

# Probe an ADTS file to inspect its properties
ffprobe -v quiet -print_format json -show_streams input.aac

Batch Conversion with Shell Scripting

# Convert all WAV files in a directory to AAC
for f in *.wav; do
    ffmpeg -i "$f" -codec:a aac -b:a 192k "${f%.wav}.m4a"
done

Useful FFmpeg Flags Reference

FlagPurpose
-iInput file
-codec:a / -c:aAudio codec
-b:aAudio bitrate
-arSample rate
-acNumber of audio channels
-vnDisable video (audio-only output)
-fForce output format
-yOverwrite output without asking
-v quietSuppress verbose output

Getting Help

FFmpeg's documentation is extensive. Use ffmpeg -codecs to list all available codecs, ffmpeg -formats for container formats, and ffmpeg -h encoder=aac for detailed options for a specific encoder. The official FFmpeg wiki and documentation at ffmpeg.org are also excellent references for more advanced use cases.