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

Bugfix/webvtt-parse: cue offset (subtitle stream without X-TIMESTAMP-MAP) #4557

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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