Skip to content

Commit

Permalink
Apply PTSNormalize to ID3 and Text samples to handle timestamp rollover
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Walch committed Jul 31, 2020
1 parent 27fe40d commit aa15efa
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/remux/mp4-remuxer.js
Expand Up @@ -755,7 +755,7 @@ class MP4Remuxer {
this.remuxAudio(track, timeOffset, contiguous);
}

remuxID3 (track) {
remuxID3 (track, timeOffset) {
const length = track.samples.length;
if (!length) {
return;
Expand All @@ -768,8 +768,8 @@ class MP4Remuxer {
const sample = track.samples[index];
// setting id3 pts, dts to relative time
// using this._initPTS and this._initDTS to calculate relative time
sample.pts = ((sample.pts - initPTS) / inputTimeScale);
sample.dts = ((sample.dts - initDTS) / inputTimeScale);
sample.pts = PTSNormalize(sample.pts - initPTS, timeOffset * inputTimeScale) / inputTimeScale;
sample.dts = PTSNormalize(sample.dts - initDTS, timeOffset * inputTimeScale) / inputTimeScale;
}
this.observer.trigger(Event.FRAG_PARSING_METADATA, {
samples: track.samples
Expand All @@ -778,22 +778,21 @@ class MP4Remuxer {
track.samples = [];
}

remuxText (track) {
track.samples.sort(function (a, b) {
return (a.pts - b.pts);
});

let length = track.samples.length, sample;
remuxText (track, timeOffset) {
const length = track.samples.length;
const inputTimeScale = track.inputTimeScale;
const initPTS = this._initPTS;
// consume samples
if (length) {
for (let index = 0; index < length; index++) {
sample = track.samples[index];
const sample = track.samples[index];
// setting text pts, dts to relative time
// using this._initPTS and this._initDTS to calculate relative time
sample.pts = ((sample.pts - initPTS) / inputTimeScale);
sample.pts = PTSNormalize(sample.pts - initPTS, timeOffset * inputTimeScale) / inputTimeScale;
}
track.samples.sort(function (a, b) {
return (a.pts - b.pts);
});
this.observer.trigger(Event.FRAG_PARSING_USERDATA, {
samples: track.samples
});
Expand Down

0 comments on commit aa15efa

Please sign in to comment.