Skip to content

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
duiniuluantanqin:feature/fix_bug_parse_avc_bframe
Jul 10, 2025
Merged

Fix H.264 B-frame detection logic to comply with specification. v5.0.224 v6.0.169 v7.0.46#4414
winlinvip merged 5 commits intoossrs:developfrom
duiniuluantanqin:feature/fix_bug_parse_avc_bframe

Conversation

@duiniuluantanqin
Copy link
Copy Markdown
Member

@duiniuluantanqin duiniuluantanqin commented Jul 7, 2025

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

@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Jul 7, 2025
@winlinvip winlinvip changed the title fix bug for parse_avc_bframe Fix H.264 B-frame detection logic to comply with specification Jul 9, 2025
@winlinvip winlinvip changed the title Fix H.264 B-frame detection logic to comply with specification Fix H.264 B-frame detection logic to comply with specification. v5.0.224 v6.0.169 v7.0.46 Jul 10, 2025
@winlinvip winlinvip added the RefinedByAI Refined by AI/GPT. label Jul 10, 2025
@winlinvip winlinvip merged commit 6208b6f into ossrs:develop Jul 10, 2025
5 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

EnglishNative This issue is conveyed exclusively in English. RefinedByAI Refined by AI/GPT.

Development

Successfully merging this pull request may close these issues.

3 participants