0

I tried to Identify idr packet in c from h264 over rtp.

I follow this answer but I don't understand.

Do I need to search 00 00 01 or 00 00 00 01 and than 0x65 mean start code of idr?

Because I saw a table of all defined NALUs

Type Name

0 [unspecified]

1 Coded slice
2 Data Partition A

3 Data Partition B
4 Data Partition C

5 IDR (Instantaneous Decoding Refresh) Picture
6 SEI (Supplemental Enhancement Information)
7 SPS (Sequence Parameter Set)
8 PPS (Picture Parameter Set)
9 Access Unit Delimiter    10 EoS (End of Sequence)    11 EoS (End of Stream)    12 Filter Data 13-23 [extended] 24-31 [unspecified]

And this code that looking about another conditions (type=5 and more)

public static bool 
isH264iFrame(byte[] paket)
{
    int RTPHeaderBytes = 0;

    int fragment_type = paket[RTPHeaderBytes + 0] & 0x1F;
    int nal_type = paket[RTPHeaderBytes + 1] & 0x1F;
    int start_bit = paket[RTPHeaderBytes + 1] & 0x80;

    if (((fragment_type == 28 || fragment_type == 29) && nal_type == 5 && start_bit == 128) || fragment_type == 5)
    {
        return true;
    }

    return false;
}

So how do identify idr packet?

Community
  • 1
  • 1
Keystone
  • 165
  • 1
  • 9

1 Answers1

1

The code you posted does not cover all the cases. You should actually start by reading the rfc on RTP payload format for H.264. Depending on the RTP packetization the IDR can come in different RTP packet types:

  • Single nal unit packet
  • STAP-A/STAP-B packet
  • MTAP packet
  • FU-A/FU-B packet.

The code you posted actually handles FU-A/FU-B (via the (fragment_type == 28 || fragment_type == 29) && nal_type == 5 && start_bit == 128) check) and single nal unit case (via the fragment_type == 5 check). RTP actually does not use the 00 00 00 01 and 00 00 01 prefixes, those are used in Annex B format. So you just need to be able to determine the type of the packet and contained NAL unit type from the RTP header. How to do that should be clear after reading the RFC.

Community
  • 1
  • 1
Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71
  • thank you. I looking for understand the h264 data that wrap with rtp. Is in h264 data is there sequence number and/timestamp for each packet or those data only in rtp data? – Keystone Jul 08 '19 at 21:03