pysubs2 icon indicating copy to clipboard operation
pysubs2 copied to clipboard

Support `X-TIMESTAMP-MAP` for WebVTT

Open X-C0DE opened this issue 3 years ago • 5 comments

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

X-C0DE avatar Aug 19 '20 00:08 X-C0DE

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)

tkarabela avatar Oct 18 '20 19:10 tkarabela

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

X-C0DE avatar Oct 18 '20 20:10 X-C0DE

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.

tkarabela avatar May 07 '21 23:05 tkarabela

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

tkarabela avatar Oct 31 '22 22:10 tkarabela

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

moi15moi avatar Dec 06 '22 01:12 moi15moi