In multi-audio and multi-subtitle workflows, -map is one of FFmpeg’s most important and most frequently misused options.
If you don’t explicitly specify -map, FFmpeg auto-selects streams using default rules, and the output is often not what you expect. For example:
- Subtitles disappear after export
- The wrong language track is selected
- Unwanted data streams are included
This article uses common real-world scenarios to explain how -map works.
First, Understand What a “Stream” Is
A container file (such as mp4 or mkv) usually contains multiple streams, including:
- Video streams (
v) - Audio streams (
a) - Subtitle streams (
s) - Attachment/data streams (fonts, cover art, chapters, etc.)
You can inspect streams with ffprobe:
|
|
Basic -map Syntax
Most common pattern:
|
|
Examples:
0:v: all video streams from the 1st input0:a:0: the 1st audio stream from the 1st input1:s:1: the 2nd subtitle stream from the 2nd input
Notes:
input_indexstarts from0, based on-iorderstream_indexalso starts from0
Practical Examples
1) Video from A, audio from B
|
|
Meaning:
- Use the first video stream from
english.mp4 - Use the first audio stream from
french.mp3 - Merge into
french.mp4
2) Keep all streams from input 1, then add one more audio track
|
|
Meaning:
-map 0keeps all streams from the first input- Then append the first audio stream from the second input
Two Useful Advanced Tricks
1) Negative mapping: exclude unwanted streams
For example, keep everything from input 1 but remove its second audio stream:
|
|
2) Optional mapping: don’t fail when a stream is missing
If some files may not have subtitles, use ?:
|
|
0:s? means: map subtitles if present; otherwise skip without error.
Common Pitfalls
- Once you use
-map, FFmpeg stops automatic stream selection, so you must map everything you need. -c copyonly remuxes without transcoding. If the target container doesn’t support a codec, it still fails.- With multiple inputs, index mistakes are common. Input indices are determined only by
-iorder. - For robust scripts, inspect with
ffprobefirst, then generate-mapdynamically.
Summary
The core idea of -map is simple: explicitly tell FFmpeg which input to use, what stream type to pick, and which stream index to select.
Once you master this, you can reliably handle complex cases like multi-audio, multi-subtitle, and cross-file stream composition.