Repository navigation
Fix H.264 SPS and SEI dropped as HEVC access unit delimiters - #2656
Merged
Merged
Conversation
AlexxIT
approved these changes
Nov 28, 2026
Owner
|
Thanks for the idea! I've refined it a bit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2655.
Problem
annexb.EncodeToAVCCdrops any NAL unit whose first byte matches the HEVC AUD mask,b & 0x7e == 35 << 1. On an H.264 stream that mask also matches two legal headers:0x47: SPS withnal_ref_idc = 20x46: SEI withnal_ref_idc = 2Losing the SPS means the RTSP SDP is published without
sprop-parameter-sets, and clients cannot decode the stream at all:Fix
The NAL unit is now checked once its size is known instead of looking only at its first byte. A HEVC AUD is always three bytes long (two header bytes plus the picture type) and has a non zero
nuh_temporal_id_plus1, which is what tells it apart from an H.264 SPS or SEI.Dropping a parameter set breaks the whole stream, while keeping an AUD is harmless, so the check is deliberately strict: when in doubt the NAL unit is kept.
Result with the stream from the issue
Before:
After:
Tests
Three new cases in
pkg/h264/annexb/annexb_test.go:TestH264SPSWithNalRefIDC2: the SPS and the PPS survive.TestH264SEIWithNalRefIDC2: the SEI survives.TestHEVCAUDIsStillDropped: a HEVC AUD is still removed.They fail on master and pass with this change. The existing HEVC cases (
TestFFmpegMPEGTSHEVC,TestReolink,TestDahua) keep passing, so AUD removal for HEVC sources is unchanged.go build ./...succeeds.go test ./...shows the same failures with and without this change (pkg/core,pkg/hap,pkg/ivideon,pkg/tuyado not compile, andinternal/ffmpegandinternal/streamsfail on this machine), so none of them is introduced here.The same code is present in the
devbranch, so the fix applies there too.