Log in

View Full Version : ffmpeg creates subtitles delay


carlosrodriguez
10th July 2020, 23:44
Hi everyone

I want to mux a .ass subtitles file into a matroska container together with a video stream.

First I checked the .ass file in Aegisubs before muxing and I got the following timing on the individual subtitles lines:
First text line from 00:14.49 - 00:17.83
https://i.imgur.com/npkj1Ff.png



If I now mux the .ass file together with a .mkv video file with mkvtoolnix I get the following timing on the first line (through checkingt he resulting .mkv with embedded .ass in Aegisub):
First text line from 00:14.49 - 00:17.83
https://i.imgur.com/1jlsA45.png
mkvtoolnix muxed the subtitles file exactly as it was when I checked the .ass file in Aegisub before muxing.



When I tried to mux the .ass file together with a video.mkv file using ffmpeg and the following command, the subtitles timing gets messed up and delayed (through checking the resulting .mkv with embedded .ass in Aegisub):
ffmpeg -i video.mkv -i subtitles.ass -map 0 -map 1 -c copy -output.mkv
First text line from 00:14.44 - 00:17-78
https://i.imgur.com/ghj6e4U.png



In conclusion: When I mux with ffmpeg instead of mkkvtoolnix, I get delayed subtitles of - 0.05s.

Has anybody else encountered this problem when muxing subtitles with ffmpeg. How can I avoid this and make ffmpeg mux the .ass file exactly as it is shown when opened in Aegisub without creating that 0.05s delay?

carlosrodriguez
11th July 2020, 22:49
I found a quick and dirty workaround with itsoffset like this

ffmpeg -i video.mkv -itsoffset 0.05 -i subs.ass -c copy output.mkv

It seems to work but it is still somewhat problematic because I don't know if the subtitles offset is always 0.05s and always in the same direction. I am muxing wiith .bat batch files and if I have to test every single file again for the delay I could just as well mux them one by one in mkvtoolnix. The whole point of me doing it in ffmpeg command line is that I can automate it with batch.

Would still appreciate it if somebody knows why this delay happens in the first place and if there is any command that prevents it. Must be something with timestamps or key frames or the sorts. I have no experience with these things unfortunately.

sneaker_ger
12th July 2020, 09:57
I am muxing wiith .bat batch files and if I have to test every single file again for the delay I could just as well mux them one by one in mkvtoolnix. The whole point of me doing it in ffmpeg command line is that I can automate it with batch.
MKVToolNix includes "mkvmerge" which is a cli tool like ffmpeg.
mkvmerge -o "output.mkv" "video.mkv" "subs.ass"
https://mkvtoolnix.download/doc/mkvmerge.html

carlosrodriguez
12th July 2020, 12:54
Thank you sneaker_ger I didn't think of that. I will use this method from now on with the option of .bat files and without having to deal with the delay.