FFmpeg Map Video and Subtitles from Different Files
This article provides a quick and practical guide on how to use FFmpeg to combine a video track from one file with a subtitle track from another file. You will learn the exact command-line syntax required to map these specific streams and save the combined result into a new container without the need for time-consuming re-encoding.
To map streams from different files in FFmpeg, you use the
-map option. FFmpeg indexes input files starting from
0. Therefore, the first input file is 0, and
the second input file is 1.
Command to Map Video, Audio, and External Subtitles
In most cases, you will want to keep the video and audio from your primary media file and add the subtitles from a secondary file. Use the following command:
ffmpeg -i video_source.mp4 -i subtitle_source.srt -map 0:v -map 0:a -map 1:s -c copy output.mkvCommand Breakdown
-i video_source.mp4: Defines the first input file (index0), which contains the video and audio.-i subtitle_source.srt: Defines the second input file (index1), which contains the subtitle track.-map 0:v: Instructs FFmpeg to take the video stream (v) from the first input (0).-map 0:a: Instructs FFmpeg to take the audio stream (a) from the first input (0).-map 1:s: Instructs FFmpeg to take the subtitle stream (s) from the second input (1).-c copy: Copies all streams directly without re-encoding, making the process almost instantaneous.output.mkv: The final output file. The MKV container is highly recommended as it natively supports almost all subtitle formats (like SRT, ASS, and VTT).
Command to Map Only Video and Subtitles (No Audio)
If you want to extract only the video track from the first file (excluding its audio) and merge it with the subtitles from the second file, use this command:
ffmpeg -i video_source.mp4 -i subtitle_source.srt -map 0:v -map 1:s -c copy output.mkvBy omitting the -map 0:a parameter, FFmpeg will ignore
the audio track entirely during the merging process.