Extract audio from a video
Pulls just the audio track out of a video file in seconds by stream-copying it into a new container, with no re-encoding or quality loss.
Last updated
ffmpeg -i input.mp4 -vn -c:a copy output.m4a
How it works
-vn ("no video") drops the video stream entirely, so ffmpeg only has to deal with audio. -c:a copy then copies the audio codec's bitstream as-is instead of decoding and re-encoding it — for an MP4 with AAC audio, that means remuxing into an .m4a container (also MPEG-4-based) takes seconds and loses nothing, versus a full re-encode that would take much longer and degrade quality slightly.
The .m4a extension matters here: it's the same container family as MP4, so it can hold the AAC stream directly. Pairing -c:a copy with an incompatible container (like .mp3) fails outright, because that format can't store an AAC bitstream verbatim.
Watch out for
- →If you actually need an MP3 file, drop -c:a copy and re-encode instead: ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3 — that's a real transcode, not a copy, so it takes longer and is technically lossy.
- →A source with multiple audio tracks (alternate languages, commentary) gets only the first one by default — add -map 0:a:0 (or the index you want) to pick a specific track explicitly.
- →This fails immediately, with no output file, if the source has no audio stream at all — expected behavior, but worth knowing before assuming something's broken.
Part by part
- -vn
- No video. Without it ffmpeg tries to carry the video stream into a container that may not accept it.
- -c:a copy
- Copy the audio stream rather than re-encoding it. This is the important flag: it is lossless and near-instant because no decoding happens.
- output.m4a
- The container must match the codec being copied. AAC audio from an MP4 belongs in an .m4a, which is why this recipe does not end in .mp3.
Common mistakes
ffmpeg -i input.mp4 -vn output.mp3Converting AAC to MP3 re-encodes lossy audio into a different lossy format, so you lose quality for no reason. Copy the stream to its native container unless something genuinely requires MP3.
ffmpeg -i input.mp4 -vn -c:a copy output.m4affmpeg -i input.mp4 -c:a copy output.m4aWithout -vn, ffmpeg may attempt to include the video stream. Depending on the container this either fails outright or produces a file far larger than the audio you asked for.
ffmpeg -i input.mkv -vn -c:a copy output.m4aThe flags are right but the assumption is not: a Matroska file may hold Vorbis, Opus or FLAC, none of which belong in an .m4a. Check the codec first with ffprobe and pick the container to match.
Questions
How do I find out what codec the audio is?
Run ffprobe against the file, or ffmpeg -i with no output — both print the stream list. The audio line names the codec, and that determines which container can hold a copied stream.
When should I re-encode instead of copying?
When the target genuinely cannot accept the source codec, or when you need a smaller file. Re-encoding always loses something from an already-lossy source, so treat it as a deliberate trade rather than a default.
Can I extract just part of the audio?
Yes — add -ss for the start point and -t for the duration, exactly as in the trimming recipe. Combined with -c:a copy the operation stays lossless and fast.
Why is the extracted file smaller than I expected?
Because the video was most of the original. Audio is typically a tenth or less of a video file's size, so an extract that looks suspiciously small is usually correct.