Analysis of h264 RTP Header

Source: Internet
Author: User

H264 RTP Header Parsing ProcessCombined with naldecoder. c Analysis

Protocol Analysis: Each RTP datagram consists of the header and payload. The meaning of the first 12 bytes of the header is fixed, the load can be audio or video data.

 
The parameter set of the active sequence remains unchanged in the same encoding video sequence, and the parameter set of the active image remains unchanged in the same encoding image.

 

H.264
The encoder must set the nri value (subclause 7.4.1) According to H.264 specifications when the range of nal_unit_type is 1 to 12. In particular,
H.264 requires that the nri value of NAL units whose nal_unit_type is 6, 9, 10, 11, and 12 be 0.

 

 
For NAL units whose nal_unit_type is equal to 264 (indicating an ordered parameter set or image parameter set), H.264 Encoder should set NRI to 11 (binary format)

For the nal unit of the main encoded image whose nal_unit_type is equal to 5 (indicating that the encoded image belongs to an IDR image), the H.264 Encoder should set NRI to 11.

 

Open the h264 file and read the stream

Locate NALU Peugeot startcode, that is, 00 00 01 or 00 00 01 string

Determine the Data Segment Size of the ualu unit (the maximum data size that UDP can send at a time is 64 KB)

Which sending method (single sending, aggregate sending, and multipart sending) is used)

If the ualu data is less than 1500 (set by yourself), use a single package to send:

Fill the RTP Header (12 bytes), payload (7 bit): 96 marker (1 bit): 0 seq_no (16 bit): Random timestamp (32 bit ):

13th bytes fill the NALU header (the next byte of startcode ),

If the NALU data is greater than 1500, use multipart transmission: (the first RTP, the middle RTP, And the last RTP)

Fill the RTP Header, similar to sending a single packet, and send the entire nalu, timestamp is added only once.

The difference is that fill in Fu indicator in 13th bytes, and its type must be 28; fill in Fu header in 14th bytes,

    • The first RTP: 13th byte is Fu indicator, and its type is set to 28; 14th byte is Fu header, S: e: r =, followed by video data.
    • In the middle, RTP: 13th byte is Fu indicator, and its type is set to 28; 14th byte is Fu header, S: e: r = 0: 0, followed by video data.
    • The last RTP: 13th byte is Fu indicator, and its type is set to 28; 14th byte is Fu header, S: e: r =, followed by video data.

NALU data is very small and encapsulated in combination:

Combined encapsulation: NALU payload = NALU payload size + NALU payload header + NALU payload data

If a NALU of H.264 is like this:

[00 00 00 01 67 42 A0 1E 23 56 0e 2f...] [00 00 00 01 67 42 A0 1E 23 56 0e 2f...]

This is a serial parameter set nal unit. [00 00 01] is the start code of four bytes, 67 is the NALU header, and the data starting from 42 is the content of NALU.

The RTP package may be encapsulated as follows:

[RTP Header] [78, STAP-A nal HDR, one byte] [length, two bytes] [67 42 A0 1E 23 56 0e 2f...] [length, two bytes] [67 42 A0 1E 23 56 0e 2f...]

Several Types mixed up by reading RFC 3984:

    • PT load type payload type (PT) in RTP: 7 bits -- send h264 video, which is invariably set to 96
    • The type in NALU describes the attributes of nalu, for example, 7 indicates the sequence parameter set, and 8 indicates the image parameter set.
    • Type after RTP, that is, the type starting from 13 bytes. the type of a single package is the same as the type in NALU. the type of the Fu package is set to 28;

Refer:

Http://bbs.chinavideo.org/viewthread.php? Tid = 2451 & Highlight = RTP % 2bh264

 

Http://www.cppblog.com/czanyou/archive/2010/02/09/67940.html#107573

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.