How to Map Specific Streams in FFmpeg
This article explains how to use the FFmpeg -map option
to precisely select and route video, audio, and subtitle streams from
your input files to your output file. You will learn the basic syntax of
the -map option, see practical examples for single and
multiple inputs, and discover how to exclude specific streams during
processing.
By default, FFmpeg automatically selects only one video stream and
one audio stream from your inputs. To gain full control over which
streams are included in your output, you must use the -map
option.
The Basic Syntax
The syntax for the -map option uses the following
format:
-map input_file_index:stream_type_specifier:stream_indexinput_file_index: The 0-based index of the input file (e.g.,0for the first input file,1for the second).stream_type_specifier: An optional letter defining the stream type (vfor video,afor audio,sfor subtitles).stream_index: The 0-based index of the stream of that type (e.g.,a:0for the first audio stream,a:1for the second).
Common Use Cases and Examples
1. Map All Streams from an Input
To copy every single video, audio, and subtitle stream from your first input file to the output:
ffmpeg -i input.mkv -map 0 -c copy output.mkv2. Map Only the Video Stream
If you want to extract just the video from a file and discard all audio and subtitles:
ffmpeg -i input.mp4 -map 0:v output_video.mp43. Map a Specific Audio Track
If an input file has multiple language tracks and you want to select
the second audio track (index 1):
ffmpeg -i input.mkv -map 0:v:0 -map 0:a:1 -c copy output.mkvThis command maps the first video stream (0:v:0) and
the second audio stream (0:a:1).
4. Combine Streams from Multiple Input Files
To take the video from one file and the audio from another file:
ffmpeg -i video_input.mp4 -i audio_input.wav -map 0:v:0 -map 1:a:0 -c:v copy -c:a aac output.mp4-map 0:v:0selects the first video stream from the first input (video_input.mp4).-map 1:a:0selects the first audio stream from the second input (audio_input.wav).
5. Exclude a Specific Stream (Negative Mapping)
You can use a negative sign - to exclude specific
streams. For example, to map all streams from a file except the
subtitles:
ffmpeg -i input.mkv -map 0 -map -0:s -c copy output.mkvThis maps everything from the first input (-map 0)
and then explicitly removes all subtitle streams
(-map -0:s).