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
- Using
-vnto exclude video and output audio only - Lossless copy (
-c:a copy) vs. re-encoding — difference and when to use each - Format-specific commands for MP3, AAC, FLAC, and WAV
- Container/codec compatibility reference
- Selecting a specific audio track with
-map - Extracting a specific time range
- Batch audio extraction for an entire folder
- Five common errors and fixes
- 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
| Format | Codec | Compression | File Size | Best For |
|---|---|---|---|---|
.aac / .m4a | AAC | Lossy | Small | General use, phone compatibility |
.mp3 | MP3 | Lossy | Small | Most universal — music, podcasts |
.flac | FLAC | Lossless | Medium | Music archives, lossless storage |
.wav | PCM | Uncompressed | Large | DAWs, audio editing, professional |
.ogg | Vorbis | Lossy | Small | Games, web streaming |
.opus | Opus | Lossy | Smallest | Low bitrate with high quality |
Lossless Copy vs. Re-Encoding
| Condition | Recommendation |
|---|---|
| Output codec unchanged (AAC→AAC, etc.) | -c:a copy (lossless, fast) |
| Output codec changes (AAC→MP3, etc.) | Re-encode |
| Need different bitrate or sample rate | Re-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 Container | Audio Codec | Compatible Lossless Output |
|---|---|---|
| .mp4 | AAC | .aac, .m4a |
| .mkv | FLAC | .flac |
| .mkv | AAC | .aac, .m4a |
| .avi | MP3 | .mp3 |
| .mov | AAC | .aac, .m4a |
Option Reference
| Option | Meaning | Recommended Value |
|---|---|---|
-vn | Exclude video stream from output | Always include for audio extraction |
-c:a copy | Lossless audio copy | When codec stays the same |
-c:a libmp3lame | MP3 encoder | For MP3 output |
-q:a N | VBR quality (0–9) | 0 (best) to 2 (high quality) |
-b:a Nk | Fixed audio bitrate | Music: 192k–320k / Voice: 64k–128k |
-ac N | Change channel count | 1 (mono), 2 (stereo) |
-ar N | Change sample rate | 44100 (CD), 48000 (video standard) |
-map 0:a:N | Select N-th audio track | 0: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
Related Articles
- Audio Format Conversion — WAV, MP3, AAC, FLAC
- Loudness Normalization — EBU R128 with loudnorm Filter
- Inspect Metadata and Stream Info with ffprobe
- Extract Thumbnail from Video
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