From cb3351ef785b3df4bda8fe60f5272a6459c1b8b4 Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Mon, 17 Jul 2023 17:25:06 -0700 Subject: [PATCH] Use input timescale when remuxing inband captions (#5675) Fixes #5669 --- src/remux/mp4-remuxer.ts | 2 +- src/utils/texttrack-utils.ts | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/remux/mp4-remuxer.ts b/src/remux/mp4-remuxer.ts index 27c10e28a38..11d5e4b6dba 100644 --- a/src/remux/mp4-remuxer.ts +++ b/src/remux/mp4-remuxer.ts @@ -1125,7 +1125,7 @@ export function flushTextTrackUserdataCueSamples( // using this._initPTS and this._initDTS to calculate relative time sample.pts = normalizePts( - sample.pts - (initPTS.baseTime * 90000) / initPTS.timescale, + sample.pts - (initPTS.baseTime * inputTimeScale) / initPTS.timescale, timeOffset * inputTimeScale ) / inputTimeScale; } diff --git a/src/utils/texttrack-utils.ts b/src/utils/texttrack-utils.ts index dd64a9cc68c..1f8a944ea74 100644 --- a/src/utils/texttrack-utils.ts +++ b/src/utils/texttrack-utils.ts @@ -29,13 +29,19 @@ export function addCueToTrack(track: TextTrack, cue: VTTCue) { } } catch (err) { logger.debug(`[texttrack-utils]: ${err}`); - const textTrackCue = new (self.TextTrackCue as any)( - cue.startTime, - cue.endTime, - cue.text - ); - textTrackCue.id = cue.id; - track.addCue(textTrackCue); + try { + const textTrackCue = new (self.TextTrackCue as any)( + cue.startTime, + cue.endTime, + cue.text + ); + textTrackCue.id = cue.id; + track.addCue(textTrackCue); + } catch (err2) { + logger.debug( + `[texttrack-utils]: Legacy TextTrackCue fallback failed: ${err2}` + ); + } } } if (mode === 'disabled') {