Fix H.264 B-frame detection logic to comply with specification. v5.0.224 v6.0.169 v7.0.46#4414
Merged
winlinvip merged 5 commits intoossrs:developfrom Jul 10, 2025
Conversation
suzp1984
approved these changes
Jul 7, 2025
winlinvip
approved these changes
Jul 9, 2025
winlinvip
added a commit
that referenced
this pull request
Jul 10, 2025
…224 (#4414) For H.264, only when the NAL Type is 1, 2, 3, or 4 is it possible for B-frames to be present; that is, non-IDR pictures and slice data. The current `SrsVideoFrame::parse_avc_bframe()` function uses incorrect logic to determine if a NALU can contain B-frames. The original implementation only checked for specific NALU types (IDR, SPS, PPS) to mark as non-B-frames, but this approach misses many other NALU types that cannot contain B-frames according to the H.264 specification. According to H.264 specification (ISO_IEC_14496-10-AVC-2012.pdf, Table 7-1), B-frames can **only** exist in these specific NALU types: - Type 1: Non-IDR coded slice (`SrsAvcNaluTypeNonIDR`) - Type 2: Coded slice data partition A (`SrsAvcNaluTypeDataPartitionA`) - Type 3: Coded slice data partition B (`SrsAvcNaluTypeDataPartitionB`) - Type 4: Coded slice data partition C (`SrsAvcNaluTypeDataPartitionC`) All other NALU types (IDR=5, SEI=6, SPS=7, PPS=8, AUD=9, etc.) cannot contain B-frames by definition. --------- Co-authored-by: Jacob Su <suzp1984@gmail.com> Co-authored-by: winlin <winlinvip@gmail.com>
winlinvip
added a commit
that referenced
this pull request
Jul 10, 2025
…169 (#4414) For H.264, only when the NAL Type is 1, 2, 3, or 4 is it possible for B-frames to be present; that is, non-IDR pictures and slice data. The current `SrsVideoFrame::parse_avc_bframe()` function uses incorrect logic to determine if a NALU can contain B-frames. The original implementation only checked for specific NALU types (IDR, SPS, PPS) to mark as non-B-frames, but this approach misses many other NALU types that cannot contain B-frames according to the H.264 specification. According to H.264 specification (ISO_IEC_14496-10-AVC-2012.pdf, Table 7-1), B-frames can **only** exist in these specific NALU types: - Type 1: Non-IDR coded slice (`SrsAvcNaluTypeNonIDR`) - Type 2: Coded slice data partition A (`SrsAvcNaluTypeDataPartitionA`) - Type 3: Coded slice data partition B (`SrsAvcNaluTypeDataPartitionB`) - Type 4: Coded slice data partition C (`SrsAvcNaluTypeDataPartitionC`) All other NALU types (IDR=5, SEI=6, SPS=7, PPS=8, AUD=9, etc.) cannot contain B-frames by definition. --------- Co-authored-by: Jacob Su <suzp1984@gmail.com> Co-authored-by: winlin <winlinvip@gmail.com>
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.
For H.264, only when the NAL Type is 1, 2, 3, or 4 is it possible for B-frames to be present; that is, non-IDR pictures and slice data.
The current
SrsVideoFrame::parse_avc_bframe()function uses incorrect logic to determine if a NALU can contain B-frames. The original implementation only checked for specific NALU types (IDR, SPS, PPS) to mark as non-B-frames, but this approach misses many other NALU types that cannot contain B-frames according to the H.264 specification.According to H.264 specification (ISO_IEC_14496-10-AVC-2012.pdf, Table 7-1), B-frames can only exist in these specific NALU types:
SrsAvcNaluTypeNonIDR)SrsAvcNaluTypeDataPartitionA)SrsAvcNaluTypeDataPartitionB)SrsAvcNaluTypeDataPartitionC)All other NALU types (IDR=5, SEI=6, SPS=7, PPS=8, AUD=9, etc.) cannot contain B-frames by definition.
Co-authored-by: Jacob Su suzp1984@gmail.com