Skip to content

rtspv2 Client Incorrectly Sets IsKeyFrame=false for IDR Slices (NALU Type 5) when Using Length-Prefixed Output #116

@havenotfear

Description

@havenotfear

When using the rtspv2.Dial client to connect to an RTSP stream the av.Packet structs received from the RTSPClient.OutgoingPacketQueue consistently have IsKeyFrame set to false, even when the packet contains an H.264 IDR slice (NAL Unit Type 5).

SDP from Server:

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 0.0.0.0
t=0 0
m=video 0 RTP/AVP 96
a=control:trackID=0
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; profile-level-id=640016; sprop-parameter-sets=Z2QAFqy0BQHtCAAAAwAIAAADAPR4sXU=,aO88sA==

Observed Behavior:

Packets are received successfully via RTSPClient.OutgoingPacketQueue, but the IsKeyFrame field is always false.

Analysis & Evidence:

Further debugging reveals that the av.Packet.Data provided by vdk in this case is structured as:

  • Bytes 0-3: 4-byte Big Endian length of the following NAL unit.
  • Byte 4 onwards: The actual H.264 NAL unit data.

By inspecting packet.Data[4], we can correctly identify the NAL unit type. The logs below show examples where the NALU type at offset 4 is correctly identified as 1 (Non-IDR) or 5 (IDR), but vdk consistently reports vdk_IsKeyFrame: false.

Log Examples:

  • Non-Keyframe Packet (NALU Type 1 @ offset 4):
{"level":"info","ts":"2025-04-29T12:44:59.719Z","caller":"webrtc/stream.go:298","msg":"Raw Payload Start Hex","size":20,"hexData":"00000010419b8620d5fffedaa6580000"}
{"level":"info","ts":"2025-04-29T12:44:59.719Z","caller":"webrtc/stream.go:323","msg":"Received packet - VDK Analysis (Offset 4)","vdk_IsKeyFrame":false,"debug_IsMaybeKeyFrame":false,"debug_PayloadDesc":"Non-IDR Slice (Type 1 @ offset 4)","debug_RealNaluType":1,"DataSize":20}
  • Keyframe Packet (NALU Type 5 @ offset 4):
{"level":"info","ts":"2025-04-29T12:44:59.920Z","caller":"webrtc/stream.go:298","msg":"Raw Payload Start Hex","size":226,"hexData":"000000de65888201abffecffc255ffd8"}
{"level":"info","ts":"2025-04-29T12:44:59.922Z","caller":"webrtc/stream.go:323","msg":"Received packet - VDK Analysis (Offset 4)","vdk_IsKeyFrame":false,"debug_IsMaybeKeyFrame":true,"debug_PayloadDesc":"IDR Slice (Type 5 @ offset 4)","debug_RealNaluType":5,"DataSize":226}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions