Skip to content

Comments

Handle H265 encoders that produce multi-slice IDR #844

Open
chenosaurus wants to merge 6 commits intomainfrom
dc/handle_multi_slice_idr
Open

Handle H265 encoders that produce multi-slice IDR #844
chenosaurus wants to merge 6 commits intomainfrom
dc/handle_multi_slice_idr

Conversation

@chenosaurus
Copy link
Contributor

@chenosaurus chenosaurus commented Feb 6, 2026

Fix issue where a h265 encoder outputs multi-slice IDR, causing downstream decoders to fail.

  • add detection for multi-slide IDR via first_slice_segment_in_pic_flag and collect the slices into a single AU before emitting the frame.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • ✅ Full review completed - (🔄 Check again to review again)
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dc/handle_multi_slice_idr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chenosaurus chenosaurus requested a review from boks1971 February 6, 2026 21:15
Copy link
Contributor

@boks1971 boks1971 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments @chenosaurus . LGTM, but I am not familiar with all the nuances of the bitstream. Getting some more 👀 on this would be great.

if *sampleIsAnnexB || len(dst) > 0 {
if !*sampleIsAnnexB && len(dst) > 0 {
dst = append([]byte{0, 0, 0, 1}, dst...)
*sampleIsAnnexB = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be a return here? Not able to fully understand the sequence needed here, but letting this fall through seems like it adds another start code and also sets sampleIsAnnexB to true again. Seems redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned up

// aggregate vps,sps,pps into a single AP packet (chrome requires this)
// Aggregate VPS/SPS/PPS before the next access unit.
if nal.NalUnitType == 32 || nal.NalUnitType == 33 || nal.NalUnitType == 34 {
sampleIsAnnexB = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sampleAnnexB is also getting set here. Would be good to consolidate AnnexB determination in one place if possible?

// Once we've started a picture, detect the next access-unit boundary.
if nal.NalUnitType < 32 {
// VCL: split when first_slice_segment_in_pic_flag starts a new picture.
if isFirstSlice, ok := h265FirstSliceInPic(nal.Data); ok && isFirstSlice {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be simplified a bit? looks like only the combination of firstInSlice: true && ok: false is the only one continuing. Can this be written as one check?

if isFirstSlice, ok := h265FirstSliceInPic(nal.Data); !ok || isFirstSlice

Did I get that logic right?

switch nal.NalUnitType {
case 40: // suffix SEI, ignore
continue
case 39, 32, 33, 34:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case different from default below? If not, can this just be made a comment and made let the default be the handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ur right, simplified

@chenosaurus chenosaurus marked this pull request as ready for review February 13, 2026 07:00
@chenosaurus chenosaurus requested a review from milos-lk February 13, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants