When you work with videos that have multiple audio tracks or subtitles, leaving everything up to FFmpeg can leave only the streams you never intended to keep. The -map option lets you explicitly choose which video, audio, and subtitle streams to include in the output. This article explains -map through practical examples, from the basic syntax to extracting specific tracks, excluding streams with negative mapping, and combining multiple input files.
Tested with: FFmpeg 6.1 (verified against real FFmpeg) / Target OS: Windows / macOS / Linux
Default Behavior Without -map
If you do not specify -map, FFmpeg automatically selects one “best” stream of each kind:
- Video: the highest-resolution stream
- Audio: the stream with the most channels
- Subtitles: the first compatible subtitle may be selected when the output format and default subtitle encoder support it
To handle multiple audio tracks or specific subtitles, you need -map.
Basic Syntax of -map
-map [input file index]:[stream type]:[stream index]
- Input file index: the first input is
0, the second is1, and so on - Stream type:
v(video),a(audio),s(subtitle),d(data) - Stream index: the number within the same type (0-based)
Basic Usage
Select the First Video and First Audio Stream
ffmpeg -i input.mp4 -map 0:v:0 -map 0:a:0 -c copy output.mp4
Copy All Streams (Including Subtitles)
ffmpeg -i input.mkv -map 0 -c copy output.mkv
-map 0 includes every stream from input file 0 in the output.
Inspecting Stream Information
First, check the list of streams in the input file with ffprobe:
ffprobe -v quiet -show_streams -select_streams a input.mkv
Working with Multiple Audio Tracks
Extract Only a Specific Audio Track (the Second One)
ffmpeg -i input.mkv -map 0:v:0 -map 0:a:1 -c copy output_audio1.mp4
Include All Audio Tracks
ffmpeg -i input.mkv -map 0:v -map 0:a -c copy output_all_audio.mp4
Selecting Subtitle Streams
Output with Subtitles Included
ffmpeg -i input.mkv -map 0:v:0 -map 0:a:0 -map 0:s:0 -c copy output_with_sub.mkv
Extract Subtitles Only
ffmpeg -i input.mkv -map 0:s:0 -c:s copy output.srt
Negative Mapping (Excluding Specific Streams)
Prefixing -map with a - lets you exclude that stream:
All Streams Except Subtitles
ffmpeg -i input.mkv -map 0 -map -0:s -c copy output_nosubs.mkv
Specify -map 0 (all streams) followed by -map -0:s (exclude subtitles).
Exclude Only a Specific Audio Track
ffmpeg -i input.mkv -map 0 -map -0:a:1 -c copy output.mkv
Combining Streams from Multiple Input Files
Take the video and audio from two files and merge them into one:
ffmpeg -i video.mp4 -i audio.mp3 -map 0:v:0 -map 1:a:0 -c copy output.mp4
Combine Two Language Audio Tracks into One File
ffmpeg -i video.mp4 -i audio_ja.aac -i audio_en.aac \
-map 0:v:0 -map 1:a:0 -map 2:a:0 \
-c copy output_bilingual.mkv
Setting Stream Metadata
To set language tags on streams:
ffmpeg -i input.mkv -map 0 -c copy \
-metadata:s:a:0 language=jpn \
-metadata:s:a:1 language=eng \
output.mkv
Summary of Common Use Cases
| Goal | Command |
|---|---|
| Extract video only | -map 0:v:0 |
| Extract audio only | -map 0:a:0 |
| Copy all streams | -map 0 |
| All streams except subtitles | -map 0 -map -0:s |
| Replace audio from another file | -map 0:v -map 1:a |
Measured Example
If a 2-minute MKV contains one video stream, two audio streams, and one subtitle stream, -map 0 -c copy copies all streams without re-encoding:
ffmpeg -i input.mkv -map 0 -c copy output_all.mkv
This is mostly remuxing, so on an SSD it often finishes in a few to a dozen seconds. Output size is usually almost identical to the input, though container metadata and indexes can change it by a few MB.
If you copy subtitles from MKV to MP4, the command may fail depending on the subtitle format. For MP4, either omit subtitles or convert them to a supported format. Before delivery, inspect the output with ffprobe and verify audio count, language tags, and channel layout. Results vary by environment.
Related Articles
- Adding, Selecting, and Removing Multiple Audio Tracks
- Embedding Subtitles into Video
- How Filtergraphs Work and How to Write Complex Filters
Primary sources: ffmpeg.org/ffmpeg.html#Stream-specifiers-1 / trac.ffmpeg.org/wiki/Map