Adding multiple subtitle streams to an MKV file with FFmpeg requires precise input mapping and distinct output indices. The command must explicitly map each subtitle source to a separate stream index using the -map flag, ensuring that video, audio, and all subtitle files are correctly associated before muxing into the final container.
Understanding the Mapping Requirement
The core issue when adding multiple subtitles is not a limitation of the MKV format or FFmpeg itself, but rather how the muxer handles stream selection. By default, FFmpeg automatically selects one stream per type (video, audio, subtitle) from the inputs if you do not specify otherwise. When you have multiple subtitle sources, such assub1.srt and sub2.srt, you must manually tell FFmpeg which input corresponds to which output stream. This is achieved through the -map option, which allows granular control over every single stream in your input files. Without explicit mapping, FFmpeg may ignore subsequent subtitle inputs or overwrite previous ones, leading to the perception that only one subtitle track is being added.
To successfully include multiple subtitle tracks, you need to treat each subtitle file as a separate input. For example, if you have a video file movie.mp4 and two subtitle files english.srt and french.srt, you will provide three inputs to FFmpeg. The order of these inputs matters because it determines the input indices used in your mapping commands. Typically, the first input is index 0, the second is index 1, and the third is index 2. You then use -map to select specific streams from these inputs to be included in the output.
Distinguishing Stream Types
It is crucial to distinguish between video, audio, and subtitle streams in your mapping. A common mistake is to assume that all streams from a subtitle file are subtitles; however, some formats might carry metadata or other data types. Using the-c:s copy instruction tells FFmpeg to copy the subtitle codec without re-encoding, which is safe for text-based formats like SRT or ASS. For binary subtitle formats like PGS (used in Blu-rays), copying is also generally safe, but encoding might be required for compatibility with certain players. Understanding this distinction helps prevent errors where the muxer fails to recognize a stream as a subtitle.
For more context on handling subtitles during conversion, see Converting VOB to MKV with Subtitles and Audio Preserved.
Constructing the Correct Command
A valid command structure starts by listing all inputs, followed by the mapping instructions, and finally the output file. Let us break down a robust command line that adds two subtitle tracks to a video. Assume your inputs are arranged as follows:0: movie.mp4(contains video and audio)1: english.srt2: french.srt
ffmpeg -i movie.mp4 -i english.srt -i french.srt \
-map 0:v -map 0:a -map 1:s -map 2:s \
-c copy \
output.mkv
In this example, -map 0:v selects the video stream from the first input. -map 0:a selects the audio stream from the first input. -map 1:s selects the subtitle stream from the second input (English), and -map 2:s selects the subtitle stream from the third input (French). The -c copy flag ensures that no streams are re-encoded, preserving quality and speed. Note that -c copy applies to all mapped streams unless overridden by specific codec settings.
Handling Complex Inputs
If your video file contains multiple audio tracks or chapters, you may need to be more specific with your maps. Instead of-map 0:a, you might use -map 0:a:0 to select only the first audio track. Similarly, for subtitles, if a file contains multiple subtitle streams, you can target them individually using :0, :1, etc. This level of detail prevents accidental inclusion of unwanted streams and ensures that the output MKV file has exactly the tracks you intend.
When dealing with burned-in captions, character rendering issues can arise. See The Challenge of Rendering Characters with FFmpeg for troubleshooting text display problems.
Verifying the Output
After running the command, verify that both subtitle streams are present in the output file. You can use ffprobe to inspect the media file:ffprobe output.mkv
Look for the "Stream" lines that indicate Subtitle type. You should see two distinct subtitle streams, each with its own index and language tag if available. If only one subtitle stream appears, review your mapping commands to ensure that both subtitle inputs were correctly referenced. It is also helpful to check the metadata tags within the subtitle streams, as some players rely on these tags to identify the language of each track.
Language Tags
To assign language tags to your subtitle streams, you can add-metadata:s:s:0 lang=eng and -metadata:s:s:1 lang=fre to your command. This ensures that media players like VLC or MPV correctly label the tracks as English and French, improving the user experience for viewers switching between languages.
Common Pitfalls and Solutions
One frequent error is mixing up the input indices. If you accidentally map-map 1:s when the English subtitle is actually input 2, the wrong file will be included. Always count your inputs carefully from zero. Another pitfall is using -c:s mov_text incorrectly; while this converts subtitles to a native MOV text format, it may not be compatible with all MKV players. Sticking to -c copy for standard SRT or ASS files is usually the safest approach.
For information on merging different media types, refer to Merging Three Audio Files into One: A Tech Support Guide, which shares similar mapping principles.
Frequently Asked Questions
Why does FFmpeg only keep one subtitle track?
FFmpeg defaults to selecting one stream per type if you do not use the-map flag. To keep multiple subtitles, you must explicitly map each subtitle input to a separate output stream using -map indices.
Can I burn multiple subtitles into the video simultaneously?
No, FFmpeg cannot burn multiple independent subtitle layers into a single video pixel stream simultaneously. You would need to merge the subtitle files into one before burning, or use external tools to composite them, though this is rarely supported natively in playback.What is the difference between -c copy and -c:s mov_text?
-c copy preserves the original subtitle format (e.g., SRT, ASS) inside the MKV container, which is ideal for flexibility. -c:s mov_text converts subtitles to a simpler text format, which may improve compatibility with older players but reduces formatting options.
How do I check if my subtitles are correctly tagged?
Useffprobe output.mkv and look for the language tag in the subtitle stream details. You can also set these tags manually using the -metadata:s:s:X lang=XXX parameter in your FFmpeg command.
Does this method work for PGS subtitle streams?
Yes, you can map PGS subtitle streams just like SRT files using-map. Ensure you use -c copy to preserve the bitmap nature of PGS subtitles, as re-encoding them can lead to significant quality loss or incompatibility.