asticode / go-astisub

Manipulate subtitles in GO (.srt, .ssa/.ass, .stl, .ttml, .vtt (webvtt), teletext, etc.)
MIT License
577 stars 111 forks source link

Support configurable X-TIMESTAMP-MAP in webvtt #111

Closed nakkamarra closed 3 weeks ago

nakkamarra commented 1 month ago

I'd like to be able to set an X-TIMESTAMP-MAP before writing to WebVTT. Maybe could store it on Metadata as a struct? i.e

type TimestampMap struct {
    LocalTimestamp time.Duration
    PresentationTimestamp in64
}
nakkamarra commented 1 month ago

Actually, now that I look through what the webvtt reader is doing and think about it, this could just be done by directly by calculating the offset and then manually applying it i.e subtitles.Add(calculatedOffset) 🤔

nakkamarra commented 1 month ago

Actually I believe this needs to be reworked either way.

@anupcshan @asticode I don't believe we can always just apply the timeOffset from the X-TIMESTAMP-MAP like we are doing here, because if we want to be able to support writing the X-TIMESTAMP-MAP or manually applying the offset defined by it like my comment above suggests, we would have to consider the case that the current *Subtitles have been parsed from a WebVTT and the correction has already been applied. In this scenario we will have cue times that have been shifted by the offset, plus a header or Add(...) call applying the same offset again resulting in 2x the offset.

nakkamarra commented 1 month ago

Here's an example of the usage in a PR I've created, the usage still supports both cases I think, but in @anupcshan 's case where you want to write a WebVTT without the header and the time offset applied, you can do so with a call to Add()

nakkamarra commented 4 weeks ago

Sorry for the annoying bump @asticode @anupcshan but any thoughts on this issue / PR?

asticode commented 4 weeks ago

No worries, I have seen your PR but didn't have much time to review it. I'll try to do it next week 👍