Extract all audio tracks / streams
This puts all audio into one file:
ffmpeg -i input.mov -map 0:a -c copy output.mov
-map 0:a
selects all audio streams only. Video and subtitles will be excluded.
-c copy
enables stream copy mode. This copies the audio and does not re-encode it. Remove -c copy
if you want the audio to be re-encoded.
- Choose an output format that supports your audio format. See comparison of container formats.
Extract a specific audio track / stream
Example to extract audio stream #4:
ffmpeg -i input.mkv -map 0:a:3 -c copy output.m4a
-map 0:a:3
selects audio stream #4 only (ffmpeg
starts counting from 0).
-c copy
enables stream copy mode. This copies the audio and does not re-encode it. Remove -c copy
if you want the audio to be re-encoded.
- Choose an output format that supports your audio format. See comparison of container formats.
Extract and re-encode audio / change format
Similar to the examples above, but without -c copy
. Various examples:
ffmpeg -i input.mp4 -map 0:a output.mp3
ffmpeg -i input.mkv -map 0:a output.m4a
ffmpeg -i input.avi -map 0:a -c:a aac output.mka
ffmpeg -i input.mp4 output.wav
Extract all audio streams individually
This input in this example has 4 audio streams. Each audio stream will be output as single, individual files.
ffmpeg -i input.mov -map 0:a:0 output0.wav -map 0:a:1 output1.wav -map 0:a:2 output2.wav -map 0:a:3 output3.wav
Optionally add -c copy
before each output file name to enable stream copy mode.
Extract a certain channel
Use the channelsplit filter. Example to get the Front Right (FR) channel from a stereo input:
ffmpeg -i stereo.wav -filter_complex "[0:a]channelsplit=channel_layout=stereo:channels=FR[right]" -map "[right]" front_right.wav
channel_layout
is the channel layout of the input. It is not automatically detected so you must provide the layout name.
channels
lists the channel(s) you want to extract.
- See
ffmpeg -layouts
for audio channel layout names (for channel_layout
) and channel names (for channels
).
- Using stream copy mode (
-c copy
) is not possible to use when filtering, so the audio must be re-encoded.
- See FFmpeg Wiki: Audio Channels for more examples.
What's the difference between -map
and -vn
?
ffmpeg
has a default stream selection behavior that will select 1 stream per stream type (1 video, 1 audio, 1 subtitle, 1 data).
-vn
is an old, legacy option. It excludes video from the default stream selection behavior. So audio, subtitles, and data are still automatically selected unless told not to with -an
, -sn
, or -dn
.
-map
is more complicated but more flexible and useful. -map
disables the default stream selection behavior and ffmpeg
will only include what you tell it to with -map
option(s). -map
can also be used to exclude certain streams or stream types. For example, -map 0 -map -0:v
would include all streams except all video.
See FFmpeg Wiki: Map for more examples.
Errors
Invalid audio stream. Exactly one MP3 audio stream is required.
MP3 only supports 1 audio stream. The error means you are trying to put more than 1 audio stream into MP3. It can also mean you are trying to put non-MP3 audio into MP3.
WAVE files have exactly one stream
Similar to above.
Could not find tag for codec in stream #0, codec not currently supported in container
You are trying to put an audio format into an output that does not support it, such as PCM (WAV) into MP4.
Remove -c copy
, choose a different output format (change the file name extension), or manually choose the encoder (such as -c:a aac
).
See comparison of container formats.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
This is a useless, generic error. The actual, informative error should immediately precede this generic error message.