Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue/4888-ccOffset #4889

Merged
merged 2 commits into from
Sep 13, 2022
Merged

Conversation

littlespex
Copy link
Collaborator

@littlespex littlespex commented Sep 9, 2022

Ensure the first continuity segment is processed in webvtt-parser's oncue handler.

The first continuity segment is hard coded with new: false. This prevents webvtt-parser from correctly calculating the ccOffset when you seek back to the first continuity segment after starting in a later segment:

webvtt-parser

  parser.oncue = function (cue: VTTCue) {
    // Adjust cue timing; clamp cues to start no earlier than - and drop cues that don't end after - 0 on timeline.
    const currCC = vttCCs[cc];
    let cueOffset = vttCCs.ccOffset;


    // Calculate subtitle PTS offset
    const webVttMpegTsMapOffset = (timestampMapMPEGTS - initPTS90Hz) / 90000;

    /////////////////////////////////////////////////////
    // Only "new" CCs get their cue offsets calculated.
    // This makes sense if you start playback from 0,
    // but causes a problem when `startPosition` is set
    // to a later continuity segment. When you seek back
    // the `cueOffset` remains at the later playhead time
    // and new cues are added at the wrong time.
    /////////////////////////////////////////////////////

    // Update offsets for new discontinuities
    if (currCC?.new) {
      if (timestampMapLOCAL !== undefined) {
        // When local time is provided, offset = discontinuity start time - local time
        cueOffset = vttCCs.ccOffset = currCC.start;
      } else {
        calculateOffset(vttCCs, cc, webVttMpegTsMapOffset);
      }
    }

Resolves issues:

#4888

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@robwalch robwalch added this to the 1.2.3 milestone Sep 13, 2022
@robwalch robwalch merged commit 4ddf764 into video-dev:master Sep 13, 2022
@littlespex littlespex deleted the issue/4888-ccOffset branch September 19, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants