Sync a Specific Subtitle Track in MKV Using FFmpeg
Adjusting the timing of a single subtitle track in a multi-track MKV
file without altering the other video, audio, or subtitle streams can be
done efficiently using FFmpeg. This guide explains how to use the
-itsoffset option and stream mapping to delay or advance a
specific subtitle track while keeping all other tracks in their original
state, all without re-encoding.
The Logic Behind the Command
FFmpeg applies the -itsoffset option to the input file
that immediately follows it in the command line. To adjust only one
subtitle track, you must load the MKV file twice: 1. First Input
(unsynced): Used for the video, audio, and any other subtitle
tracks that do not need adjustment. 2. Second Input
(offset): Preceded by -itsoffset to shift the
timing, used solely to extract the target subtitle track.
By mapping the unaffected tracks from the first input and the offset subtitle track from the second input, you merge them into a single, corrected output file.
Step-by-Step Command
To delay or advance a specific subtitle track, use the following command structure:
ffmpeg -i input.mkv -itsoffset 3.5 -i input.mkv -map 0:v -map 0:a -map 0:s:0 -map 1:s:1 -c copy output.mkvExplaining the Command Parameters
-i input.mkv: The first input. This serves as the source for your video, audio, and unaltered subtitle tracks.-itsoffset 3.5 -i input.mkv: The second input, offset by 3.5 seconds.- Use a positive value (e.g.,
3.5) to delay the subtitles (make them appear later). - Use a negative value (e.g.,
-3.5) to advance the subtitles (make them appear earlier).
- Use a positive value (e.g.,
-map 0:vand-map 0:a: Copies all video and audio streams from the first (unmodified) input.-map 0:s:0: Copies the first subtitle track (index 0) from the first (unmodified) input.-map 1:s:1: Copies the second subtitle track (index 1) from the second (offset) input.-c copy: Copies all streams without re-encoding, preserving original quality and completing the process almost instantly.
How to Identify Your Subtitle Stream Indices
To ensure you map the correct streams, first check the stream layout
of your MKV file using ffprobe:
ffprobe input.mkvLook for the subtitle streams in the output. For example: *
Stream #0:2: Subtitle: subrip (This is the first subtitle
track, referenced as s:0) *
Stream #0:3: Subtitle: subrip (This is the second subtitle
track, referenced as s:1)
Match these indices to your -map options to ensure only
the desired track receives the time offset.