Skip to content

Commit

Permalink
PR remarks readjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Asen-O-Nikolov committed Jan 24, 2024
1 parent f507ecd commit e43fcc9
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/remux/mp4-remuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,29 @@ export default class MP4Remuxer implements Remuxer {
inputSamples[0].dts = firstDTS;
inputSamples[0].pts = firstPTS;
} else {
let isPTSOrderRetained = true;
for (let i = 0; i < inputSamples.length; i++) {
if (inputSamples[i].dts > firstPTS) {
if (inputSamples[i].dts > firstPTS && isPTSOrderRetained) {
break;
}

const prevPTS = inputSamples[i].pts;
inputSamples[i].dts -= delta;
inputSamples[i].pts -= delta;

// check to see if this sample's PTS order has changed
// relative to the next one
if (i < inputSamples.length - 1) {
const nextSamplePTS = inputSamples[i + 1].pts;
const currentSamplePTS = inputSamples[i].pts;

const currentOrder = Math.sign(
nextSamplePTS - currentSamplePTS,
);
const prevOrder = Math.sign(nextSamplePTS - prevPTS);

isPTSOrderRetained = currentOrder == prevOrder;
}
}
}
logger.log(
Expand Down Expand Up @@ -584,11 +601,6 @@ export default class MP4Remuxer implements Remuxer {
nbNalu += nbUnits;
sample.length = sampleLen;

// ensure sample increasing PTS
if (i > 0 && safariWebkitVersion) {
sample.pts = Math.max(inputSamples[i - 1].pts + 1, sample.pts);
}

// ensure sample monotonic DTS
if (sample.dts < dtsStep) {
sample.dts = dtsStep;
Expand Down

0 comments on commit e43fcc9

Please sign in to comment.