Search code examples
ffmpegtimestampsynchronizationm3u8webvtt

FFMPEG Webvtt m3u8 download into single vtt file, ignore the "X-TIMESTAMP-MAP=MPEGTS=" (timestamp sync problem)


I want to download the subtitle of a video, it has separated m3u8 file for subtitle:

webvtt source in m3u8 format: https://sdn-global-streaming-cache.3qsdn.com/9378/files/19/05/1199332/Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes.ism/Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes-textstream_deu=1000.m3u8

looks like:

#EXTM3U
#EXT-X-VERSION:4
## Created with Unified Streaming Platform(version=1.9.5)
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:989
#USP-X-TIMESTAMP-MAP:MPEGTS=900000,LOCAL=1970-01-01T00:00:00Z
#EXTINF:24.72, no desc
Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes-textstream_deu=1000-1.webvtt
#EXTINF:2.56, no desc
Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes-textstream_deu=1000-13.webvtt
#EXTINF:50.88, no desc
Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes-textstream_deu=1000-14.webvtt
#EXTINF:3.079, no desc
Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes-textstream_deu=1000-40.webvtt
#EXTINF:60.401, no desc
....

Then use the command to download the multiple webvtts into one vtt file "EN.vtt":

ffmpeg -i  "https://sdn-global-streaming-cache.3qsdn.com/9378/files/19/05/1199332/Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes.ism/Dqt6jZBkvX2nLyY4CGhxmpK89PbQRFV7-drm-aes-textstream_deu=1000.m3u8"  "DE.vtt"

In output "DE.vtt" the X-TIMESTAMP-MAP=MPEGTS:xxxxxx,LOCAL:00:00:00.000 from each webvtt file (webvtt in m3u8) are ignored.

so that the time Synchronisation is broken, the start time of each Segment always begins from 00:00:00, looks like:

WEBVTT

00:00.000 --> 00:02.560
So viel Macht.

00:00.000 --> 00:03.079
Was er sagte.

00:00.000 --> 00:04.680
oder
die Schönheit

00:00.000 --> 00:01.440
Er sagte immer:

00:00.000 --> 00:03.840
Auf seinen Klang 

00:00.000 --> 00:07.519
Seine Paranoia.

Could ffmpeg support the relative time stamp to convert into absolute time stamp? Or use other method to download perfect webvvt file?


Solution

  • All i could find was this very old patch that has never been merged into FFmpeg: https://patchwork.ffmpeg.org/project/ffmpeg/patch/[email protected]/

    I edited it a little bit and applied it to the current ffmpeg source code, recompiled and successfully converted some webVTT subtitles served via HLS with X-TIMESTAMP-MAP tags.

    This is the patch i finally used: https://gist.github.com/SebiderSushi/bdf8d46d5501f7085d0b27d8a19eb12c

    Edit:
    There is an open ticket on the FFmpeg issue tracker about this: https://trac.ffmpeg.org/ticket/8825