Skip to content

Commit

Permalink
Handle PTS rollover on initial sample of video or audio
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Walch committed Oct 8, 2020
1 parent b5b2889 commit df80df0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/remux/mp4-remuxer.js
Expand Up @@ -52,7 +52,7 @@ class MP4Remuxer {
} else {
return sample.pts;
}
}, videoSamples[0].pts);
}, PTSNormalize(videoSamples[0].pts, 0));
if (rolloverDetected) {
logger.debug('PTS rollover detected');
}
Expand All @@ -76,7 +76,7 @@ class MP4Remuxer {
// when providing timeOffset to remuxAudio / remuxVideo. if we don't do that, there might be a permanent / small
// drift between audio and video streams
const startPTS = this.getVideoStartPts(videoTrack.samples);
const tsDelta = audioTrack.samples[0].pts - startPTS;
const tsDelta = PTSNormalize(audioTrack.samples[0].pts, 0) - startPTS;
const audiovideoTimestampDelta = tsDelta / videoTrack.inputTimeScale;
audioTimeOffset += Math.max(0, audiovideoTimestampDelta);
videoTimeOffset += Math.max(0, -audiovideoTimestampDelta);
Expand Down Expand Up @@ -190,7 +190,7 @@ class MP4Remuxer {
if (computePTSDTS) {
const startPTS = this.getVideoStartPts(videoSamples);
const startOffset = Math.round(inputTimeScale * timeOffset);
initDTS = Math.min(initDTS, videoSamples[0].dts - startOffset);
initDTS = Math.min(initDTS, PTSNormalize([0].dts, 0) - startOffset);
initPTS = Math.min(initPTS, startPTS - startOffset);
this.observer.trigger(Event.INIT_PTS_FOUND, { initPTS });
}
Expand Down

0 comments on commit df80df0

Please sign in to comment.