From 052feab9f3a3998e95525e5aab92234d82accd6a Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Mon, 13 Jul 2020 12:14:14 -0400 Subject: [PATCH] Clamp DTS after timecode hole/overlap check and Safari frame duration calculation --- src/remux/mp4-remuxer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/remux/mp4-remuxer.js b/src/remux/mp4-remuxer.js index 645f1c8ee8c..875473e29be 100644 --- a/src/remux/mp4-remuxer.js +++ b/src/remux/mp4-remuxer.js @@ -285,6 +285,10 @@ class MP4Remuxer { mp4SampleDuration = Math.round((lastDTS - firstDTS) / (inputSamples.length - 1)); } + // Clamp first DTS to 0 so that we're still aligning on initPTS, + // and not passing negative values to MP4.traf. This will change initial frame compositionTimeOffset! + firstDTS = Math.max(firstDTS, 0); + let nbNalu = 0, naluLen = 0; for (let i = 0; i < nbSamples; i++) { // compute total/avc sample length and nb of NAL units