⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lencod.c

📁 h.264 影像壓縮 必須在 .net 的環境 下操作
💻 C
📖 第 1 页 / 共 5 页
字号:
      img->framepoc   = imin (img->toppoc, img->bottompoc);
    }
#endif

    //Rate control
    if (input->RCEnable && img->type == I_SLICE)
      rc_init_gop_params();

    // which layer does the image belong to?
    img->layer = (IMG_NUMBER % (input->NumFramesInELSubSeq + 1)) ? 0 : 1;

    // redundant frame initialization and allocation
    if (input->redundant_pic_flag)
    {
      Init_redundant_frame();
      Set_redundant_frame();
    }

    encode_one_frame(); // encode one I- or P-frame

    img->last_ref_idc = img->nal_reference_idc ? 1 : 0;

    // if key frame is encoded, encode one redundant frame
    if (input->redundant_pic_flag && key_frame)
    {
      encode_one_redundant_frame();
    }

    if (img->type == I_SLICE && input->EnableOpenGOP)
      img->last_valid_reference = img->ThisPOC;

    if (input->ReportFrameStats)
      report_frame_statistic();

    if (img->nal_reference_idc == 0)
    {
      primary_disp ++;
      //img->frame_num -= 1;
      //img->frame_num %= max_frame_num;
    }

    if (img->currentPicture->idr_flag)
    {
      img->idr_gop_number = 0;
      //start_frame_no_in_this_IGOP = img->frm_number;
      //start_tr_in_this_IGOP = img->toppoc;
      // start_tr_in_this_IGOP = (img->frm_number - 1 ) * (input->jumpd + 1) +1;
    }
    else
      img->idr_gop_number ++;

    encode_enhancement_layer();    
  }
  // terminate sequence
  terminate_sequence();

  flush_dpb();

  close(p_in);
  if (-1 != p_dec)
    close(p_dec);
  if (p_trace)
    fclose(p_trace);

  Clear_Motion_Search_Module ();

  RandomIntraUninit();
  FmoUninit();

  if (input->HierarchicalCoding)
    clear_gop_structure ();

  // free structure for rd-opt. mode decision
  clear_rdopt ();

#ifdef _LEAKYBUCKET_
  calc_buffer();
#endif

  // report everything
  report();

#ifdef _LEAKYBUCKET_
  if (Bit_Buffer)
  free(Bit_Buffer);
#endif

  free_dpb();
  if( IS_INDEPENDENT(input) )
  {
    for( nplane=0; nplane<MAX_PLANE; nplane++ )
    {
      free_colocated(Co_located_JV[nplane]);
    }
  }
  else
  {
    free_colocated(Co_located);
  }
  uninit_out_buffer();

  free_global_buffers();

  // free image mem
  free_img ();
  free_context_memory ();
  FreeNalPayloadBuffer();
  FreeParameterSets();

  return 0;
}
/*!
 ***********************************************************************
 * \brief
 *    Terminates and reports statistics on error.
 *
 ***********************************************************************
 */
void report_stats_on_error(void)
{
  int nplane;
  input->no_frames = img->frm_number;
  terminate_sequence();

  flush_dpb();

  close(p_in);
  if (-1 != p_dec)
    close(p_dec);

  if (p_trace)
    fclose(p_trace);

  Clear_Motion_Search_Module ();

  RandomIntraUninit();
  FmoUninit();

  if (input->HierarchicalCoding)
    clear_gop_structure ();

  // free structure for rd-opt. mode decision
  clear_rdopt ();

#ifdef _LEAKYBUCKET_
  calc_buffer();
#endif

  if (input->ReportFrameStats)
    report_frame_statistic();

  // report everything
  report();

  free_dpb();
  if( IS_INDEPENDENT(input) )
  {
    for( nplane=0; nplane<MAX_PLANE; nplane++ )
    {
      free_colocated(Co_located_JV[nplane]);
    }
  }
  else
  {
    free_colocated(Co_located);
  }
  uninit_out_buffer();

  free_global_buffers();

  // free image mem
  free_img ();
  free_context_memory ();
  FreeNalPayloadBuffer();
  FreeParameterSets();
  exit (-1);
}

/*!
 ***********************************************************************
 * \brief
 *    Initializes the POC structure with appropriate parameters.
 *
 ***********************************************************************
 */
void init_poc()
{
  //the following should probably go in sequence parameters
  // frame poc's increase by 2, field poc's by 1

  img->pic_order_cnt_type=input->pic_order_cnt_type;

  img->delta_pic_order_always_zero_flag = FALSE;
  img->num_ref_frames_in_pic_order_cnt_cycle= 1;

  if (input->BRefPictures == 1)
  {
    img->offset_for_non_ref_pic  =   0;
    img->offset_for_ref_frame[0] =   2;
  }
  else
  {
    img->offset_for_non_ref_pic  =  -2*(input->successive_Bframe);
    img->offset_for_ref_frame[0] =   2*(input->successive_Bframe+1);
  }

  if ((input->PicInterlace==FRAME_CODING) && (input->MbInterlace==FRAME_CODING))
    img->offset_for_top_to_bottom_field=0;
  else
    img->offset_for_top_to_bottom_field=1;

  if ((input->PicInterlace==FRAME_CODING) && (input->MbInterlace==FRAME_CODING))
  {
    img->pic_order_present_flag = FALSE;
    img->delta_pic_order_cnt_bottom = 0;
  }
  else
  {
    img->pic_order_present_flag = TRUE;
    img->delta_pic_order_cnt_bottom = 1;
  }
}


/*!
 ***********************************************************************
 * \brief
 *    Initializes the img->nz_coeff
 * \par Input:
 *    none
 * \par  Output:
 *    none
 * \ side effects
 *    sets omg->nz_coef[][][][] to -1
 ***********************************************************************
 */
void CAVLC_init(void)
{
  unsigned int i, k, l;

  for (i = 0; i < img->PicSizeInMbs; i++)
    for (k = 0; k < 4; k++)
      for (l = 0; l < (4 + (unsigned int)img->num_blk8x8_uv); l++)
        img->nz_coeff[i][k][l] = 0;
}


/*!
 ***********************************************************************
 * \brief
 *    Initializes the Image structure with appropriate parameters.
 * \par Input:
 *    Input Parameters struct inp_par *inp
 * \par  Output:
 *    Image Parameters struct img_par *img
 ***********************************************************************
 */
void init_img()
{
  int i;
  int byte_abs_range;

  static int mb_width_cr[4] = {0,8, 8,16};
  static int mb_height_cr[4]= {0,8,16,16};

  // Color format
  img->yuv_format = input->yuv_format;

  //pel bitdepth init
  img->bitdepth_luma            = input->BitDepthLuma;
  img->bitdepth_scale[0]        = 1 << (img->bitdepth_luma - 8);
  img->bitdepth_lambda_scale    = 2 * (img->bitdepth_luma - 8);
  img->bitdepth_luma_qp_scale   = 3 *  img->bitdepth_lambda_scale;
  img->dc_pred_value_comp[0]    =  1<<(img->bitdepth_luma - 1);
  img->max_imgpel_value_comp[0] = (1<<img->bitdepth_luma) - 1;

  img->dc_pred_value            =  img->dc_pred_value_comp[0]; // set defaults
  img->max_imgpel_value         = img->max_imgpel_value_comp[0];

  img->mb_size[0][0]            = img->mb_size[0][1] = MB_BLOCK_SIZE;

  // Initialization for RC QP parameters (could be placed in ratectl.c)
  img->RCMinQP                = input->RCMinQP[P_SLICE];
  img->RCMaxQP                = input->RCMaxQP[P_SLICE];

  // Set current residue & prediction array pointers
  img->curr_res = img->m7[0];
  img->curr_prd = img->mpr[0];

  if (img->yuv_format != YUV400)
  {
    img->bitdepth_chroma          = input->BitDepthChroma;
    img->bitdepth_scale[1]        = 1 << (img->bitdepth_chroma - 8);
    img->dc_pred_value_comp[1]    = 1<<(img->bitdepth_chroma - 1);
    img->dc_pred_value_comp[2]    = img->dc_pred_value_comp[1];
    img->max_imgpel_value_comp[1] = (1<<img->bitdepth_chroma) - 1;
    img->max_imgpel_value_comp[2] = img->max_imgpel_value_comp[1];
    img->num_blk8x8_uv        = (1<<img->yuv_format)&(~(0x1));
    img->num_cdc_coeff        = img->num_blk8x8_uv<<1;
    img->mb_size[1][0] = img->mb_size[2][0] = img->mb_cr_size_x = (img->yuv_format == YUV420 || img->yuv_format == YUV422) ? 8 : 16;
    img->mb_size[1][1] = img->mb_size[2][1] = img->mb_cr_size_y = (img->yuv_format == YUV444 || img->yuv_format == YUV422) ? 16 : 8;

    img->bitdepth_chroma_qp_scale = 6*(img->bitdepth_chroma - 8);

    img->chroma_qp_offset[0] = active_pps->cb_qp_index_offset;
    img->chroma_qp_offset[1] = active_pps->cr_qp_index_offset;
  }
  else
  {
    img->bitdepth_chroma     = 0;
    img->bitdepth_scale[1]   = 0;
    img->max_imgpel_value_comp[1] = 0;
    img->max_imgpel_value_comp[2] = img->max_imgpel_value_comp[1];
    img->num_blk8x8_uv       = 0;
    img->num_cdc_coeff       = 0;
    img->mb_size[1][0] = img->mb_size[2][0] = img->mb_cr_size_x = 0;
    img->mb_size[1][1] = img->mb_size[2][1] = img->mb_cr_size_y = 0;

    img->bitdepth_chroma_qp_scale = 0;
    img->bitdepth_chroma_qp_scale = 0;

    img->chroma_qp_offset[0] = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -