Extract audio from video

audio

// what it does

Pulls the audio track out of a video. -vn discards the video stream; the first form uses -acodec copy to stream-copy the existing audio bytes verbatim (instant, lossless) into a .aac file, while the second re-encodes to MP3 with libmp3lame at -q:a 2, a VBR quality level (~190 kbps average, where 0 is best and 9 worst). Reach for copy when you just need the raw track out, and libmp3lame when you need a portable MP3.

// shell

$ ffmpeg -i input.mp4 -vn -acodec copy audio.aac
$ ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3

// gotcha

With -acodec copy the container must accept the source codec, so the extension has to match what's actually in the file (AAC-in-MP4 becomes .aac). Copying that AAC into an incompatible container like .mp3 fails at the muxer — the mp3 muxer errors with 'Invalid audio stream. Exactly one MP3 audio stream is required.'