Extracting Audio from Video — Lossless Copy vs. Re-Encoding

There are many reasons to extract only the audio track from a video file: building a BGM or sound effects library, preparing interview audio for transcription, organizing podcast source material, and more. FFmpeg can handle all of these with a single command, but choosing incorrectly between “lossless copy” and “re-encoding” can lead to compatibility problems or quality loss. This article clarifies the difference and presents command examples for the most common formats.

Tested with: ffmpeg 6.1.1 / Ubuntu 24.04


1. The -vn Option: Excluding the Video Stream

-vn is specified on the output side to prevent the video stream from being included in the output file. The official documentation describes it as “disables video recording i.e. automatic selection or mapping of any video stream.”

The basic form of audio extraction looks like this:

ffmpeg -i input.mp4 -vn output.mp3

Adding -vn removes the video, and the remaining audio stream is encoded (or converted) to match the output format.


2. Lossless Extraction: Using -c:a copy

How It Works and Its Benefits

Specifying -c:a copy writes the audio data directly to the container without decoding or encoding it. Processing is fast and audio quality does not change.

ffmpeg -i input.mp4 -vn -c:a copy output.aac

Watch Out for Container/Codec Compatibility

Lossless copy means “keep the codec as-is, only change the container.” Therefore, the output container must support the input codec.

Input ContainerAudio CodecAppropriate Extensions for Lossless Copy
.mp4AAC.aac, .m4a, .mp4 (audio only)
.mkvFLAC.flac, .mkv
.mkvAAC.aac, .m4a
.movAAC.aac, .m4a
.aviMP3.mp3

For example, trying to losslessly copy an AAC stream into .mp3 will error because the MP3 container does not support the AAC codec. Before outputting without codec conversion, verify that the container supports the codec.


3. Re-Encoding Extraction

Use re-encoding when you need to change the codec, or when you want to output at a specific bitrate or quality.

Convert MP4 to MP3

ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3

Convert MP4 to AAC

ffmpeg -i input.mp4 -vn -c:a aac -b:a 192k output.aac

Convert MKV to FLAC

ffmpeg -i input.mkv -vn -c:a flac output.flac

FLAC is a lossless codec. If the source audio is uncompressed PCM, it can be compressed without quality loss.

Convert MKV to WAV (Uncompressed)

ffmpeg -i input.mkv -vn -c:a pcm_s16le output.wav

pcm_s16le is 16-bit little-endian PCM, the standard WAV format.


4. Explicitly Selecting a Stream: -map 0:a:0

When a video file contains multiple audio tracks (e.g., a Japanese track and an English track), FFmpeg automatically selects one by default. Use -map to specify a particular track.

ffmpeg -i input.mkv -map 0:a:0 -c:a copy output.aac

To extract the second audio track, specify 0:a:1.


5. Checking Audio Streams (ffprobe)

Verifying the audio codec before extraction helps avoid container compatibility mistakes.

ffprobe -v error -select_streams a -show_entries stream=codec_name,sample_rate,channels -of csv=p=0 input.mp4

Example output:

aac,44100,2

This shows the codec name, sample rate, and channel count.


6. Lossless Copy vs. Re-Encoding: How to Choose

ConditionRecommendation
Output codec unchanged (same format)-c:a copy (lossless)
Output format does not support the input codecRe-encode
Want to change bitrate or qualityRe-encode
Want to change the sample rateRe-encode

Quality perspective: Lossless copy does not alter audio quality. Re-encoding causes generation loss when the source audio is already lossy (MP3, AAC, etc.). The general rule is to prefer lossless copy whenever possible and only re-encode when a codec conversion is truly necessary.



Tested with: ffmpeg 6.1.1 / Ubuntu 24.04 (GitHub Actions runner)
Primary sources: ffmpeg.org/ffmpeg.html / ffmpeg.org/ffmpeg-codecs.html / ffmpeg.org/ffmpeg-filters.html