Delay and Merge Multiple SRT Subtitles into MKV with FFmpeg
This article provides a straightforward guide on how to use FFmpeg to
multiplex multiple SRT subtitle tracks into a single MKV video file
while applying individual time delays to each subtitle track. By using
the -itsoffset option, you can precisely synchronize each
language track with the video without permanently altering the original
SRT files.
To multiplex multiple subtitles with unique delay offsets, you must structure your FFmpeg command so that the offset option is placed immediately before the input subtitle file it is meant to affect.
Here is the template command to achieve this:
ffmpeg -i input.mp4 \
-itsoffset 2.5 -i subtitle_eng.srt \
-itsoffset -1.8 -i subtitle_spa.srt \
-map 0:v -map 0:a -map 1 -map 2 \
-c:v copy -c:a copy -c:s copy \
-metadata:s:s:0 language=eng -metadata:s:s:0 title="English" \
-metadata:s:s:1 language=spa -metadata:s:s:1 title="Spanish" \
output.mkvCommand Breakdown
-i input.mp4: Specifies the primary source video and audio file (mapped as input0).-itsoffset 2.5 -i subtitle_eng.srt: Applies a positive delay of 2.5 seconds to the English subtitle. The subtitles will appear 2.5 seconds later than their original timestamps.-itsoffset -1.8 -i subtitle_spa.srt: Applies a negative delay of 1.8 seconds to the Spanish subtitle, making them appear 1.8 seconds earlier.-map 0:v -map 0:a: Selects the video and audio streams from the first input file.-map 1 -map 2: Maps the first subtitle file (input1) and the second subtitle file (input2) into the output file.-c:v copy -c:a copy -c:s copy: Copies the video, audio, and subtitle streams directly without re-encoding, preserving quality and completing the process in seconds.-metadata:s:s:0 language=eng: Sets the language metadata for the first subtitle track (index 0 of the subtitle streams) to English.-metadata:s:s:1 language=spa: Sets the language metadata for the second subtitle track (index 1 of the subtitle streams) to Spanish.