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

📄 configfile.c

📁 H.264编码实现
💻 C
📖 第 1 页 / 共 4 页
字号:
  {
    if ((params->slice_argument%2)!=0)
    {
      fprintf ( stderr, "Warning: slice border within macroblock pair. ");
      if (params->slice_argument > 1)
      {
        params->slice_argument--;
      }
      else
      {
        params->slice_argument++;
      }
      fprintf ( stderr, "Using %d MBs per slice.\n", params->slice_argument);
    }
  }

  // read the slice group configuration file. Only for types 0, 2 or 6
  if ( 0 != params->num_slice_groups_minus1 )
  {
    read_slice_group_info();
  }

  if (params->WPMCPrecision && (params->RDPictureDecision != 1 || params->GenerateMultiplePPS != 1) )
  {
    snprintf(errortext, ET_SIZE, "WPMCPrecision requires both RDPictureDecision=1 and GenerateMultiplePPS=1.\n");
    error (errortext, 400);
  }
  if (params->WPMCPrecision && params->WPMCPrecFullRef && params->num_ref_frames < 16 )
  {
    params->num_ref_frames++;
    if ( params->P_List0_refs )
      params->P_List0_refs++;
    else
      params->P_List0_refs = params->num_ref_frames;
    if ( params->B_List0_refs )
      params->B_List0_refs++;
    else
      params->B_List0_refs = params->num_ref_frames;
    if ( params->B_List1_refs )
      params->B_List1_refs++;
    else
      params->B_List1_refs = params->num_ref_frames;
  }
  else if ( params->WPMCPrecision && params->WPMCPrecFullRef )
  {
    snprintf(errortext, ET_SIZE, "WPMCPrecFullRef requires NumberReferenceFrames < 16.\n");
    error (errortext, 400);
  }

  if (params->ReferenceReorder && params->MbInterlace )
  {
    snprintf(errortext, ET_SIZE, "ReferenceReorder not supported with MBAFF\n");
    error (errortext, 400);
  }

  if (params->PocMemoryManagement && params->MbInterlace )
  {
    snprintf(errortext, ET_SIZE, "PocMemoryManagement not supported with MBAFF\n");
    error (errortext, 400);
  }

  if ((!params->rdopt)&&(params->MbInterlace))
  {
    snprintf(errortext, ET_SIZE, "MB AFF is not compatible with non-rd-optimized coding.");
    error (errortext, 500);
  }

  // check RDoptimization mode and profile. FMD does not support Frex Profiles.
  if (params->rdopt==2 && ( params->ProfileIDC>=FREXT_HP || params->ProfileIDC==FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "Fast Mode Decision methods not supported in FREX Profiles");
    error (errortext, 500);
  }

  if ( (params->MEErrorMetric[Q_PEL] == ERROR_SATD && params->MEErrorMetric[H_PEL] == ERROR_SAD && params->MEErrorMetric[F_PEL] == ERROR_SAD)
    && params->SearchMode > FAST_FULL_SEARCH && params->SearchMode < EPZS)
  {
    snprintf(errortext, ET_SIZE, "MEDistortionQPel=2, MEDistortionHPel=0, MEDistortionFPel=0 is not allowed when SearchMode is set to 1 or 2.");
    error (errortext, 500);
  }

  // Tian Dong: May 31, 2002
  // The number of frames in one sub-seq in enhanced layer should not exceed
  // the number of reference frame number.
  if ( params->NumFramesInELSubSeq > params->num_ref_frames || params->NumFramesInELSubSeq < 0 )
  {
    snprintf(errortext, ET_SIZE, "NumFramesInELSubSeq (%d) is out of range [0,%d).", params->NumFramesInELSubSeq, params->num_ref_frames);
    error (errortext, 500);
  }
  // Tian Dong: Enhanced GOP is not supported in bitstream mode. September, 2002
  if ( params->NumFramesInELSubSeq > 0 && params->of_mode == PAR_OF_ANNEXB )
  {
    snprintf(errortext, ET_SIZE, "Enhanced GOP is not supported in bitstream mode and RTP mode yet.");
    error (errortext, 500);
  }
  // Tian Dong (Sept 2002)
  // The AFF is not compatible with spare picture for the time being.
  if ((params->PicInterlace || params->MbInterlace) && params->SparePictureOption == TRUE)
  {
    snprintf(errortext, ET_SIZE, "AFF is not compatible with spare picture.");
    error (errortext, 500);
  }

  // Only the RTP mode is compatible with spare picture for the time being.
  if (params->of_mode != PAR_OF_RTP && params->SparePictureOption == TRUE)
  {
    snprintf(errortext, ET_SIZE, "Only RTP output mode is compatible with spare picture features.");
    error (errortext, 500);
  }

  if( (params->WeightedPrediction > 0 || params->WeightedBiprediction > 0) && (params->MbInterlace))
  {
    snprintf(errortext, ET_SIZE, "Weighted prediction coding is not supported for MB AFF currently.");
    error (errortext, 500);
  }
  if ( params->NumFramesInELSubSeq > 0 && params->WeightedPrediction > 0)
  {
    snprintf(errortext, ET_SIZE, "Enhanced GOP is not supported in weighted prediction coding mode yet.");
    error (errortext, 500);
  }

  //! the number of slice groups is forced to be 1 for slice group type 3-5
  if(params->num_slice_groups_minus1 > 0)
  {
    if( (params->slice_group_map_type >= 3) && (params->slice_group_map_type<=5) )
      params->num_slice_groups_minus1 = 1;
  }

  // Rate control
  if(params->RCEnable)
  {
    if (params->basicunit == 0)
      params->basicunit = (params->output.height + img->auto_crop_bottom)*(params->output.width + img->auto_crop_right)/256;

    if ( ((params->output.height + img->auto_crop_bottom)*(params->output.width + img->auto_crop_right)/256) % params->basicunit != 0)
    {
      snprintf(errortext, ET_SIZE, "Frame size in macroblocks must be a multiple of BasicUnit.");
      error (errortext, 500);
    }

    if ( params->RCUpdateMode == RC_MODE_1 && 
      !( (params->intra_period == 1 || params->idr_period == 1 || params->BRefPictures == 2 ) && !params->successive_Bframe ) )
    {
      snprintf(errortext, ET_SIZE, "Use RCUpdateMode = 1 only for all intra or all B-slice coding.");
      error (errortext, 500);
    }

    if ( params->BRefPictures == 2 && params->intra_period == 0 && params->RCUpdateMode != RC_MODE_1 )
    {
      snprintf(errortext, ET_SIZE, "Use RCUpdateMode = 1 for all B-slice coding.");
      error (errortext, 500);
    }

    if ( params->HierarchicalCoding && params->RCUpdateMode != RC_MODE_2 && params->RCUpdateMode != RC_MODE_3 )
    {
      snprintf(errortext, ET_SIZE, "Use RCUpdateMode = 2 or 3 for hierarchical B-picture coding.");
      error (errortext, 500);
    }

    if ( (params->RCUpdateMode != RC_MODE_1) && (params->intra_period == 1) )
    {
      snprintf(errortext, ET_SIZE, "Use RCUpdateMode = 1 for all intra coding.");
      error (errortext, 500);
    }
  }

  if ((params->successive_Bframe)&&(params->BRefPictures)&&(params->idr_period)&&(params->pic_order_cnt_type!=0))
  {
    error("Stored B pictures combined with IDR pictures only supported in Picture Order Count type 0\n",-1000);
  }

  if( !params->direct_spatial_mv_pred_flag && params->num_ref_frames<2 && params->successive_Bframe >0)
    error("temporal direct needs at least 2 ref frames\n",-1000);

  if (params->rdopt == 0)
  {
    if ((params->DisableSubpelME && params->MEErrorMetric[F_PEL] != params->ModeDecisionMetric))
    {
      snprintf(errortext, ET_SIZE, "\nLast refinement level (FPel) distortion not the same as Mode decision distortion.\nPlease update MEDistortionFPel (%d) and/or  MDDistortion(%d).", params->MEErrorMetric[F_PEL], params->ModeDecisionMetric);
      error (errortext, 500);
    }
    else if (params->MEErrorMetric[Q_PEL] != params->ModeDecisionMetric)
    {
      snprintf(errortext, ET_SIZE, "\nLast refinement level (QPel) distortion not the same as Mode decision distortion.\nPlease update MEDistortionQPel (%d) and/or  MDDistortion(%d).", params->MEErrorMetric[Q_PEL], params->ModeDecisionMetric);
      error (errortext, 500);
    }
  }
  // frext
  if(params->Transform8x8Mode && params->sp_periodicity /*SP-frames*/)
  {
    snprintf(errortext, ET_SIZE, "\nThe new 8x8 mode is not implemented for sp-frames.");
    error (errortext, 500);
  }

  if(params->Transform8x8Mode && ( params->ProfileIDC<FREXT_HP && params->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nTransform8x8Mode may be used only with ProfileIDC %d to %d.", FREXT_HP, FREXT_Hi444);
    error (errortext, 500);
  }

  if (params->DisableIntra4x4 == 1 && params->DisableIntra16x16 == 1 && params->EnableIPCM == 0 && params->Transform8x8Mode == 0)
  {
    snprintf(errortext, ET_SIZE, "\nAt least one intra prediction mode needs to be enabled.");
    error (errortext, 500);
  }

  if(params->ScalingMatrixPresentFlag && ( params->ProfileIDC<FREXT_HP && params->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nScalingMatrixPresentFlag may be used only with ProfileIDC %d to %d.", FREXT_HP, FREXT_Hi444);
    error (errortext, 500);
  }

  if(params->yuv_format==YUV422 && ( params->ProfileIDC < FREXT_Hi422 && params->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nFRExt Profile(YUV Format) Error!\nYUV422 can be used only with ProfileIDC %d or %d\n",FREXT_Hi422, FREXT_Hi444);
    error (errortext, 500);
  }
  if(params->yuv_format==YUV444 && ( params->ProfileIDC < FREXT_Hi444 && params->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nFRExt Profile(YUV Format) Error!\nYUV444 can be used only with ProfileIDC %d.\n",FREXT_Hi444);
    error (errortext, 500);
  }

  if (params->successive_Bframe && ((params->BiPredMotionEstimation) && (params->search_range < params->BiPredMESearchRange)))
  {
    snprintf(errortext, ET_SIZE, "\nBiPredMESearchRange must be smaller or equal SearchRange.");
    error (errortext, 500);
  }

  // check consistency
  if ( params->ChromaMEEnable && !(params->ChromaMCBuffer) ) 
  {
    snprintf(errortext, ET_SIZE, "\nChromaMCBuffer must be set to 1 if ChromaMEEnable is set.");
    error (errortext, 500);
  }

  if ( params->ChromaMEEnable && params->yuv_format ==  YUV400) 
  {
    fprintf(stderr, "Warning: ChromaMEEnable cannot be used with YUV400 color format, disabling ChromaMEEnable.\n");
    params->ChromaMEEnable = 0;
  }

  if ( (params->ChromaMCBuffer == 0) && (( params->yuv_format ==  YUV444) && (!params->separate_colour_plane_flag)) )
  {
    fprintf(stderr, "Warning: Enabling ChromaMCBuffer for YUV444 combined color coding.\n");
    params->ChromaMCBuffer = 1;
  }


  if (params->EnableOpenGOP)
    params->ReferenceReorder = 1;

  if (params->SearchMode != EPZS)
    params->EPZSSubPelGrid = 0;

  params->EPZSGrid = params->EPZSSubPelGrid << 1;

  if (params->redundant_pic_flag)
  {
    if (params->PicInterlace || params->MbInterlace)
    {
      snprintf(errortext, ET_SIZE, "Redundant pictures cannot be used with interlaced tools.");
      error (errortext, 500);
    }
    if (params->RDPictureDecision)
    {
      snprintf(errortext, ET_SIZE, "Redundant pictures cannot be used with RDPictureDecision.");
      error (errortext, 500);
    }
    if (params->successive_Bframe)
    {
      snprintf(errortext, ET_SIZE, "Redundant pictures cannot be used with B frames.");
      error (errortext, 500);
    }
    if (params->PrimaryGOPLength < (1 << params->NumRedundantHierarchy))
    {
      snprintf(errortext, ET_SIZE, "PrimaryGOPLength must be equal or greater than 2^NumRedundantHierarchy.");
      error (errortext, 500);
    }
    if (params->num_ref_frames < params->PrimaryGOPLength)
    {
      snprintf(errortext, ET_SIZE, "NumberReferenceFrames must be greater than or equal to PrimaryGOPLength.");
      error (errortext, 500);
    }
  }

  if (params->num_ref_frames == 1 && params->successive_Bframe)
  {
    fprintf( stderr, "\nWarning: B slices used but only one reference allocated within reference buffer.\n");
    fprintf( stderr, "         Performance may be considerably compromised! \n");
    fprintf( stderr, "         2 or more references recommended for use with B slices.\n");
  }
  if ((params->HierarchicalCoding || params->BRefPictures) && params->successive_Bframe)
  {
    fprintf( stderr, "\nWarning: Hierarchical coding or Referenced B slices used.\n");
    fprintf( stderr, "         Make sure that you have allocated enough references\n");
    fprintf( stderr, "         in reference buffer to achieve best performance.\n");
  }

  if (params->FastMDEnable == 0)
  {
    params->FastIntraMD = 0;
    params->FastIntra16x16 = 0;
    params->FastIntra4x4 = 0;
    params->FastIntra8x8 = 0;
    params->FastIntraChroma = 0;
  }

  if (params->UseRDOQuant == 1)
  {
    if (params->rdopt == 0)
    {
      snprintf(errortext, ET_SIZE, "RDO Quantization not supported with low complexity RDO.");
      error (errortext, 500);
    }

    if (params->MbInterlace != 0)
    {
      printf("RDO Quantization currently not supported with MBAFF. Option disabled.\n");
      params->UseRDOQuant = 0;
      params->RDOQ_QP_Num = 1;
      params->RDOQ_CP_MV = 0;
      params->RDOQ_CP_Mode = 0;
    }
    else
    {
      params->AdaptiveRounding = 0;
      printf("AdaptiveRounding is disabled when RDO Quantization is used\n");
      if (params->RDOQ_QP_Num < 2)
      {
        params->RDOQ_CP_MV = 0;
        params->RDOQ_CP_Mode = 0;
      }
    }
  }
  else
  {
    params->RDOQ_QP_Num = 1;
    params->RDOQ_CP_MV = 0;
    params->RDOQ_CP_Mode = 0;
  }

  ProfileCheck();
  LevelCheck();
}

void PatchInputNoFrames(void)
{
  // Tian Dong: May 31, 2002
  // If the frames are grouped into two layers, "FramesToBeEncoded" in the config file
  // will give the number of frames which are in the base layer. Here we let params->no_frames
  // be the total frame numbers.
  params->no_frames = 1 + (params->no_frames - 1) * (params->NumFramesInELSubSeq + 1);
}

⌨️ 快捷键说明

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