The extraction and function of SPS and PPS in H264

Source: Internet
Author: User
Tags base64

Awesome video conferencing website: http://wmnmtm.blog.163.com/blog/#m =0

++++++++++++++++++++++++++++++++++++++++++++++++++++

http://wmnmtm.blog.163.com/blog/static/38245714201192491746701/

When using RTP to transmit H264, we need to use the SDP protocol description, two of them: Sequence Parameter Sets (SPS) and picture Parameter Set (PPS) need to be used, so where are these two items obtained? The answer is to get it from the H264 code stream. In the H264 stream, all are "0x00 0x00 0x01" or "0x00 0x00 0x00 0x01" as the start code, after the start code is found, the low 5 bits of the first byte after using the start code are judged to be 7 (SPS) or 8 (PPS) , and data[4] & 0x1f = 7 | | DATA[4] & 0x1f = 8. Then base64 code the acquired nal after the start code is removed, and the information obtained can be used for Sdp.sps and PPS to be separated by commas.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How to parse the SPS and PPS strings contained in the SDP H.264

Http://www.pernet.tv.sixxs.org/thread-109-1-1.html

The SPS and PPS strings of the H.264 in SDP contain the information parameters needed to initialize the H.264 decoder, including the profile,level used for encoding, the width and height of the image, the Deblock filter, and so on.
Since the SPS and PPS in SDP are BASE64 encoded forms, it is not easy to understand that the attachment has a tool software to parse SPS and PPS in the SDP.
The usage is to enter at the command line:
Spsparser sps.txt pps.txt output.txt

For example, the content in Sps.txt is:
z0lgfnofgle=
The contents of the Pps.txt are:
Am4wpia=

The result of the final resolution is:

Start Dumping SPS:
PROFILE_IDC = 66
Constrained_set0_flag = 1
Constrained_set1_flag = 1
Constrained_set2_flag = 1
Constrained_set3_flag = 0
LEVEL_IDC = 20
seq_parameter_set_id = 0
CHROMA_FORMAT_IDC = 1
BIT_DEPTH_LUMA_MINUS8 = 0
BIT_DEPTH_CHROMA_MINUS8 = 0
Seq_scaling_matrix_present_flag = 0
LOG2_MAX_FRAME_NUM_MINUS4 = 0
Pic_order_cnt_type = 2
LOG2_MAX_PIC_ORDER_CNT_LSB_MINUS4 = 0
Delta_pic_order_always_zero_flag = 0
Offset_for_non_ref_pic = 0
Offset_for_top_to_bottom_field = 0
num_ref_frames_in_pic_order_cnt_cycle = 0
Num_ref_frames = 1
Gaps_in_frame_num_value_allowed_flag = 0
PIC_WIDTH_IN_MBS_MINUS1 = 21
Pic_height_in_mbs_minus1 = 17
Frame_mbs_only_flag = 1
Mb_adaptive_frame_field_flag = 0
Direct_8x8_interence_flag = 0
Frame_cropping_flag = 0
Frame_cropping_rect_left_offset = 0
Frame_cropping_rect_right_offset = 0
Frame_cropping_rect_top_offset = 0
Frame_cropping_rect_bottom_offset = 0
Vui_parameters_present_flag = 0

Start Dumping PPS:
pic_parameter_set_id = 0
seq_parameter_set_id = 0
Entropy_coding_mode_flag = 0
Pic_order_present_flag = 0
NUM_SLICE_GROUPS_MINUS1 = 0
Slice_group_map_type = 0
NUM_REF_IDX_L0_ACTIVE_MINUS1 = 0
NUM_REF_IDX_L1_ACTIVE_MINUS1 = 0
Weighted_pref_flag = 0
WEIGHTED_BIPRED_IDC = 0
PIC_INIT_QP_MINUS26 = 0
PIC_INIT_QS_MINUS26 = 0
Chroma_qp_index_offset = 10
Deblocking_filter_control_present_flag = 1
Constrained_intra_pred_flag = 0
Redundant_pic_cnt_present_flag = 0
Transform_8x8_mode_flag = 0
Pic_scaling_matrix_present_flag = 0
Second_chroma_qp_index_offset = 10

/////////////////////////////////////////////////////////////////////////////////////////////////
Here we need to mention these two parameters in particular.
PIC_WIDTH_IN_MBS_MINUS1 = 21
Pic_height_in_mbs_minus1 = 17
Indicates the width and height of the image, minus 1 for the value of the macro block (16x16)
Therefore, the actual width is (21+1) *16 = 352
Spsparser.rar

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Http://krdai.info.sixxs.org/blog/mp4-sps-pps-data.html

A recent study of H264 Encode/decode is hoping to get h264 information out of Android's mediarecorder. The question now is how to get the SPS and the PPS. Since Mediarecorder was written into the MP4 file, he had to come and analyze the MP4 file format, and found it difficult to imagine. This is mainly part of the ISO/IEC 14496-15. In MP4 's file, find the AvcC string, and then the Avcdecoderconfigurationrecord. The format of Avcdecoderconfigurationrecord is as follows:

[CPP] view Plain copy aligned (8) class Avcdecoderconfigurationrecord {unsigned int (8) configurationversion      = 1;      unsigned int (8) avcprofileindication;      unsigned int (8) profile_compatibility; unsigned int (8) avclevelindication;

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.