Skip to content
Latchkey

ffmpeg -vn: Extract Audio From Video

ffmpeg -i in.mp4 -vn -c:a libmp3lame out.mp3 drops the video and writes only the audio track.

Pulling audio out of a clip (for transcription, captions, or a smaller asset) is a one-liner. The choice is whether to copy the existing audio codec or re-encode it.

What it does

-vn disables the video stream so ffmpeg writes audio only. With -c:a copy it extracts the original encoded audio without quality loss (when the container supports it); with a codec like libmp3lame or aac it re-encodes.

Common usage

Terminal
# extract and re-encode to MP3
ffmpeg -i in.mp4 -vn -c:a libmp3lame -q:a 2 out.mp3
# copy the original audio losslessly into an M4A
ffmpeg -i in.mp4 -vn -c:a copy out.m4a
# extract a specific audio stream (second track)
ffmpeg -i in.mkv -map 0:a:1 -vn -c:a copy track2.m4a

Options

FlagWhat it does
-vnNo video: output audio only
-c:a copyCopy audio without re-encoding
-c:a libmp3lameRe-encode to MP3
-q:a <n>VBR quality for MP3 (0 best .. 9 worst)
-b:a <rate>Constant audio bitrate, e.g. 192k
-map 0:a:<n>Select a specific audio stream by index

In CI

Prefer -c:a copy when you just need the audio out of the container; it is fast and lossless. Only re-encode when you need a specific format (MP3 for compatibility) or a smaller file. Add -y to avoid the overwrite prompt.

Common errors in CI

"Could not write header for output file ... Invalid argument" with -c:a copy means the source audio codec is incompatible with the target container (e.g. copying AAC into an MP3 file); re-encode or pick a matching extension. "Stream map '0:a:1' matches no streams" means there is no second audio track; check with ffprobe. "Unknown encoder 'libmp3lame'" means the build lacks the MP3 encoder; install a full ffmpeg.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →