pysubs2
pysubs2 copied to clipboard
Support `X-TIMESTAMP-MAP` for WebVTT
On the vtt subtitle fragments, when opened in the subtitle edit, it does a correction/conversion, showing the "translated" times, but with pysubs2, as well with ffmpeg or another program where I can do a simple direct conversion from vtt to srt, this "translation" of the respective times does not happen... I tried to find the logic behind it and noticed that there is a delay based on the MPEGTS value, found at the beginning of the subtitle... does it have anything to do with it?
I am attaching a file where you can see this problem that I mention file-1_vtt.zip
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:368640
Yes, the X-TIMESTAMP-MAP
seems to be specifying an offset of subtitle times vs. media times ( https://sdks.support.brightcove.com/features/synchronizing-webvtt-captions.html ), though this is not part of the standard ( https://www.w3.org/TR/webvtt1/ ).
To handle this, it would be necessary to know what is the time scale of the MPEGTS
timestamp:
- Is it 368640 * 1 microsecond?
- Is it 368640 * some constant defined in the MPEG-TS standard?
- Does it depend on the input file? (let's hope not)
to solve this problem i made a workarround 🤣 delay = TIMESTAMP / 90 so I take this delay value in ms and apply it to the whole subtitle
It would be good to have some support for this, but I'm not sure how to implement this. If anyone has experience with X-TIMESTAMP-MAP
, feel free to point me in the right direction or open a pull request.
Note for implementation of X-TIMESTAMP-MAP
: The MPEG timestamps should be Presentation Timestamps (PES) with one unit being 1/90000 s. See also https://www.rfc-editor.org/rfc/rfc8216#section-3.5
Here is how SubstitleEdit implemented it:
How it "detect" the presence of X-TIMESTAMP-MAP
- https://github.com/SubtitleEdit/subtitleedit/blob/1304bccf757009d8b234f60fa7cc7e951ba46447/src/libse/SubtitleFormats/WebVTT.cs#L270-L274
- https://github.com/SubtitleEdit/subtitleedit/blob/1304bccf757009d8b234f60fa7cc7e951ba46447/src/libse/SubtitleFormats/WebVTT.cs#L233-L248
The function that return of how much the subtitle need to be delayed:
- https://github.com/SubtitleEdit/subtitleedit/blob/1304bccf757009d8b234f60fa7cc7e951ba46447/src/libse/SubtitleFormats/WebVTT.cs#L398-L457
Here is how an fork of ffmpeg (not official ffmpeg !) implemented it: https://github.com/anssih/FFmpeg/commit/65af02397a58300e9b9ec5820a59387e0af6ec53