Skip to content

Commit

Permalink
bugfix #4500
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Toczko committed Mar 11, 2022
1 parent 5df2c7b commit ed72063
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/utils/webvtt-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export function parseWebVTT(
let timestampMapLOCAL = 0;
let parsingError: Error;
let inHeader = true;
let timestampMap = false;

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.
Expand All @@ -134,16 +133,14 @@ export function parseWebVTT(
cueOffset = webVttMpegTsMapOffset - vttCCs.presentationOffset;
}

if (timestampMap) {
const duration = cue.endTime - cue.startTime;
const startTime =
normalizePts(
(cue.startTime + cueOffset - timestampMapLOCAL) * 90000,
timeOffset * 90000
) / 90000;
cue.startTime = startTime;
cue.endTime = startTime + duration;
}
const duration = cue.endTime - cue.startTime;
const startTime =
normalizePts(
(cue.startTime + cueOffset - timestampMapLOCAL) * 90000,
timeOffset * 90000
) / 90000;
cue.startTime = startTime;
cue.endTime = startTime + duration;

//trim trailing webvtt block whitespaces
const text = cue.text.trim();
Expand Down Expand Up @@ -180,7 +177,6 @@ export function parseWebVTT(
if (startsWith(line, 'X-TIMESTAMP-MAP=')) {
// Once found, no more are allowed anyway, so stop searching.
inHeader = false;
timestampMap = true;
// Extract LOCAL and MPEGTS.
line
.substr(16)
Expand All @@ -196,7 +192,6 @@ export function parseWebVTT(
// Convert cue time to seconds
timestampMapLOCAL = cueString2millis(cueTime) / 1000;
} catch (error) {
timestampMap = false;
parsingError = error;
}
// Return without parsing X-TIMESTAMP-MAP line.
Expand Down

0 comments on commit ed72063

Please sign in to comment.