Skip to content

Extracting MP3 audio from an AVI file with ffmpeg

I look this up every few months, so here it is in one place. ffmpeg takes the video apart and writes just the audio track to an MP3 file.

The whole file:

ffmpeg -i sample.avi -vn -c:a libmp3lame -b:a 256k sample.mp3

-vn drops the video stream, -c:a libmp3lame selects the MP3 encoder and -b:a 256k sets the audio bitrate. For a variable bitrate instead, replace -b:a 256k with -q:a 2, which gives roughly 190 kbit/s at a noticeably better size-to-quality ratio.

To extract a section — here 40 seconds starting at 00:21:24:

ffmpeg -ss 00:21:24 -t 00:00:40 -i sample.avi -vn -c:a libmp3lame -b:a 256k sample.mp3

The position of -ss matters. Placed before -i as above, ffmpeg seeks in the input and starts decoding at that point, which is near instantaneous even in a large file. Placed after -i it decodes the file from the beginning and throws away everything before the timestamp: same result, much slower.

One more shortcut worth knowing: AVI files frequently already carry an MP3 audio track. In that case there is no need to re-encode at all, and no quality is lost:

ffmpeg -i sample.avi -vn -c:a copy sample.mp3

If the audio turns out to be AC-3, AAC or anything else, ffmpeg will refuse to write it into an .mp3 container — then fall back to the first command.

This post is from 2009. The commands have been updated to the modern option names: the original used -ab 256k, which still works today as an alias for -b:a, but the explicit -c:a / -b:a form is what current ffmpeg documentation uses.