Map Multiple Audio and Subtitle Streams in FFmpeg
This article provides a straightforward guide on how to use FFmpeg in
Linux to map multiple audio and subtitle streams from one or more input
files into a single output file. You will learn the core syntax of the
-map option, how to select specific language tracks, and
how to preserve all available streams without automatic filtering.
Understanding the FFmpeg Map Syntax
By default, when FFmpeg processes an input file, it only selects one
stream of each type (one video, one audio, one subtitle) based on the
highest quality or default flags. To override this behavior and manually
select multiple streams, you must use the -map option.
The basic syntax for mapping uses the input file index and the stream index, separated by a colon:
-map input_file_index:stream_type_specifier:stream_indexinput_file_index: The order of the input file starting at0for the first file,1for the second, etc.stream_type_specifier: Letters likevfor video,afor audio, andsfor subtitles.stream_index: The sequence number of that specific stream type, starting at0.
Command to Map All Streams
If your goal is to copy every single video, audio, and subtitle stream from a single input file into the output file without discarding anything, use the following command:
ffmpeg -i input.mkv -map 0:v -map 0:a -map 0:s -c copy output.mkvIn this command, -map 0:v grabs all video streams from
the first input, -map 0:a grabs all audio streams, and
-map 0:s grabs all subtitle streams. The
-c copy flag ensures the streams are copied directly
without re-encoding, which saves time and preserves quality.
Command to Map Specific Audio and Subtitle Tracks
If you have a file with multiple language tracks and you only want to include specific ones, you can target them directly by their index numbers.
For example, to create an output file containing the main video, the first two audio tracks (e.g., English and Spanish), and the second subtitle track, use:
ffmpeg -i input.mkv -map 0:v:0 -map 0:a:0 -map 0:a:1 -map 0:s:1 -c copy output.mkvCombining Streams from Multiple Input Files
FFmpeg also allows you to merge audio and subtitle streams from entirely separate files into a single container.
The following command takes the video from the first file
(0:v:0), an English audio track from a second file
(1:a:0), and a French subtitle track from a third file
(2:s:0):
ffmpeg -i video.mp4 -i audio.mp3 -i subtitles.srt -map 0:v:0 -map 1:a:0 -map 2:s:0 -c:v copy -c:a aac -c:s srt output.mkvNote: When mixing different file formats, you may need to specify encoders (like
-c:a aacor-c:s srt) instead of using-c copyif the destination container does not support the original source codecs natively.