Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #5632, where missing AUD units for keyframes causes them to be merged with their preceding frame #5660

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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