Skip to content

Commit

Permalink
Fix issue #5632, where missing AUD units for keyframes causes them to…
Browse files Browse the repository at this point in the history
… be merged with their preceding frame (#5660)
  • Loading branch information
Thulinma committed Jul 14, 2023
1 parent 94cd133 commit ead838a
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/demux/tsdemuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,21 +573,8 @@ class TSDemuxer implements Demuxer {
switch (unit.type) {
// NDR
case 1: {
let iskey = false;
push = true;
if (!avcSample) {
avcSample = this.avcSample = createAVCSample(
true,
pes.pts,
pes.dts,
''
);
}

if (debug) {
avcSample.debug += 'NDR ';
}

avcSample.frame = true;
const data = unit.data;
// only check slice type to detect KF in case SPS found in same packet (any keyframe is preceded by SPS ...)
if (spsfound && data.length > 4) {
Expand All @@ -604,15 +591,42 @@ class TSDemuxer implements Demuxer {
sliceType === 7 ||
sliceType === 9
) {
avcSample.key = true;
iskey = true;
}
}
if (iskey) {
// if we have non-keyframe data already, that cannot belong to the same frame as a keyframe, so force a push
if (avcSample?.frame && !avcSample.key) {
pushAccessUnit(avcSample, track);
avcSample = this.avcSample = null;
}
}
if (!avcSample) {
avcSample = this.avcSample = createAVCSample(
true,
pes.pts,
pes.dts,
''
);
}

if (debug) {
avcSample.debug += 'NDR ';
}

avcSample.frame = true;
avcSample.key = iskey;
break;
// IDR
}
case 5:
push = true;
// handle PES not starting with AUD
// if we have non-keyframe data already, that cannot belong to the same frame as a keyframe, so force a push
if (avcSample?.frame && !avcSample.key) {
pushAccessUnit(avcSample, track);
avcSample = this.avcSample = null;
}
if (!avcSample) {
avcSample = this.avcSample = createAVCSample(
true,
Expand Down

0 comments on commit ead838a

Please sign in to comment.