Skip to content

Commit

Permalink
fix(Remuxer): Safari segment overlap ensure PTS order (#6132)
Browse files Browse the repository at this point in the history
* fix(Remuxer): Safari segment overlap ensure PTS alignment
  • Loading branch information
Asen-O-Nikolov committed Jan 29, 2024
1 parent 763c129 commit af42912
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/remux/mp4-remuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,27 @@ 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 = nextSamplePTS <= currentSamplePTS;
const prevOrder = nextSamplePTS <= prevPTS;

isPTSOrderRetained = currentOrder == prevOrder;
}
}
}
logger.log(
Expand Down

0 comments on commit af42912

Please sign in to comment.