The single decision that matters when you pull audio out of a video with ffmpeg is whether to copy the audio stream untouched or re-encode it. Copying is instant and lossless because ffmpeg just lifts the existing audio bytes out of the video container and writes them to a new one:
ffmpeg -i input.mp4 -vn -c:a copy output.m4a-vn drops the video. -c:a copy takes the audio stream as-is, no quality loss, no waiting. The catch: the output container has to support the codec you are copying. An MP4's audio is almost always AAC, and AAC lives happily in a .m4a (or .aac) container, so the command above works. Try to copy that same AAC stream into a .mp3 and ffmpeg refuses, because MP3 files only hold MPEG audio.
Re-encoding is the other path. You hand ffmpeg an encoder and a target format and it rebuilds the audio:
# Re-encode to MP3 at a good VBR quality
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3Re-encode when you need a specific format the source is not already in (MP3 for an old player, WAV for an editor), or when you want to change the bitrate or sample rate. Copy when you just want the audio that is already there. The rest of this page is the detail behind that choice.
Re-encoding from a lossy source loses quality. If the video's audio is AAC (lossy) and you re-encode it to MP3 (also lossy), you decode and re-compress, and quality drops a little even at high settings. Copy the AAC out to
.m4ainstead and you keep the original bytes exactly. Only re-encode when you genuinely need the other format.
Check the source codec first with ffprobe
Before you decide whether copy will work, find out what codec the video's audio actually is. ffprobe (it ships with ffmpeg) prints it:
ffprobe -v error -select_streams a -show_entries stream=index,codec_name,channels,sample_rate -of default=noprint_wrappers=1 input.mp4That lists every audio stream with its codec, channel count, and sample rate, and nothing else. A typical MP4 reports codec_name=aac. Now you know:
- AAC copies cleanly to
.m4aor.aac. - Opus (common in WebM and modern files) copies to
.opus,.ogg, or.mka. - MP3 copies straight to
.mp3. - AC-3 / E-AC-3 (movie soundtracks) copies to
.ac3or.eac3.
If the codec matches a container you are happy with, copy. If not, re-encode. The error you get when copy and container disagree is explicit, something like Could not find tag for codec ... in stream, which is ffmpeg telling you that codec cannot live in that file type.
Copy the audio stream (fast, lossless)
This is the right default whenever the source format is acceptable. Match the extension to the codec ffprobe reported:
# AAC audio out of an MP4, untouched
ffmpeg -i input.mp4 -vn -c:a copy output.m4a
# Opus audio out of a WebM, untouched
ffmpeg -i input.webm -vn -c:a copy output.opusThere is no quality knob here because nothing is being re-compressed. It finishes in the time it takes to read the file. -vn is doing the real work of "audio only"; -c:a copy is doing the "do not touch it" work.
Re-encode to a target format
When you need a format the source is not in, pick an encoder. For MP3, that is libmp3lame:
# VBR, quality-targeted (recommended)
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3
# CBR, fixed bitrate, if a device needs it
ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 192k output.mp3-q:a 2 is variable bitrate aimed at roughly 190 kbps and is the better default than a fixed rate: it spends bits where the audio needs them. The scale runs 0 (best, biggest) to 9 (worst); 2 is the standard "transparent enough for anyone" choice. Use -b:a 192k only when something genuinely requires a constant bitrate.
For other targets, swap the encoder and extension:
# AAC into an .m4a (re-encode, e.g. from a non-AAC source)
ffmpeg -i input.mkv -vn -c:a aac -b:a 192k output.m4a
# Uncompressed WAV for an editor (large, lossless container)
ffmpeg -i input.mp4 -vn -c:a pcm_s16le output.wavA note on format choice: MP3 is the universal-compatibility option and the one to reach for when you do not know what will play the file. M4A (AAC) and Opus are better quality per kilobyte, and if your source is already one of them, copying beats any re-encode. WAV is for editing, not distribution: it is uncompressed and huge.
Extract just a segment
You rarely need the whole soundtrack. -ss seeks to a start time and -t sets a duration (or -to sets an absolute end). Put -ss before -i so the seek is fast:
# 30 seconds of audio starting at 1:05, copied untouched
ffmpeg -ss 00:01:05 -t 30 -i input.mp4 -vn -c:a copy clip.m4a
# Same window, re-encoded to MP3
ffmpeg -ss 00:01:05 -to 00:01:35 -i input.mp4 -vn -c:a libmp3lame -q:a 2 clip.mp3With -c:a copy, the cut can only land on a packet boundary, so the start may be a fraction off. If you need it frame-tight, re-encode (drop the copy) and seek with -ss after -i instead.
Pull a specific track from a multi-track file
Some files (a Blu-ray rip, a film with a director's commentary) carry several audio streams. ffprobe numbers them from zero; -map picks one:
# Take the second audio stream (0:a:1), copy it out
ffmpeg -i input.mkv -map 0:a:1 -c:a copy commentary.m4a0:a:1 reads as "input 0, audio stream index 1". Run the ffprobe command from earlier to see the index of each track before you map it. Without -map, ffmpeg picks the default audio stream, which is usually the first one.
If ffmpeg complains there is no audio stream (Output file does not contain any stream), the video is silent, there is nothing to extract, and ffprobe will show zero audio streams to confirm it.
For the full set of conversion, trimming, and remux commands in one place, see the ffmpeg command cheat sheet.
FAQ
See also
- The ffmpeg command cheat sheet: every common convert, trim, crop, and remux command in one reference.
- Add or replace an audio track on a video with ffmpeg: the inverse job, muxing an audio stream back onto video.
- Trim and cut a video with ffmpeg: the keyframe vs frame-accurate tradeoff behind
-ss,-t, and-to.
Sources
Authoritative references this article was fact-checked against.
- ffmpeg documentation (official)ffmpeg.org
- ffmpeg wiki: encoding to MP3 with libmp3lame (official)trac.ffmpeg.org
- ffprobe documentation (official)ffmpeg.org





