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 #5652

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 32 additions & 15 deletions src/demux/video/avc-video-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,8 @@ class AvcVideoParser extends BaseVideoParser {
switch (unit.type) {
// NDR
case 1: {
let iskey = false;
push = true;
if (!VideoSample) {
VideoSample = this.VideoSample = this.createVideoSample(
true,
pes.pts,
pes.dts,
''
);
}

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

VideoSample.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 @@ -76,15 +63,45 @@ class AvcVideoParser extends BaseVideoParser {
sliceType === 7 ||
sliceType === 9
) {
VideoSample.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 (VideoSample?.frame && !VideoSample.key) {
this.pushAccessUnit(VideoSample, track);
VideoSample = this.VideoSample = null;
}
}

if (!VideoSample) {
VideoSample = this.VideoSample = this.createVideoSample(
true,
pes.pts,
pes.dts,
''
);
}

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

VideoSample.frame = true;
VideoSample.key = iskey;

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