subtitles sometimes come with mistimed lines at the beginning. for example this file had 18 lines that were mistimed before the rest of the correctly timed lines:
18
00:34:32,033 --> 00:34:34,224
<SHOW WHAT I HAVE>
19
00:28:51,438 --> 00:28:56,591
Let's say hello. Two, three!
if the mistimed subtitles aren't important you could just delete them, but in most cases you should re-time them manually. you can do this with a video player and a text editor, or a dedicated subtitling program such as aegisub
. I suggest making a back up before doing any editing.
subtitles will also come with sync issues, meaning they don't line up with the audio in the muxed file. this can be fixed by finding the offset between a subtitle and it's corresponding spoken line. vcr/cinematic segments are generally best for this as they are subbed before the stream and will always be timed correctly. if there aren't any of these segments then just use the very first subtitle.
for example, if the chosen subtitle is at 00:13:00
and the corresponding line is spoken at 00:15:30
, then the subtitles need to be offset by 2:30
. you can slot your offset into the following command, which also sets the subtitle language metadata and muxes them into the mkv:
ffmpeg -i stream.ts -itsoffset 00:00:00 -i <lang>.srt -metadata:s:s:0 language=<lang> -c copy mux.mkv
note: if the subtitle starts after the spoken line, prefix the time stamp with -
.
streams often begin and end with a short waiting room period. these are unnecessary and can be removed to reduce file size.
open the muxed file, find your desired start and end times, then slot them into the following command:
ffmpeg -i mux.mkv -ss 00:00:00 -to 00:00:00 -c copy trimmed.mkv