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.mkvCommand Breakdown
-i input.mp4: Specifies the input video file.-i subtitle.srt: Specifies the input subtitle file.-c copy: Copies the video and audio streams directly without re-encoding them, saving time and CPU power.-metadata:s:s:0 language=spa: Sets the language metadata for the subtitle track.s:s:0targets the first subtitle stream. Use the standard ISO 639-2 three-letter language code (e.g.,spafor Spanish,frafor French,deufor German).-metadata:s:s:0 title="Spanish Subtitles": Sets the custom track name that users will see in their media player’s subtitle selection menu.output.mkv: The resulting video file containing the embedded subtitle track.
Target MP4 vs. MKV Containers
The choice of video container affects how subtitles are stored:
1. Outputting to MKV (Recommended)
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.mp4Note: -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.mkvIn 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).