Add Localized SRT Subtitles to Video with FFmpeg

Adding localized subtitles to a video file is essential for reaching a global audience. This article provides a straightforward, step-by-step guide on how to use the command-line tool FFmpeg to embed an external SubRip (SRT) subtitle file into a video container. You will learn the exact commands needed to merge the files without re-encoding the video, assign the correct language metadata, and set a custom track title that displays in media players.

The Basic Command Structure

To add an SRT subtitle track to a video while setting the language and a custom title, use the following command template. This process uses stream copying (-c copy), which merges the files instantly without losing video quality.

ffmpeg -i input.mp4 -i subtitle.srt -c copy -metadata:s:s:0 language=spa -metadata:s:s:0 title="Spanish Subtitles" output.mkv

Command Breakdown

Target MP4 vs. MKV Containers

The choice of video container affects how subtitles are stored:

The MKV format natively supports raw SRT subtitles. The command above works perfectly for MKV outputs and preserves the exact format of your SRT file.

2. Outputting to MP4

The MP4 container does not support raw SRT subtitles. If you must output to an MP4 file, you must convert the subtitle codec to mov_text (the native subtitle format for MP4):

ffmpeg -i input.mp4 -i subtitle.srt -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=fra -metadata:s:s:0 title="French Subtitles" output.mp4

Note: -c:s mov_text tells FFmpeg to convert the SRT subtitle stream to MP4-compatible text, while -c:v copy and -c:a copy ensure the video and audio streams are copied without re-encoding.

Adding Multiple Localized Tracks

If you want to add multiple localized subtitle tracks at once, you can map multiple input files and define metadata for each track sequentially:

ffmpeg -i input.mp4 -i english.srt -i spanish.srt -map 0 -map 1 -map 2 -c copy \
-metadata:s:s:0 language=eng -metadata:s:s:0 title="English (SDH)" \
-metadata:s:s:1 language=spa -metadata:s:s:1 title="Spanish" \
output.mkv

In this multi-track command: * -map 0 -map 1 -map 2 tells FFmpeg to include all streams from the video (input 0), the first subtitle (input 1), and the second subtitle (input 2). * s:s:0 targets the first subtitle track (English). * s:s:1 targets the second subtitle track (Spanish).