Reputation: 59
I use ffmpeg to convert video to hls format (m3u8) and I use videojs to read this video. But I have a problem, subtitles appeared 1.4 seconds before the real timestamp.
I execute this command to extract video, audio and subtitles :
ffmpeg -i [file] -map 0:1 -c:a aac -ar 48000 -b:a 320k -hls_time 2 -hls_segment_filename audio/1/seq-%d.ts audio/1/320kbit.m3u8 -map 0:2 -c:a aac -ar 48000 -b:a 320k -hls_time 2 -hls_segment_filename audio/2/seq-%d.ts audio/2/320kbit.m3u8 -map 0:s:0 -f webvtt sub.vtt -map 0:v:0 -vf scale=1920:-2 -c:v h264 -profile:v main -g 48 -keyint_min 48 -crf 20 -sc_threshold 0 -b:v 5000k -maxrate 5350k -bufsize 7500k -hls_time 2 -hls_segment_filename video/1080p/seq-%d.ts video/1080p/5000k.m3u8
And this command to convert substile to hls format
ffmpeg -i sub.vtt -f segment -segment_time 2 -segment_list_size 0 -segment_list my-hero/subtitles/sub.m3u8 -segment_format webvtt -scodec copy my-hero/subtitles/seq-%d.vtt
And then I create a playlist file to gather all of that
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio-group",LANGUAGE="fre",NAME="Français",DEFAULT=YES,AUTOSELECT=YES,URI="audio/1/128k.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio-group",LANGUAGE="jpn",NAME="Japonais",DEFAULT=NO,AUTOSELECT=YES,URI="audio/2/128k.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Français",DEFAULT=yes,AUTOSELECT=YES,FORCED=NO,LANGUAGE="fr",URI="subtitles_fr.m3u8"
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,SUBTITLES="subs",AUDIO="audio-group"
video/1080p/5000k.m3u8
I don't see the problem so if anyone have an idea :/
Upvotes: 2
Views: 2051
Reputation: 8254
See my previous answer:
Ffmpeg burnt in subtitles out of sync when converting to hls
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.
Upvotes: 3