Need to pull audio from a meeting recording, extract BGM from a video, or convert a video file to MP3? FFmpeg does it all in a single command. The key decision is whether to copy losslessly or re-encode — understanding that choice lets you extract exactly what you need, at the quality you want. Time to complete: 10 minutes.

Tested with: FFmpeg 6.1 (ubuntu-latest / GitHub Actions CI-validated)


What You Will Learn

  1. Using -vn to exclude video and output audio only
  2. Lossless copy (-c:a copy) vs. re-encoding — difference and when to use each
  3. Format-specific commands for MP3, AAC, FLAC, and WAV
  4. Container/codec compatibility reference
  5. Selecting a specific audio track with -map
  6. Extracting a specific time range
  7. Batch audio extraction for an entire folder
  8. Five common errors and fixes
  9. Five frequently asked questions

Command Examples

1. Fastest: Lossless Copy (Zero Quality Loss)

Extract audio in the original codec without re-encoding. Fastest method, no quality change.

# Extract AAC from MP4 as .aac
ffmpeg -i input.mp4 -vn -c:a copy output.aac

# Same content as .m4a (better compatibility with Windows/phones)
ffmpeg -i input.mp4 -vn -c:a copy output.m4a
  • -vn — exclude the video stream from the output
  • -c:a copy — copy audio data as-is, no decode/encode

2. Convert to MP3 (libmp3lame)

Re-encode to MP3 from any source format.

# VBR MP3 — best quality (recommended)
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 0 output.mp3

# CBR MP3 at 320 kbps
ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 320k output.mp3

# CBR MP3 at 128 kbps (smaller file)
ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 128k output.mp3
  • -q:a 0 — VBR quality (0–9; lower = better; 0 is highest quality)
  • -b:a 320k — fixed bitrate

3. Extract as AAC

# AAC at 192 kbps (music / high quality)
ffmpeg -i input.mkv -vn -c:a aac -b:a 192k output.aac

# AAC at 128 kbps (general use)
ffmpeg -i input.mp4 -vn -c:a aac -b:a 128k output.aac

4. Extract as FLAC (Lossless Compressed)

# FLAC: lossless compression — ideal for archiving from PCM or lossless source
ffmpeg -i input.mkv -vn -c:a flac output.flac

5. Extract as WAV (Uncompressed PCM)

# 16-bit PCM WAV (standard)
ffmpeg -i input.mp4 -vn -c:a pcm_s16le output.wav

# 24-bit PCM WAV (high-quality recording / DAW use)
ffmpeg -i input.mp4 -vn -c:a pcm_s24le output.wav

6. Extract a Specific Time Range

# Lossless copy from 1:00 to 2:00
ffmpeg -ss 00:01:00 -i input.mp4 -to 00:02:00 -vn -c:a copy clip_audio.aac

# Re-encode 60 seconds starting at 30s as MP3
ffmpeg -ss 30 -i input.mp4 -t 60 -vn -c:a libmp3lame -q:a 2 output.mp3

7. Select a Specific Audio Track

# List all audio tracks
ffprobe -v quiet -select_streams a \
  -show_entries stream=index,codec_name,tags:stream_tags=language \
  -of default input.mkv

# Extract first audio track (0:a:0)
ffmpeg -i input.mkv -map 0:a:0 -c:a copy track1.aac

# Extract second audio track (0:a:1 — e.g., English dub)
ffmpeg -i input.mkv -map 0:a:1 -c:a copy track2.aac

8. Batch Audio Extraction

for f in *.mp4; do
  ffmpeg -i "$f" -vn -c:a libmp3lame -q:a 2 "${f%.mp4}.mp3" -y
done

Format Comparison Table

FormatCodecCompressionFile SizeBest For
.aac / .m4aAACLossySmallGeneral use, phone compatibility
.mp3MP3LossySmallMost universal — music, podcasts
.flacFLACLosslessMediumMusic archives, lossless storage
.wavPCMUncompressedLargeDAWs, audio editing, professional
.oggVorbisLossySmallGames, web streaming
.opusOpusLossySmallestLow bitrate with high quality

Lossless Copy vs. Re-Encoding

ConditionRecommendation
Output codec unchanged (AAC→AAC, etc.)-c:a copy (lossless, fast)
Output codec changes (AAC→MP3, etc.)Re-encode
Need different bitrate or sample rateRe-encode
Need filters (normalize, denoise, etc.)Re-encode

Lossless copy preserves audio quality exactly. Re-encoding causes generation loss when the source is already lossy (MP3, AAC). Always prefer lossless copy when the codec doesn’t need to change.

Container/Codec Compatibility

Input ContainerAudio CodecCompatible Lossless Output
.mp4AAC.aac, .m4a
.mkvFLAC.flac
.mkvAAC.aac, .m4a
.aviMP3.mp3
.movAAC.aac, .m4a

Option Reference

OptionMeaningRecommended Value
-vnExclude video stream from outputAlways include for audio extraction
-c:a copyLossless audio copyWhen codec stays the same
-c:a libmp3lameMP3 encoderFor MP3 output
-q:a NVBR quality (0–9)0 (best) to 2 (high quality)
-b:a NkFixed audio bitrateMusic: 192k–320k / Voice: 64k–128k
-ac NChange channel count1 (mono), 2 (stereo)
-ar NChange sample rate44100 (CD), 48000 (video standard)
-map 0:a:NSelect N-th audio track0:a:0 (first track)

Troubleshooting

Problem 1: -c:a copy Errors Out (Container Incompatibility)

Symptom: Could not write header for output file or Invalid argument
Cause: The output container doesn’t support the input codec (e.g., copying AAC into .mp3).
Fix:

# Check the actual codec first
ffprobe -v quiet -select_streams a -show_entries stream=codec_name input.mp4

# Use a compatible output extension for AAC
ffmpeg -i input.mp4 -vn -c:a copy output.aac  # not .mp3

Problem 2: Encoder libmp3lame not found

Cause: Your FFmpeg build lacks MP3 encoding support.
Fix: Install the full-featured FFmpeg binary:

sudo apt install ffmpeg       # Ubuntu/Debian
brew install ffmpeg           # macOS

Problem 3: Extracted Audio Duration Is Off

Cause: Input-side -ss snaps to the nearest keyframe, causing a slight offset.
Fix: Place -ss after -i for frame-accurate seeking (slower but precise), or use re-encoding instead of -c:a copy.

Problem 4: Audio Came Out as Mono

Cause: The source was recorded mono, or -ac 1 was unintentionally passed.
Fix:

# Check input channel count
ffprobe -v quiet -select_streams a -show_entries stream=channels input.mp4

# Force stereo output
ffmpeg -i input.mp4 -vn -c:a aac -ac 2 output.aac

Problem 5: WAV File Is Enormous

Cause: WAV is uncompressed PCM — about 10 MB/minute (44100 Hz, 16-bit, stereo).
Fix: Use FLAC for lossless compression or MP3 for lossy compression:

# Lossless compression with FLAC
ffmpeg -i input.mp4 -vn -c:a flac output.flac

FAQ

Q1. Should I always prefer lossless copy?
A. Yes — when the codec doesn’t need to change. -c:a copy is zero-quality-loss and much faster than re-encoding. Only re-encode when you need a different format, bitrate, or to apply audio filters.

Q2. Does converting MP4 to MP3 degrade quality?
A. Yes. MP4 audio is typically AAC; converting to MP3 (AAC → decode → MP3 encode) causes generation loss. To minimize it, use -q:a 0 (best VBR) or -b:a 320k (high fixed bitrate).

Q3. How do I find how many audio tracks a video has?

ffprobe -v quiet -show_entries stream=index,codec_name,codec_type -of default input.mkv | grep audio

Q4. Can I normalize the audio volume during extraction?
A. Yes — combine the loudnorm filter:

ffmpeg -i input.mp4 -vn -af loudnorm=I=-16:LRA=11:TP=-1.5 -c:a aac -b:a 192k output.aac

Q5. .aac files won’t play on Windows — what should I do?
A. Use .m4a instead — it’s the same AAC codec in an MPEG-4 container, which Windows Media Player and most apps support natively:

ffmpeg -i input.mp4 -vn -c:a copy output.m4a


Tested with: ffmpeg 6.1.1 / Ubuntu 24.04 (GitHub Actions runner)
Primary sources: ffmpeg.org/ffmpeg.html / ffmpeg.org/ffmpeg-codecs.html / ffmpeg.org/ffmpeg-filters.html