// 【h264编码出的NALU规律】
// 第一帧 SPS【0 0 0 1 0x67】 PPS【0 0 0 1 0x68】 SEI【0 0 0 1 0x6】 IDR【0 0 0 1 0x65】
// p帧      P【0 0 0 1 0x61】
// I帧    SPS【0 0 0 1 0x67】 PPS【0 0 0 1 0x68】 IDR【0 0 0 1 0x65】
// 【mp4v2封装函数MP4WriteSample】
// 此函数接收I/P nalu,该nalu需要用4字节的数据大小头替换原有的起始头,并且数据大小为big-endian格式

示例文件下载地址:“NALU中SPS、PPS、SEI、IDR、P帧标识

H.264码流第一个 NALU 是 SPS(序列参数集Sequence Parameter Set)
对应H264标准文档 7.3.2.1 序列参数集的语法进行解析

SPS参数解析// fill sps with content of p
  1. int InterpretSPS (VideoParameters *p_Vid, DataPartition *p, seq_parameter_set_rbsp_t *sps)
  2. {
  3. unsigned i;
  4. unsigned n_ScalingList;
  5. int reserved_zero;
  6. Bitstream *s = p->bitstream;
  7. assert (p != NULL);
  8. assert (p->bitstream != NULL);
  9. assert (p->bitstream->streamBuffer != 0);
  10. assert (sps != NULL);
  11. p_Dec->UsedBits = 0;
  12. sps->profile_idc                            = u_v  (8, "SPS: profile_idc"                           , s);
  13. if ((sps->profile_idc!=BASELINE       ) &&
  14. (sps->profile_idc!=MAIN           ) &&
  15. (sps->profile_idc!=EXTENDED       ) &&
  16. (sps->profile_idc!=FREXT_HP       ) &&
  17. (sps->profile_idc!=FREXT_Hi10P    ) &&
  18. (sps->profile_idc!=FREXT_Hi422    ) &&
  19. (sps->profile_idc!=FREXT_Hi444    ) &&
  20. (sps->profile_idc!=FREXT_CAVLC444 )
  21. #if (MVC_EXTENSION_ENABLE)
  22. && (sps->profile_idc!=MVC_HIGH)
  23. && (sps->profile_idc!=STEREO_HIGH)
  24. #endif
  25. )
  26. {
  27. printf("Invalid Profile IDC (%d) encountered. /n", sps->profile_idc);
  28. return p_Dec->UsedBits;
  29. }
  30. sps->constrained_set0_flag                  = u_1  (   "SPS: constrained_set0_flag"                 , s);
  31. sps->constrained_set1_flag                  = u_1  (   "SPS: constrained_set1_flag"                 , s);
  32. sps->constrained_set2_flag                  = u_1  (   "SPS: constrained_set2_flag"                 , s);
  33. sps->constrained_set3_flag                  = u_1  (   "SPS: constrained_set3_flag"                 , s);
  34. #if (MVC_EXTENSION_ENABLE)
  35. sps->constrained_set4_flag                  = u_1  (   "SPS: constrained_set4_flag"                 , s);
  36. reserved_zero                               = u_v  (3, "SPS: reserved_zero_3bits"                   , s);
  37. #else
  38. reserved_zero                               = u_v  (4, "SPS: reserved_zero_4bits"                   , s);
  39. #endif
  40. assert (reserved_zero==0);
  41. sps->level_idc                              = u_v  (8, "SPS: level_idc"                             , s);
  42. sps->seq_parameter_set_id                   = ue_v ("SPS: seq_parameter_set_id"                     , s);
  43. // Fidelity Range Extensions stuff
  44. sps->chroma_format_idc = 1;
  45. sps->bit_depth_luma_minus8   = 0;
  46. sps->bit_depth_chroma_minus8 = 0;
  47. p_Vid->lossless_qpprime_flag   = 0;
  48. sps->separate_colour_plane_flag = 0;
  49. if((sps->profile_idc==FREXT_HP   ) ||
  50. (sps->profile_idc==FREXT_Hi10P) ||
  51. (sps->profile_idc==FREXT_Hi422) ||
  52. (sps->profile_idc==FREXT_Hi444) ||
  53. (sps->profile_idc==FREXT_CAVLC444)
  54. #if (MVC_EXTENSION_ENABLE)
  55. || (sps->profile_idc==MVC_HIGH)
  56. || (sps->profile_idc==STEREO_HIGH)
  57. #endif
  58. )
  59. {
  60. sps->chroma_format_idc                      = ue_v ("SPS: chroma_format_idc"                       , s);
  61. if(sps->chroma_format_idc == YUV444)
  62. {
  63. sps->separate_colour_plane_flag           = u_1  ("SPS: separate_colour_plane_flag"              , s);
  64. }
  65. sps->bit_depth_luma_minus8                  = ue_v ("SPS: bit_depth_luma_minus8"                   , s);
  66. sps->bit_depth_chroma_minus8                = ue_v ("SPS: bit_depth_chroma_minus8"                 , s);
  67. //checking;
  68. if((sps->bit_depth_luma_minus8+8 > sizeof(imgpel)*8) || (sps->bit_depth_chroma_minus8+8> sizeof(imgpel)*8))
  69. error ("Source picture has higher bit depth than imgpel data type. /nPlease recompile with larger data type for imgpel.", 500);
  70. p_Vid->lossless_qpprime_flag                  = u_1  ("SPS: lossless_qpprime_y_zero_flag"            , s);
  71. sps->seq_scaling_matrix_present_flag        = u_1  (   "SPS: seq_scaling_matrix_present_flag"       , s);
  72. if(sps->seq_scaling_matrix_present_flag)
  73. {
  74. n_ScalingList = (sps->chroma_format_idc != YUV444) ? 8 : 12;
  75. for(i=0; iseq_scaling_list_present_flag[i]   = u_1  (   "SPS: seq_scaling_list_present_flag"         , s);
  76. if(sps->seq_scaling_list_present_flag[i])
  77. {
  78. if(i<6) scaling_list="">ScalingList4x4[i], 16, &sps->UseDefaultScalingMatrix4x4Flag[i], s);
  79. else
  80. Scaling_List(sps->ScalingList8x8[i-6], 64, &sps->UseDefaultScalingMatrix8x8Flag[i-6], s);
  81. }
  82. }
  83. }
  84. }
  85. sps->log2_max_frame_num_minus4              = ue_v ("SPS: log2_max_frame_num_minus4"                , s);
  86. sps->pic_order_cnt_type                     = ue_v ("SPS: pic_order_cnt_type"                       , s);
  87. if (sps->pic_order_cnt_type == 0)
  88. sps->log2_max_pic_order_cnt_lsb_minus4 = ue_v ("SPS: log2_max_pic_order_cnt_lsb_minus4"           , s);
  89. else if (sps->pic_order_cnt_type == 1)
  90. {
  91. sps->delta_pic_order_always_zero_flag      = u_1  ("SPS: delta_pic_order_always_zero_flag"       , s);
  92. sps->offset_for_non_ref_pic                = se_v ("SPS: offset_for_non_ref_pic"                 , s);
  93. sps->offset_for_top_to_bottom_field        = se_v ("SPS: offset_for_top_to_bottom_field"         , s);
  94. sps->num_ref_frames_in_pic_order_cnt_cycle = ue_v ("SPS: num_ref_frames_in_pic_order_cnt_cycle"  , s);
  95. for(i=0; inum_ref_frames_in_pic_order_cnt_cycle; i++)
  96. sps->offset_for_ref_frame[i]               = se_v ("SPS: offset_for_ref_frame[i]"              , s);
  97. }
  98. sps->num_ref_frames                        = ue_v ("SPS: num_ref_frames"                         , s);
  99. sps->gaps_in_frame_num_value_allowed_flag  = u_1  ("SPS: gaps_in_frame_num_value_allowed_flag"   , s);
  100. sps->pic_width_in_mbs_minus1               = ue_v ("SPS: pic_width_in_mbs_minus1"                , s);
  101. sps->pic_height_in_map_units_minus1        = ue_v ("SPS: pic_height_in_map_units_minus1"         , s);
  102. sps->frame_mbs_only_flag                   = u_1  ("SPS: frame_mbs_only_flag"                    , s);
  103. if (!sps->frame_mbs_only_flag)
  104. {
  105. sps->mb_adaptive_frame_field_flag        = u_1  ("SPS: mb_adaptive_frame_field_flag"           , s);
  106. }
  107. sps->direct_8x8_inference_flag             = u_1  ("SPS: direct_8x8_inference_flag"              , s);
  108. sps->frame_cropping_flag                   = u_1  ("SPS: frame_cropping_flag"                    , s);
  109. if (sps->frame_cropping_flag)
  110. {
  111. sps->frame_cropping_rect_left_offset      = ue_v ("SPS: frame_cropping_rect_left_offset"           , s);
  112. sps->frame_cropping_rect_right_offset     = ue_v ("SPS: frame_cropping_rect_right_offset"          , s);
  113. sps->frame_cropping_rect_top_offset       = ue_v ("SPS: frame_cropping_rect_top_offset"            , s);
  114. sps->frame_cropping_rect_bottom_offset    = ue_v ("SPS: frame_cropping_rect_bottom_offset"         , s);
  115. }
  116. sps->vui_parameters_present_flag           = (Boolean) u_1  ("SPS: vui_parameters_present_flag"      , s);
  117. InitVUI(sps);
  118. ReadVUI(p, sps);
  119. sps->Valid = TRUE;
  120. return p_Dec->UsedBits;
  121. }

H.264码流第二个 NALU 是 PPS(图像参数集Picture Parameter Set)
对应H264标准文档 7.3.2.2 序列参数集的语法进行解析

PPS参数解析
  1. int InterpretPPS (VideoParameters *p_Vid, DataPartition *p, pic_parameter_set_rbsp_t *pps)
  2. {
  3. unsigned i;
  4. unsigned n_ScalingList;
  5. int chroma_format_idc;
  6. int NumberBitsPerSliceGroupId;
  7. Bitstream *s = p->bitstream;
  8. assert (p != NULL);
  9. assert (p->bitstream != NULL);
  10. assert (p->bitstream->streamBuffer != 0);
  11. assert (pps != NULL);
  12. p_Dec->UsedBits = 0;
  13. pps->pic_parameter_set_id                  = ue_v ("PPS: pic_parameter_set_id"                   , s);
  14. pps->seq_parameter_set_id                  = ue_v ("PPS: seq_parameter_set_id"                   , s);
  15. pps->entropy_coding_mode_flag              = u_1  ("PPS: entropy_coding_mode_flag"               , s);
  16. //! Note: as per JVT-F078 the following bit is unconditional.  If F078 is not accepted, then
  17. //! one has to fetch the correct SPS to check whether the bit is present (hopefully there is
  18. //! no consistency problem :-(
  19. //! The current encoder code handles this in the same way.  When you change this, don't forget
  20. //! the encoder!  StW, 12/8/02
  21. pps->bottom_field_pic_order_in_frame_present_flag                = u_1  ("PPS: bottom_field_pic_order_in_frame_present_flag"                 , s);
  22. pps->num_slice_groups_minus1               = ue_v ("PPS: num_slice_groups_minus1"                , s);
  23. // FMO stuff begins here
  24. if (pps->num_slice_groups_minus1 > 0)
  25. {
  26. pps->slice_group_map_type               = ue_v ("PPS: slice_group_map_type"                , s);
  27. if (pps->slice_group_map_type == 0)
  28. {
  29. for (i=0; i<=pps->num_slice_groups_minus1; i++)
  30. pps->run_length_minus1 [i]                  = ue_v ("PPS: run_length_minus1 [i]"              , s);
  31. }
  32. else if (pps->slice_group_map_type == 2)
  33. {
  34. for (i=0; inum_slice_groups_minus1; i++)
  35. {
  36. //! JVT-F078: avoid reference of SPS by using ue(v) instead of u(v)
  37. pps->top_left [i]                          = ue_v ("PPS: top_left [i]"                        , s);
  38. pps->bottom_right [i]                      = ue_v ("PPS: bottom_right [i]"                    , s);
  39. }
  40. }
  41. else if (pps->slice_group_map_type == 3 ||
  42. pps->slice_group_map_type == 4 ||
  43. pps->slice_group_map_type == 5)
  44. {
  45. pps->slice_group_change_direction_flag     = u_1  ("PPS: slice_group_change_direction_flag"      , s);
  46. pps->slice_group_change_rate_minus1        = ue_v ("PPS: slice_group_change_rate_minus1"         , s);
  47. }
  48. else if (pps->slice_group_map_type == 6)
  49. {
  50. if (pps->num_slice_groups_minus1+1 >4)
  51. NumberBitsPerSliceGroupId = 3;
  52. else if (pps->num_slice_groups_minus1+1 > 2)
  53. NumberBitsPerSliceGroupId = 2;
  54. else
  55. NumberBitsPerSliceGroupId = 1;
  56. pps->pic_size_in_map_units_minus1      = ue_v ("PPS: pic_size_in_map_units_minus1"               , s);
  57. if ((pps->slice_group_id = calloc (pps->pic_size_in_map_units_minus1+1, 1)) == NULL)
  58. no_mem_exit ("InterpretPPS: slice_group_id");
  59. for (i=0; i<=pps->pic_size_in_map_units_minus1; i++)
  60. pps->slice_group_id[i] = (byte) u_v (NumberBitsPerSliceGroupId, "slice_group_id[i]", s);
  61. }
  62. }
  63. // End of FMO stuff
  64. pps->num_ref_idx_l0_active_minus1          = ue_v ("PPS: num_ref_idx_l0_active_minus1"           , s);
  65. pps->num_ref_idx_l1_active_minus1          = ue_v ("PPS: num_ref_idx_l1_active_minus1"           , s);
  66. pps->weighted_pred_flag                    = u_1  ("PPS: weighted_pred_flag"                     , s);
  67. pps->weighted_bipred_idc                   = u_v  ( 2, "PPS: weighted_bipred_idc"                , s);
  68. pps->pic_init_qp_minus26                   = se_v ("PPS: pic_init_qp_minus26"                    , s);
  69. pps->pic_init_qs_minus26                   = se_v ("PPS: pic_init_qs_minus26"                    , s);
  70. pps->chroma_qp_index_offset                = se_v ("PPS: chroma_qp_index_offset"                 , s);
  71. pps->deblocking_filter_control_present_flag = u_1 ("PPS: deblocking_filter_control_present_flag" , s);
  72. pps->constrained_intra_pred_flag           = u_1  ("PPS: constrained_intra_pred_flag"            , s);
  73. pps->redundant_pic_cnt_present_flag        = u_1  ("PPS: redundant_pic_cnt_present_flag"         , s);
  74. if(more_rbsp_data(s->streamBuffer, s->frame_bitoffset,s->bitstream_length)) // more_data_in_rbsp()
  75. {
  76. //Fidelity Range Extensions Stuff
  77. pps->transform_8x8_mode_flag           = u_1  ("PPS: transform_8x8_mode_flag"                , s);
  78. pps->pic_scaling_matrix_present_flag   =  u_1  ("PPS: pic_scaling_matrix_present_flag"        , s);
  79. if(pps->pic_scaling_matrix_present_flag)
  80. {
  81. chroma_format_idc = p_Vid->SeqParSet[pps->seq_parameter_set_id].chroma_format_idc;
  82. n_ScalingList = 6 + ((chroma_format_idc != YUV444) ? 2 : 6) * pps->transform_8x8_mode_flag;
  83. for(i=0; ipic_scaling_list_present_flag[i]= u_1  ("PPS: pic_scaling_list_present_flag"          , s);
  84. if(pps->pic_scaling_list_present_flag[i])
  85. {
  86. if(i<6) scaling_list="">ScalingList4x4[i], 16, &pps->UseDefaultScalingMatrix4x4Flag[i], s);
  87. else
  88. Scaling_List(pps->ScalingList8x8[i-6], 64, &pps->UseDefaultScalingMatrix8x8Flag[i-6], s);
  89. }
  90. }
  91. }
  92. pps->second_chroma_qp_index_offset      = se_v ("PPS: second_chroma_qp_index_offset"          , s);
  93. }
  94. else
  95. {
  96. pps->second_chroma_qp_index_offset      = pps->chroma_qp_index_offset;
  97. }
  98. pps->Valid = TRUE;
  99. return p_Dec->UsedBits;
  100. }

H.264码流第三个 NALU 是 IDR(即时解码器刷新)
对应H264标准文档 7.3.3 序列参数集的语法进行解析

IDR参数解析
  1. case NALU_TYPE_IDR:
  2. img->idr_flag = (nalu->nal_unit_type == NALU_TYPE_IDR);
  3. img->nal_reference_idc = nalu->nal_reference_idc;
  4. img->disposable_flag = (nalu->nal_reference_idc == NALU_PRIORITY_DISPOSABLE);
  5. currSlice->dp_mode = PAR_DP_1;   //++ dp_mode:数据分割模式;PAR_DP_1=0:没有数据分割
  6. currSlice->max_part_nr = 1;
  7. currSlice->ei_flag = 0;  //++ 该处赋值直接影响decode_slice()函数中对decode_one_slice()函数的调用
  8. //++ 该值不为0,表明当前片出错,解码程序将忽略当前片的解码过程,而使用错误隐藏
  9. currStream = currSlice->partArr[0].bitstream;
  10. currStream->ei_flag = 0; //++ 此处的赋值为最终赋值,以后不再改变。该值将对每个宏块的ei_flag产生影响
  11. //++ 参见macroblock.c文件read_one_macroblock()函数的如下语句:
  12. //++        :if(!dP->bitstream->ei_flag)      :currMB->ei_flag = 0;
  13. //++ 该值还在macroblock.c文件if(IS_INTRA (currMB) && dP->bitstream->ei_flag && img->number)中用到
  14. currStream->frame_bitoffset = currStream->read_len = 0;
  15. memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
  16. currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
  17. // Some syntax of the Slice Header depends on the parameter set, which depends on
  18. // the parameter set ID of the SLice header.  Hence, read the pic_parameter_set_id
  19. // of the slice header first, then setup the active parameter sets, and then read
  20. // the rest of the slice header
  21. BitsUsedByHeader = FirstPartOfSliceHeader();    //++ 参见标准7.3.3
  22. UseParameterSet (currSlice->pic_parameter_set_id);
  23. BitsUsedByHeader+= RestOfSliceHeader ();    //++ 参见标准7.3.3
  24. //++ BitsUsedByHeader在程序中没有实际用处,而且BitsUsedByHeader+= RestOfSliceHeader ()
  25. //++ 重复计算了FirstPartOfSliceHeader()所用到的比特数。因为在FirstPartOfSliceHeader()
  26. //++ 之后,变量UsedBits值并未被置零就代入RestOfSliceHeader()运算,从而RestOfSliceHeader ()
  27. //++ 在返回时,BitsUsedByHeader+= RestOfSliceHeader()多加了一个BitsUsedByHeader值
  28. FmoInit (active_pps, active_sps);
  29. if(is_new_picture())
  30. {
  31. init_picture(img, input);
  32. current_header = SOP;
  33. //check zero_byte if it is also the first NAL unit in the access unit
  34. CheckZeroByteVCL(nalu, &ret);
  35. }
  36. else
  37. current_header = SOS;
  38. init_lists(img->type, img->currentSlice->structure);
  39. reorder_lists (img->type, img->currentSlice);
  40. if (img->structure==FRAME)
  41. {
  42. init_mbaff_lists();
  43. }
  44. /*        if (img->frame_num==1) // write a reference list
  45. {
  46. count ++;
  47. if (count==1)
  48. for (i=0; i
  49. // From here on, active_sps, active_pps and the slice header are valid
  50. if (img->MbaffFrameFlag)
  51. img->current_mb_nr = currSlice->start_mb_nr << 1="" style="color: #0000ff">else
  52. img->current_mb_nr = currSlice->start_mb_nr;
  53. if (active_pps->entropy_coding_mode_flag)
  54. {
  55. int ByteStartPosition = currStream->frame_bitoffset/8;
  56. if (currStream->frame_bitoffset%8 != 0)
  57. {
  58. ByteStartPosition++;
  59. }
  60. arideco_start_decoding (&currSlice->partArr[0].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len, img->type);
  61. }
  62. // printf ("read_new_slice: returning %s/n", current_header == SOP?"SOP":"SOS");
  63. FreeNALU(nalu);
  64. return current_header;
  65. break;
  66. case NALU_TYPE_DPA:
  67. //! The state machine here should follow the same ideas as the old readSliceRTP()
  68. //! basically:
  69. //! work on DPA (as above)
  70. //! read and process all following SEI/SPS/PPS/PD/Filler NALUs
  71. //! if next video NALU is dpB,
  72. //!   then read and check whether it belongs to DPA, if yes, use it
  73. //! else
  74. //!   ;   // nothing
  75. //! read and process all following SEI/SPS/PPS/PD/Filler NALUs
  76. //! if next video NALU is dpC
  77. //!   then read and check whether it belongs to DPA (and DPB, if present), if yes, use it, done
  78. //! else
  79. //!   use the DPA (and the DPB if present)
  80. /*
  81. LC: inserting the code related to DP processing, mainly copying some of the parts
  82. related to NALU_TYPE_SLICE, NALU_TYPE_IDR.
  83. */
  84. if(expected_slice_type != NALU_TYPE_DPA)
  85. {
  86. /* oops... we found the next slice, go back! */
  87. fseek(bits, ftell_position, SEEK_SET);
  88. FreeNALU(nalu);
  89. return current_header;
  90. }
  91. img->idr_flag          = (nalu->nal_unit_type == NALU_TYPE_IDR);
  92. img->nal_reference_idc = nalu->nal_reference_idc;
  93. img->disposable_flag   = (nalu->nal_reference_idc == NALU_PRIORITY_DISPOSABLE);
  94. currSlice->dp_mode     = PAR_DP_3;
  95. currSlice->max_part_nr = 3;
  96. currSlice->ei_flag     = 0;
  97. currStream             = currSlice->partArr[0].bitstream;
  98. currStream->ei_flag    = 0;
  99. currStream->frame_bitoffset = currStream->read_len = 0;
  100. memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
  101. currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);    //++ 剔除停止比特和填充比特
  102. BitsUsedByHeader     = FirstPartOfSliceHeader();
  103. UseParameterSet (currSlice->pic_parameter_set_id);
  104. BitsUsedByHeader    += RestOfSliceHeader ();
  105. FmoInit (active_pps, active_sps);
  106. if(is_new_picture())
  107. {
  108. init_picture(img, input);
  109. current_header = SOP;
  110. CheckZeroByteVCL(nalu, &ret);
  111. }
  112. else
  113. current_header = SOS;
  114. init_lists(img->type, img->currentSlice->structure);
  115. reorder_lists (img->type, img->currentSlice);
  116. if (img->structure==FRAME)
  117. {
  118. init_mbaff_lists();
  119. }
  120. // From here on, active_sps, active_pps and the slice header are valid
  121. if (img->MbaffFrameFlag)
  122. img->current_mb_nr = currSlice->start_mb_nr << 1="" style="color: #0000ff">else
  123. img->current_mb_nr = currSlice->start_mb_nr;
  124. /*
  125. LC:
  126. Now I need to read the slice ID, which depends on the value of
  127. redundant_pic_cnt_present_flag (pag.49).
  128. */
  129. slice_id_a  = ue_v("NALU:SLICE_A slice_idr", currStream);
  130. if (active_pps->entropy_coding_mode_flag)
  131. {
  132. int ByteStartPosition = currStream->frame_bitoffset/8;
  133. if (currStream->frame_bitoffset%8 != 0)
  134. {
  135. ByteStartPosition++;
  136. }
  137. arideco_start_decoding (&currSlice->partArr[0].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len, img->type);
  138. }
  139. // printf ("read_new_slice: returning %s/n", current_header == SOP?"SOP":"SOS");
  140. break;
  141. case NALU_TYPE_DPB:
  142. /* LC: inserting the code related to DP processing */
  143. currStream             = currSlice->partArr[1].bitstream;
  144. currStream->ei_flag    = 0;
  145. currStream->frame_bitoffset = currStream->read_len = 0;
  146. memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
  147. currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
  148. slice_id_b  = ue_v("NALU:SLICE_B slice_idr", currStream);
  149. if (active_pps->redundant_pic_cnt_present_flag)
  150. redundant_pic_cnt_b = ue_v("NALU:SLICE_B redudand_pic_cnt", currStream);
  151. else
  152. redundant_pic_cnt_b = 0;
  153. /*  LC: Initializing CABAC for the current data stream. */
  154. if (active_pps->entropy_coding_mode_flag)
  155. {
  156. int ByteStartPosition = currStream->frame_bitoffset/8;
  157. if (currStream->frame_bitoffset % 8 != 0)
  158. ByteStartPosition++;
  159. arideco_start_decoding (&currSlice->partArr[1].de_cabac, currStream->streamBuffer,
  160. ByteStartPosition, &currStream->read_len, img->type);
  161. }
  162. /* LC: resilience code to be inserted */
  163. /*         FreeNALU(nalu); */
  164. /*         return current_header; */
  165. break;

IDR参数解析/*!
  1. <pre name="code" class="cpp"> ************************************************************************
  2. * /brief
  3. *    read the first part of the header (only the pic_parameter_set_id)
  4. * /return
  5. *    Length of the first part of the slice header (in bits)
  6. ************************************************************************
  7. */
  8. //++ 参见标准7.3.3
  9. int FirstPartOfSliceHeader()
  10. {
  11. Slice *currSlice = img->currentSlice;
  12. int dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER];
  13. DataPartition *partition = &(currSlice->partArr[dP_nr]);
  14. Bitstream *currStream = partition->bitstream;
  15. int tmp;
  16. UsedBits= partition->bitstream->frame_bitoffset; // was hardcoded to 31 for previous start-code. This is better.
  17. // Get first_mb_in_slice
  18. currSlice->start_mb_nr = ue_v ("SH: first_mb_in_slice", currStream);
  19. tmp = ue_v ("SH: slice_type", currStream);
  20. if (tmp>4) tmp -=5;
  21. img->type = currSlice->picture_type = (SliceType) tmp;
  22. currSlice->pic_parameter_set_id = ue_v ("SH: pic_parameter_set_id", currStream);
  23. return UsedBits;
  24. }
  25. </pre><br><br>

嵌入式 H264参数语法文档: SPS、PPS、IDR以及NALU编码规律的更多相关文章

  1. Markdown 语法文档

    Markdown 语法文档 前言 Markdown 是一种轻量级标记语言,创始人为約翰・格魯伯(英语:John Gruber); 它允许人们 "使用易读易写的纯文本格式编写文档,然后转换成有 ...

  2. Smali 语法文档

    可以选择保存成pdf格式,查询起来挺方便的 if v0==0 go cond_0 if-eqz v0, :cond_0   if v0!=0 go cond_0 if-nez v0, :cond_0 ...

  3. SQL 进阶视频课程。Udacity: Intro to Relational Databases和 PostgreSQL语法文档。

    Udacity: Intro to Relational Databases The syntax of the select statement with a where clause: selec ...

  4. 嵌入式 H264中的SPS、PPS提取与作用

    使用RTP传输H264的时候,需要用到sdp协议描述,其中有两项:Sequence Parameter Sets (SPS) 和Picture Parameter Set (PPS)需要用到,那么这两 ...

  5. 嵌入式 H264—MP4格式及在MP4文件中提取H264的SPS、PPS及码流

    一.MP4格式基本概念 MP4格式对应标准MPEG-4标准(ISO/IEC14496) 二.MP4封装格式核心概念 1  MP4封装格式对应标准为 ISO/IEC 14496-12(信息技术 视听对象 ...

  6. H264码流中SPS PPS详解<转>

    转载地址:https://zhuanlan.zhihu.com/p/27896239 1 SPS和PPS从何处而来? 2 SPS和PPS中的每个参数起什么作用? 3 如何解析SDP中包含的H.264的 ...

  7. 学习h264 的语法规则,如何才能看懂H264 的官方文档

    1. 今天想查h264 的帧率,查找资料如下: 首先要解析sps,得到两个关键的数值: num_units_in_tick, time_scale fps=time_scale/num_units_i ...

  8. select2 api参数中文文档

    select2 api参数的文档   具体参数可以参考一下: 参数 类型 描述 Width 字符串 控制 宽度 样式属性的Select2容器div minimumInputLength int 最小数 ...

  9. 一步一步解析H.264码流的NALU(SPS,PSS,IDR)获取宽高和帧率

    分析H.264码流的工具 CodecVisa,StreamEye以及VM Analyzer NALU是由NALU头和RBSP数据组成,而RBSP可能是SPS,PPS,Slice或SEI 而且SPS位于 ...

随机推荐

  1. Random.Next 方法 (Int32, Int32)

    minValue 返回的随机数的下界(随机数可取该下界值). maxValue 返回的随机数的上界(随机数不能取该上界值).maxValue 必须大于等于 minValue. 返回值 一个大于等于 m ...

  2. 最近工作用到的sql脚本

    USE MadeInChina DUMP TRANSACTION MadeInChina WITH NO_LOG --清除日志 BACKUP LOG MadeInChina WITH NO_LOG B ...

  3. #-webkit-autofill##google#启用表单自动填充时,如何覆盖黄色背景

    google和opera浏览器的表单自动填充后,输入框均会变成黄色背景,黑色字体.如下图. 这样的话会与网页的整体设计风格不一致,怎样自定义样式,来覆盖黄色背景. 首先来看看是什么导致的,右键查看元素 ...

  4. CentOS下对Apache的中文乱码处理

    # vi /etc/sysconfig/i18nLANG="en_US.UTF-8"SYSFONT="latarcyrheb-sun16" 默认的语言是英文,如 ...

  5. Linux系统VIM编辑器

    vim,linux系统中一款超好用的文本编辑器,是vi的升级版. 三种操作模式 命令模式: 控制光标移动,可对文本进行删除.恢复.黏贴等工作 输入模式: 正常的文本录入 末行模式: 保存,退出与设置编 ...

  6. Android videoview循环播放视频

    如何在一个activity里实现videoview对一个文件夹下的所有视频文件顺序循环播放,当切换界面时暂停, 切换回来继续原来的视频播放呢.所谓的 自动循环播放就是监听到视频播放结束之后继续重新播放 ...

  7. ubuntu 12.04安装vncserver

    1.安装桌面 apt-get install ubuntu-desktop 2.安装vncserver apt-get install vnc4server 3.设置vncserver密码 vncpa ...

  8. DHT11温湿度传感器

    一.硬件介绍 RH是相对湿度,是用零点温度来定义的,一般,RH在45%~65%之间最为合适. 注:NTC为热敏电阻,输出为:单总线数字信号,单线双向串行通讯. 注:上拉电阻情况下,配置为开漏输出,可以 ...

  9. HDU 4652 Dice(期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(2)平均抛多少 ...

  10. Itext导出PDF,word,图片案例

    iText导出pdf.word.图片 一.前言 在企业的信息系统中,报表处理一直占比较重要的作用,本文将介绍一种生成PDF报表的Java组件--iText.通过在服务器端使用Jsp或JavaBean生 ...