tkarabela / pysubs2

A Python library for editing subtitle files
http://pysubs2.readthedocs.io
MIT License
293 stars 39 forks source link

Support `X-TIMESTAMP-MAP` for WebVTT #34

Open X-C0DE opened 3 years ago

X-C0DE commented 3 years ago

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

tkarabela commented 3 years ago
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:

X-C0DE commented 3 years ago

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

tkarabela commented 3 years ago

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 commented 1 year ago

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

moi15moi commented 1 year ago

Here is how SubstitleEdit implemented it:

How it "detect" the presence of X-TIMESTAMP-MAP

The function that return of how much the subtitle need to be delayed:

Here is how an fork of ffmpeg (not official ffmpeg !) implemented it: https://github.com/anssih/FFmpeg/commit/65af02397a58300e9b9ec5820a59387e0af6ec53