4

I have a file that has subtitles burn into it and they are perfectly in sync.

Here is the file. https://983yqbz442.s3.amazonaws.com/little-mermaid-captions.mp4

I run this command to convert to hls and it creates the .ts files and the .vtt files.

ffmpeg -i little-mermaid-captions.mp4 -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index.m3u8

I also then create a master.m3u8 file in the same folder with the following.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360,SUBTITLES="subtitles"
index.m3u8
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitles",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="ENG",URI="index_vtt.m3u8"

Now if I play the master.m3u8 file the subtitles are now out of sync and are about 1 sec to quick. I understand this is probably a setting I am missing through FFmpeg but really stuck on this and would appreciate any insight.

Thanks

More info.

Here is a link to the direct .m3u8 this can be opened in Safari.

https://983yqbz442.s3.amazonaws.com/hlstests/master.m3u8

The generated vtt file is here.

https://983yqbz442.s3.amazonaws.com/hlstests/subs-0.vtt

If you look at the start of the .vtt file you will see this.

WEBVTT

00:06.840 --> 00:10.320
once long ago in the deep blue below

It should start at 00:06.840 but when playing the .m3u8 file in Safari you should see it starts at around 5 seconds not 6 about a second too early.

user1503606
  • 3,872
  • 13
  • 44
  • 78
  • I took your mp4 converted it to HLS with your command line. I played the HLS with HLS.js in Chrome, Edge and the mp4 in VLC. The subtitles are dead on in all three scenarios. This may be player issue. What do you use for playback? – Markus Schumann May 19 '20 at 14:04
  • Hi, @MarkusSchumann thanks for the info I have updated the answer with more information. If you play the downloaded .mp4 in Quicktime you will see the correct timing. – user1503606 May 19 '20 at 15:22

1 Answers1

6

For some reason FFMPEG adds about 1.4 seconds to the presentation time of the MPEG-2 Transport Stream when writing. So your video and audio are late. If you add -muxdelay 0 to your FFMPEG command line the sync issue should be resolved.

Markus Schumann
  • 7,636
  • 1
  • 21
  • 27
  • Thank you so much for this really appreciate you helping me out this is a lifesaver was driving me crazy ;) – user1503606 May 21 '20 at 11:38
  • You are welcome. It is definitely an interesting issue. I wonder why FFMPEG is adding a Presentation Time (PTS) offset by default. Microsoft Edge native playback is out of sync - honoring the PTS offset while hls.js is in sync ignoring the PTS offset. Good luck with your project. – Markus Schumann May 21 '20 at 14:24