This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Regarding CBR with Interlaced Video Input

Hi All,

We have developed our own DM8168 based H/W, and using EZSDK version 5.05.02.00.

In our board we are able to achieve the CBR in Progressive video input, but when we feed the 

interlaced video input, the O/P bitrate is twice the given bitrate.

Can any one tell us why this is happening in the Interlaced input?

H264 settings 'c' file attached for reference.

we have tested with 1080i50 / 60 and 576i all the resolutions are behaves the same.

Please help us to resolve the issue.

Regards

R.Abdul Rahman

h264_settings.c
OMX_ERRORTYPE CTI_Apply_h264_params(	OMX_HANDLETYPE 		hEncoder,
					CTI_VideoConfig		EncoderConfig,
					CTI_Adv_AVC_Config	AdvEncoderConfig)
{
	OMX_ERRORTYPE eError = OMX_ErrorUndefined;

	OMX_VIDEO_PARAM_ENCODER_PRESETTYPE tEncoderPreset;

	int PocType = 0;


	OMX_VIDEO_CONFIG_DYNAMICPARAMS tDynParams;
	OMX_VIDEO_PARAM_STATICPARAMS tStaticParam;

	OMX_INIT_PARAM(&tStaticParam);

	tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;


	OMX_VIDEO_PARAM_AVCTYPE tAVCParams;


	OMX_INIT_PARAM(&tAVCParams);
	tAVCParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT;

	eError = OMX_GetParameter(hEncoder, OMX_IndexParamVideoAvc, &tAVCParams);

	if (eError != OMX_ErrorNone)
	{
		ERROR("failed to Encoder OMX_SetParameter OMX_IndexParamVideoAvc \n");
	}

	switch (AdvEncoderConfig.eAVC_Profile)
	{

	case CTI_AVCProfile_Main:
		tAVCParams.eProfile = OMX_VIDEO_AVCProfileMain;
		CTI_DEBUG_SAY("**** Main Profile Selected *** ID(%d)\n",AdvEncoderConfig.eAVC_ProfileLevel_ID);
		tAVCParams.bEnableASO = OMX_TRUE;
		tAVCParams.bEnableRS = OMX_TRUE;
		tAVCParams.bEnableFMO = OMX_FALSE;
		tAVCParams.bEnableUEP = OMX_TRUE;

		tAVCParams.bEntropyCodingCABAC = OMX_TRUE;

		if (AdvEncoderConfig.eBFrames == AVC_BFrame_ENABLE)
			tAVCParams.nBFrames = AdvEncoderConfig.nBFrameCount;
		else
			tAVCParams.nBFrames = 0;
		break;


	case CTI_AVCProfile_High:
		tAVCParams.eProfile = OMX_VIDEO_AVCProfileHigh;
		CTI_DEBUG_SAY("**** High Profile Selected *** ID(%d)\n",AdvEncoderConfig.eAVC_ProfileLevel_ID);
		tAVCParams.bEnableASO = OMX_TRUE;
		tAVCParams.bEnableRS = OMX_TRUE;
		tAVCParams.bEnableFMO = OMX_FALSE;
		tAVCParams.bEnableUEP = OMX_TRUE;
		tAVCParams.nBFrames = AdvEncoderConfig.nBFrameCount;

		tAVCParams.bEntropyCodingCABAC = OMX_TRUE;

		if (AdvEncoderConfig.eBFrames == AVC_BFrame_ENABLE)
			tAVCParams.nBFrames = AdvEncoderConfig.nBFrameCount;
		else
			tAVCParams.nBFrames = 0;

		break;

	case CTI_AVCProfile_Baseline:
	default:
		tAVCParams.eProfile = OMX_VIDEO_AVCProfileBaseline;
		CTI_DEBUG_SAY("**** BaseLine Profile Selected *** ID(%d) \n",AdvEncoderConfig.eAVC_ProfileLevel_ID);
		tAVCParams.bEnableASO = OMX_FALSE;
		tAVCParams.bEnableRS = OMX_FALSE;
		tAVCParams.bEnableFMO = OMX_FALSE;
		tAVCParams.bEnableUEP = OMX_FALSE;
		tAVCParams.nBFrames = 0;

		tAVCParams.bEntropyCodingCABAC = OMX_FALSE;
		break;
	}


	switch(AdvEncoderConfig.eAVC_ProfileLevel_ID)
	{
		case CTI_AVCLevel31:	tAVCParams.eLevel = OMX_VIDEO_AVCLevel31;break;
		case CTI_AVCLevel32:	tAVCParams.eLevel = OMX_VIDEO_AVCLevel32;break;
		case CTI_AVCLevel4:		tAVCParams.eLevel = OMX_VIDEO_AVCLevel4;break;
		case CTI_AVCLevel41:	tAVCParams.eLevel = OMX_VIDEO_AVCLevel41;break;

		case CTI_AVCLevel5:		tAVCParams.eLevel = OMX_VIDEO_AVCLevel5;break;
		case CTI_AVCLevel51:	tAVCParams.eLevel = OMX_VIDEO_AVCLevel51;break;

		case CTI_AVCLevel42:
		default:				tAVCParams.eLevel = OMX_VIDEO_AVCLevel42;break;
	}

	tAVCParams.bEntropyCodingCABAC = OMX_FALSE;

	if ((AdvEncoderConfig.eAVC_Profile != CTI_AVCProfile_Baseline) && (AdvEncoderConfig.eEntropy == CTI_ENTROPY_CABAC))
	{
			tAVCParams.bEntropyCodingCABAC = OMX_TRUE;
	}

	eError = OMX_SetParameter(hEncoder, OMX_IndexParamVideoAvc, &tAVCParams);
	if (eError != OMX_ErrorNone)
	{
		ERROR("failed to Encoder OMX_SetParameter OMX_IndexParamVideoAvc \n");
	}

	/* Encoder Preset settings */
	OMX_INIT_PARAM(&tEncoderPreset);
	tEncoderPreset.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
	eError =	OMX_GetParameter (hEncoder, OMX_TI_IndexParamVideoEncoderPreset,&tEncoderPreset);

	//tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_High_Speed_Med_Quality;
	tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_High_Quality;//OMX_Video_Enc_Med_Speed_High_Quality;
	tEncoderPreset.eRateControlPreset = OMX_Video_RC_User_Defined;//OMX_Video_RC_Low_Delay;
	eError =	OMX_SetParameter (hEncoder, OMX_TI_IndexParamVideoEncoderPreset,&tEncoderPreset);


	/////////////////////////////////////////////////////////////////////////////////////
#if 1
	  OMX_INIT_PARAM (&tDynParams);

	  tDynParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT;

	  eError = OMX_GetParameter (hEncoder, OMX_TI_IndexParamVideoDynamicParams,&tDynParams);

	  /* setting I frame interval */
	 tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetFrameRate = EncoderConfig.fps * 1000;
	 tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetBitRate = EncoderConfig.Bitrate*1000;


	#if ENABLE_GDR
	  /*Parameter setting for GDR*/

	  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
	  tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
	  tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
	  tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshRate = 4;
	  tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
	  /* updating rows to be intra refresh */
	  tDynParams.videoDynamicParams.h264EncDynamicParams.intraRefreshRateGDRDynamic = 4;
	  /* updating overlap rows */
	 tDynParams.videoDynamicParams.h264EncDynamicParams.gdrOverlapRowsBtwFramesDynamic = 0;
	#else

	 if((EncoderConfig.RateCtrl == ControlRate_Constant) || (EncoderConfig.RateCtrl == ControlRate_ConstantSkipFrames))
	 {
	  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
	  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY;

	  if (EncoderConfig.RateCtrl == ControlRate_ConstantSkipFrames)
	  {
		  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.allowFrameSkip = 1;
	  	  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.enablePartialFrameSkip  = 1;
	  }
	  else
	  {
		  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.allowFrameSkip = 0;
	  	  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.enablePartialFrameSkip  = 0;
	  }


	  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.HRDBufferSize = (EncoderConfig.Bitrate*1000) * 0.4;
	  tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.initialBufferLevel = (EncoderConfig.Bitrate*1000) * 0.25;
	 }

	#endif

	  tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.intraFrameInterval = EncoderConfig.i2p;

	  eError = OMX_SetParameter (hEncoder, OMX_TI_IndexParamVideoDynamicParams,&tDynParams);

	/////////////////////////////////////////////////////////////////////////////////////////

#endif






	eError = OMX_GetParameter (hEncoder, OMX_TI_IndexParamVideoStaticParams,&tStaticParam);

	tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset =	XDM_USER_DEFINED;

	tStaticParam.videoStaticParams.h264EncStaticParams.numTemporalLayer =	IH264_TEMPORAL_LAYERS_1;


	if(	(EncoderConfig.VideoInputResolution == VID_RES_S_1080I50) ||
		(EncoderConfig.VideoInputResolution == VID_RES_S_1080i)
		)
	{
		//SetInterlaceEncodingType(hEncoder);
		//tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.inputContentType =		IVIDEO_INTERLACED;
		tStaticParam.videoStaticParams.h264EncStaticParams.bottomFieldIntra =	1;
		tStaticParam.videoStaticParams.h264EncStaticParams.interlaceCodingType =	IH264_INTERLACE_DEFAULT;
	}


	/* for base profile */
	tStaticParam.videoStaticParams.h264EncStaticParams.transformBlockSize =	IH264_TRANSFORM_DEFAULT;	//IH264_TRANSFORM_4x4;

	if (AdvEncoderConfig.eAVC_Profile == CTI_AVCProfile_Baseline)
		tStaticParam.videoStaticParams.h264EncStaticParams.entropyCodingMode =	IH264_ENTROPYCODING_CAVLC;
	else
	{
		if(AdvEncoderConfig.eEntropy == CTI_ENTROPY_CAVLC)
			tStaticParam.videoStaticParams.h264EncStaticParams.entropyCodingMode =	IH264_ENTROPYCODING_CAVLC;
		else
			tStaticParam.videoStaticParams.h264EncStaticParams.entropyCodingMode =	IH264_ENTROPYCODING_CABAC;
	}

	/* for base profile end */

	/* for the mask bits, please refer to codec user guide */
	tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluControlPreset 	= IH264_NALU_CONTROL_USERDEFINED;
	tStaticParam.videoStaticParams.h264EncStaticParams.gopStructure					= IH264ENC_GOPSTRUCTURE_NONUNIFORM;
	tStaticParam.videoStaticParams.h264EncStaticParams.transformBlockSize				= IH264_TRANSFORM_ADAPTIVE;
	tStaticParam.videoStaticParams.h264EncStaticParams.log2MaxFNumMinus4				= 0;
	tStaticParam.videoStaticParams.h264EncStaticParams.referencePicMarking 				= IH264_SHORT_TERM_PICTURE;
	tStaticParam.videoStaticParams.h264EncStaticParams.enableLongTermRefFrame 			= 0;



	tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence 	|= 0x03BE; 
	tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture 	|= 0x03BE; 
	tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIntraPicture 	|= 0x03BE;
	tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskNonIntraPicture 	|= 0x0002; 
	tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskEndOfSequence  	|= 0x0C00;


	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.vuiCodingPreset 			= IH264_VUICODING_USERDEFINED;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.aspectRatioInfoPresentFlag 	= 1;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.aspectRatioIdc 				= IH264ENC_ASPECTRATIO_EXTENDED;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.videoSignalTypePresentFlag 	= 1;//0;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.videoFormat 				= IH264ENC_VIDEOFORMAT_NTSC;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.videoFullRangeFlag 			= 1;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.timingInfoPresentFlag 		= 1;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.hrdParamsPresentFlag 		= 1;//0;
	 tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.numUnitsInTicks 			= 1000;


	tStaticParam.videoStaticParams.h264EncStaticParams.IDRFrameInterval = 1;//I2P;//2;


	if(((PocType < 0)) || (PocType > 2)) PocType = 0;

	if (AdvEncoderConfig.eBFrames == AVC_BFrame_ENABLE) PocType = 0;

	//Added as per ES-264 Stream
	printf("########### Picture Order Count Type is %d ##################\n",PocType);
	tStaticParam.videoStaticParams.h264EncStaticParams.picOrderCountType = PocType;//IH264_POC_TYPE_2;

	tStaticParam.videoStaticParams.h264EncStaticParams.enableGMVSei 								= 0;
	tStaticParam.videoStaticParams.h264EncStaticParams.enableWatermark 								= 0;
	tStaticParam.videoStaticParams.h264EncStaticParams.framePackingSEIParams.framePackingPreset		= 0;
	tStaticParam.videoStaticParams.h264EncStaticParams.stereoInfoParams.stereoInfoPreset 			= 0;


	tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rateControlParamsPreset 	= IH264_RATECONTROLPARAMS_USERDEFINED;
	tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rcAlgo 					= IH264_RATECONTROL_PRC_LOW_DELAY;

	tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.removeExpensiveCoeff       = OMX_TRUE;
	tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePRC                	= OMX_TRUE;

	tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enableHRDComplianceMode 	= OMX_TRUE;

	if(EncoderConfig.RateCtrl ==  ControlRate_Constant)
	{
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip            	= OMX_FALSE; //OMX_TRUE;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip  	= OMX_FALSE;//OMX_TRUE;
	}
	else if(EncoderConfig.RateCtrl ==  ControlRate_ConstantSkipFrames)
	{
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip            	= OMX_TRUE;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip  	= OMX_TRUE;

	}

	if((EncoderConfig.RateCtrl == ControlRate_Constant) || (EncoderConfig.RateCtrl == ControlRate_ConstantSkipFrames))
	{
		tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_LOW_DELAY;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY;
		tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.maxBitRate = EncoderConfig.Bitrate*1000;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip  = 1;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = 1;
	}
	else
	{
		tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_STORAGE;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC;

		tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.maxBitRate = EncoderConfig.Bitrate*1000;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip  = 0;
		tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = 0;
	}

	tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.HRDBufferSize = ((EncoderConfig.Bitrate*1000) * 0.4);
	tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.initialBufferLevel = ((EncoderConfig.Bitrate*1000) * 0.25);


	eError = OMX_SetParameter (hEncoder, OMX_TI_IndexParamVideoStaticParams,&tStaticParam);


	if((AdvEncoderConfig.eEntropy == CTI_ENTROPY_CAVLC) && (AdvEncoderConfig.nEnableSlicing == 1))	CTI_IL_Client_EnableSlicing(hEncoder);

	printf("=========================================== h264 Params Applied ============================================\n");

	return eError;

}



  • Hi Abdul,

              Bitrate is depends on the input content If targetbitrate is less & input sequence has more motion, then there are chances that bitrate may not be acehieved.

    So is it possible to send me the both progressive & interlace bitstreams where you had observed the double bitrate. With bitstream it can be analysed why bitrate is

    not able to achieve.

    Regards

    Gajanan

  • Hello,

    Could you try to set bit 12 as well refer to the B.3 Control masks:


    // for the mask bits, please refer to codec user guide
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluControlPreset = IH264_NALU_CONTROL_USERDEFINED;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence |= 0x11A0;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture |= 0x11A0;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIntraPicture |= 0x11A0;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskNonIntraPicture |= 0x1002;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskEndOfSequence |= 0x1C00;

    BR
    Margarita
  • Hi Margarita,

    Sorry for the delayed response.

    We tried the settings given, but still we are seeing the same issue.
    moreover if we set the I to P ratio as 1 ( that is all are 'I Frames')
    in this case bitrate is increased more and more.example the given bitrate
    is 512KB but it takes 5000KB.

    Please help us to resolve the issue as soon as possible.


    Regards
    R.Abdul Rahman.
  • Hello,

    When the video stream is with progressive content are you observing the same?

    If I remember right I was able to archive 500kB but was for progressive.

    Best Regards,

    Margarita

  • Have you set these params as well:

    maxBitRate = pAppData->nBitRate;
    enablePartialFrameSkip = 1;
    allowFrameSkip = 1;
    HRDBufferSize = pAppData->nBitRate * 1/2;
    initialBufferLevel = pAppData->nBitRate * 1/2;

    ?

    BR
    Margarita

  • Hello,

    Could you share the yuv file with me to check it on my side?
    Also could you provide information about the resolution?

    BR
    Margarita

  • Hello,

    Here is what I am seeing.

    BR

    Margarita

  • Hello Margarita,

    1. Progressive video working fine. but if we set the I o P ratio to 1 then the bitrate goes high.

    2. We are using same rate control settings
    "
    maxBitRate = pAppData->nBitRate;
    enablePartialFrameSkip = 1;
    allowFrameSkip = 1;
    HRDBufferSize = pAppData->nBitRate * 1/2;
    initialBufferLevel = pAppData->nBitRate * 1/2;
    "

    3. It is happening in all the resolutions ( form CIF (352x288) to 1080p )

    4. Our YUV file size is arround 330MB can you provide any FTP access so that we can share the File.

    Can you please share your source with us, it will be very helpful for us.

    Thanks a lot for your help.

    Regards
    R.Abdul Rahman
  • Hello,

    Could you upload it somewhere and provide me the link. I can not provide you a ftp.
    The settings(CBR) for progressive shall work for interlaced as well.
    If I remember right I have provided you before the ilclient_utils.c with my settings for CBR. Could you try with them only?

    BR
    Margarita
  • Hi Margarita,

    Yes you have already given the ilclient_utils.c, I am using same settings in my code.
    Could you please provide me your email address, so that send you the google-drive link.
    my email id is : "abdulrahman@cornetindia.com"

    could you please try the I to P ration as '1' in your side ?
    also can please send your code once again i will cross check my settings.


    Thanks a lot for your Help.

    Regards
    R.Abdul RAhman
  • Hello,

    Abdul Rahman Rasool said:
    could you please try the I to P ration as '1' in your side ?

    Which params you are pointing?

    BR

    Margarita

  • Hello,

    Here is the console prints:

    ./encode_a8host_debug.xv5T -o smpl.264 -i /home/root/SampleFi
    les_to_TI/YUV_720p/SampleYUV.yuv -f 30 -b 500000 -w 1280 -h 720 -c h264
    output file: smpl.264
    input file: /home/root/SampleFiles_to_TI/YUV_720p/SampleYUV.yuv
    bit_rate: 500000
    frame_rate: 30
    codec: h264
    width: 1280
    height: 720
     Encode example
    ===============================
     OMX_Init completed
     UIAClient is ready to send a UIA configuration command
    UIAClient received UIA_CONFIGURE_ACK
    UIAClient is done sending requests
    UIAClient is ready to send a UIA configuration command
    UIAClient received UIA_CONFIGURE_ACK
    UIAClient is done sending requests
     opening file
     encoder component is created
     encoder input port allocate buffer done
      encoder outport buffers allocated
     got eventState changed to: OMX_StateIdle
     Encoder state IDLE
     got eventState changed to: OMX_StateExecuting
     encoder state execute
      file write thread created
      file read thread created
     294 Encoded Frames
    No data available for Read encILComp->numFrames 294
     read task exiting
      write task exited
     received eof
    got eventState changed to: OMX_StateIdle
     Encoder state idle
     got eventState changed to: OMX_StateLoaded
     encoder state loaded
      encoder free handle
    IL Client deinitialized
     example exit

    Here is what I am seeing for bitrate:

    Here is the encoded video:

    smpl.264.txt

    BR

    Margarita

  • Hi Margarita,

    I am talking about "intraFrameInterval"
    ( tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.intraFrameInterval = 1; )

    1. can you please set "intraFrameInterval" as 1 and see the result
    2. My Requirement is the Bitrate should be +/- 50Kb of the given bitrate in CBR mode.
    3. In lower "intraFrameInterval" (like 30) value I am able see the breathing effect on the Video.
    (in higher value the breathing effect is minimal)
    Is there any way to optimize this ?

    Please try and let us know the results. mean while i will cross check my code with your code and let you know.

    THANKS A LOT for your help

    Regards
    R.Abdul Rahman
  • Hello,

    I will check with intraFrameInterval=1. I will let you know.

    BR
    Margarita
  • Hi Margarita,

    Did you get the chance to try the settings ?
    Please help us to resolve this issue

    Thank you

    Regards
    R.Abdul Rahman.
  • Hello,

    I checked the setting intraFrameInterval to 1 in this case all frames will be I frames. I observed if the maxPicSizeRatioI is not set as well the encoded video is not playable.
    But I observed jumps to 1700Kb not to 7000Kb which is not working for you if I understand it correctly.
    You could check the h264enc user guide which settings could be set as well to archive < 500Kb.
    I am checking this issue also.

    Are you able to archive <500Kb with my settings when the video is with interlaced content but the intraFrameInterval is >1?


    BR
    Margarita

  • Hello Margarita,

    Even If we set the intraFrameInterval > 1, the bitrate is going high based on the Image complexity.
    if i set the 512kb it goes arround 700.

    Please help us to fix this issue.

    Did you found anything on "I only" frame encoding (that is intraFrameInterval is 1) .

    Thanks a lot for your help.

    Regards
    R.Abdul Rahman.
  • Hello,

    Could you share your encoder settings?

    BR
    Margarita
  • Hello Margarita,

    This is my encoder settings

    Regards
    R.Abdul Rahman
  • Hi Margarita

    Forgot to insert my settings

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    OMX_ERRORTYPE CTI_Apply_h264_params( OMX_HANDLETYPE hEncoder,
    CTI_VideoConfig EncoderConfig,
    CTI_Adv_AVC_Config AdvEncoderConfig)
    {
    OMX_ERRORTYPE eError = OMX_ErrorUndefined;

    OMX_VIDEO_PARAM_ENCODER_PRESETTYPE tEncoderPreset;

    int PocType = 0;


    OMX_VIDEO_CONFIG_DYNAMICPARAMS tDynParams;
    OMX_VIDEO_PARAM_STATICPARAMS tStaticParam;

    OMX_INIT_PARAM(&tStaticParam);

    tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;


    OMX_VIDEO_PARAM_AVCTYPE tAVCParams;


    OMX_INIT_PARAM(&tAVCParams);
    tAVCParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT;

    eError = OMX_GetParameter(hEncoder, OMX_IndexParamVideoAvc, &tAVCParams);

    if (eError != OMX_ErrorNone)
    {
    ERROR("failed to Encoder OMX_SetParameter OMX_IndexParamVideoAvc \n");
    }

    switch (AdvEncoderConfig.eAVC_Profile)
    {

    case CTI_AVCProfile_Main:
    tAVCParams.eProfile = OMX_VIDEO_AVCProfileMain;
    CTI_DEBUG_SAY("**** Main Profile Selected *** ID(%d)\n",AdvEncoderConfig.eAVC_ProfileLevel_ID);
    tAVCParams.bEnableASO = OMX_TRUE;
    tAVCParams.bEnableRS = OMX_TRUE;
    tAVCParams.bEnableFMO = OMX_FALSE;
    tAVCParams.bEnableUEP = OMX_TRUE;

    tAVCParams.bEntropyCodingCABAC = OMX_TRUE;

    if (AdvEncoderConfig.eBFrames == AVC_BFrame_ENABLE)
    tAVCParams.nBFrames = AdvEncoderConfig.nBFrameCount;
    else
    tAVCParams.nBFrames = 0;
    break;


    case CTI_AVCProfile_High:
    tAVCParams.eProfile = OMX_VIDEO_AVCProfileHigh;
    CTI_DEBUG_SAY("**** High Profile Selected *** ID(%d)\n",AdvEncoderConfig.eAVC_ProfileLevel_ID);
    tAVCParams.bEnableASO = OMX_TRUE;
    tAVCParams.bEnableRS = OMX_TRUE;
    tAVCParams.bEnableFMO = OMX_FALSE;
    tAVCParams.bEnableUEP = OMX_TRUE;
    tAVCParams.nBFrames = AdvEncoderConfig.nBFrameCount;

    tAVCParams.bEntropyCodingCABAC = OMX_TRUE;

    if (AdvEncoderConfig.eBFrames == AVC_BFrame_ENABLE)
    tAVCParams.nBFrames = AdvEncoderConfig.nBFrameCount;
    else
    tAVCParams.nBFrames = 0;

    break;

    case CTI_AVCProfile_Baseline:
    default:
    tAVCParams.eProfile = OMX_VIDEO_AVCProfileBaseline;
    CTI_DEBUG_SAY("**** BaseLine Profile Selected *** ID(%d) \n",AdvEncoderConfig.eAVC_ProfileLevel_ID);
    tAVCParams.bEnableASO = OMX_FALSE;
    tAVCParams.bEnableRS = OMX_FALSE;
    tAVCParams.bEnableFMO = OMX_FALSE;
    tAVCParams.bEnableUEP = OMX_FALSE;
    tAVCParams.nBFrames = 0;

    tAVCParams.bEntropyCodingCABAC = OMX_FALSE;
    break;
    }


    switch(AdvEncoderConfig.eAVC_ProfileLevel_ID)
    {
    case CTI_AVCLevel31: tAVCParams.eLevel = OMX_VIDEO_AVCLevel31;break;
    case CTI_AVCLevel32: tAVCParams.eLevel = OMX_VIDEO_AVCLevel32;break;
    case CTI_AVCLevel4: tAVCParams.eLevel = OMX_VIDEO_AVCLevel4;break;
    case CTI_AVCLevel41: tAVCParams.eLevel = OMX_VIDEO_AVCLevel41;break;

    case CTI_AVCLevel5: tAVCParams.eLevel = OMX_VIDEO_AVCLevel5;break;
    case CTI_AVCLevel51: tAVCParams.eLevel = OMX_VIDEO_AVCLevel51;break;

    case CTI_AVCLevel42:
    default: tAVCParams.eLevel = OMX_VIDEO_AVCLevel42;break;
    }

    tAVCParams.bEntropyCodingCABAC = OMX_FALSE;

    if ((AdvEncoderConfig.eAVC_Profile != CTI_AVCProfile_Baseline) && (AdvEncoderConfig.eEntropy == CTI_ENTROPY_CABAC))
    {
    tAVCParams.bEntropyCodingCABAC = OMX_TRUE;
    }

    eError = OMX_SetParameter(hEncoder, OMX_IndexParamVideoAvc, &tAVCParams);
    if (eError != OMX_ErrorNone)
    {
    ERROR("failed to Encoder OMX_SetParameter OMX_IndexParamVideoAvc \n");
    }

    /* Encoder Preset settings */
    OMX_INIT_PARAM(&tEncoderPreset);
    tEncoderPreset.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
    eError = OMX_GetParameter (hEncoder, OMX_TI_IndexParamVideoEncoderPreset,&tEncoderPreset);

    //tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_High_Speed_Med_Quality;
    tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_High_Quality;//OMX_Video_Enc_Med_Speed_High_Quality;
    tEncoderPreset.eRateControlPreset = OMX_Video_RC_User_Defined;//OMX_Video_RC_Low_Delay;
    eError = OMX_SetParameter (hEncoder, OMX_TI_IndexParamVideoEncoderPreset,&tEncoderPreset);


    /////////////////////////////////////////////////////////////////////////////////////
    #if 1
    OMX_INIT_PARAM (&tDynParams);

    tDynParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT;

    eError = OMX_GetParameter (hEncoder, OMX_TI_IndexParamVideoDynamicParams,&tDynParams);

    /* setting I frame interval */
    tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetFrameRate = EncoderConfig.fps * 1000;
    tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetBitRate = EncoderConfig.Bitrate*1000;


    #if ENABLE_GDR
    /*Parameter setting for GDR*/

    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
    tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
    tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
    tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshRate = 4;
    tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
    /* updating rows to be intra refresh */
    tDynParams.videoDynamicParams.h264EncDynamicParams.intraRefreshRateGDRDynamic = 4;
    /* updating overlap rows */
    tDynParams.videoDynamicParams.h264EncDynamicParams.gdrOverlapRowsBtwFramesDynamic = 0;
    #else

    if((EncoderConfig.RateCtrl == ControlRate_Constant) || (EncoderConfig.RateCtrl == ControlRate_ConstantSkipFrames))
    {
    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY;

    if (EncoderConfig.RateCtrl == ControlRate_ConstantSkipFrames)
    {
    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.allowFrameSkip = 1;
    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.enablePartialFrameSkip = 1;
    }
    else
    {
    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.allowFrameSkip = 0;
    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.enablePartialFrameSkip = 0;
    }


    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.HRDBufferSize = (EncoderConfig.Bitrate*1000) * 0.5;
    tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.initialBufferLevel = (EncoderConfig.Bitrate*1000) * 0.5;
    }

    #endif

    tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.intraFrameInterval = EncoderConfig.i2p;

    eError = OMX_SetParameter (hEncoder, OMX_TI_IndexParamVideoDynamicParams,&tDynParams);

    /////////////////////////////////////////////////////////////////////////////////////////

    #endif






    eError = OMX_GetParameter (hEncoder, OMX_TI_IndexParamVideoStaticParams,&tStaticParam);

    tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_USER_DEFINED;

    tStaticParam.videoStaticParams.h264EncStaticParams.numTemporalLayer = IH264_TEMPORAL_LAYERS_1;


    if( (EncoderConfig.VideoInputResolution == VID_RES_S_1080I50) ||
    (EncoderConfig.VideoInputResolution == VID_RES_S_1080i)
    )
    {
    //SetInterlaceEncodingType(hEncoder);
    //tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.inputContentType = IVIDEO_INTERLACED;
    tStaticParam.videoStaticParams.h264EncStaticParams.bottomFieldIntra = 1;
    tStaticParam.videoStaticParams.h264EncStaticParams.interlaceCodingType = IH264_INTERLACE_DEFAULT;
    }


    /* for base profile */
    tStaticParam.videoStaticParams.h264EncStaticParams.transformBlockSize = IH264_TRANSFORM_DEFAULT; //IH264_TRANSFORM_4x4;

    if (AdvEncoderConfig.eAVC_Profile == CTI_AVCProfile_Baseline)
    tStaticParam.videoStaticParams.h264EncStaticParams.entropyCodingMode = IH264_ENTROPYCODING_CAVLC;
    else
    {
    if(AdvEncoderConfig.eEntropy == CTI_ENTROPY_CAVLC)
    tStaticParam.videoStaticParams.h264EncStaticParams.entropyCodingMode = IH264_ENTROPYCODING_CAVLC;
    else
    tStaticParam.videoStaticParams.h264EncStaticParams.entropyCodingMode = IH264_ENTROPYCODING_CABAC;
    }

    /* for base profile end */

    /* for the mask bits, please refer to codec user guide */
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluControlPreset = IH264_NALU_CONTROL_USERDEFINED;
    tStaticParam.videoStaticParams.h264EncStaticParams.gopStructure = IH264ENC_GOPSTRUCTURE_NONUNIFORM;
    tStaticParam.videoStaticParams.h264EncStaticParams.transformBlockSize = IH264_TRANSFORM_ADAPTIVE;
    tStaticParam.videoStaticParams.h264EncStaticParams.log2MaxFNumMinus4 = 0;
    tStaticParam.videoStaticParams.h264EncStaticParams.referencePicMarking = IH264_SHORT_TERM_PICTURE;
    tStaticParam.videoStaticParams.h264EncStaticParams.enableLongTermRefFrame = 0;



    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence |= 0x03BE;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture |= 0x03BE;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIntraPicture |= 0x03BE;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskNonIntraPicture |= 0x0002;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskEndOfSequence |= 0x0C00;


    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.vuiCodingPreset = IH264_VUICODING_USERDEFINED;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.aspectRatioInfoPresentFlag = 1;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.aspectRatioIdc = IH264ENC_ASPECTRATIO_EXTENDED;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.videoSignalTypePresentFlag = 1;//0;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.videoFormat = IH264ENC_VIDEOFORMAT_NTSC;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.videoFullRangeFlag = 1;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.timingInfoPresentFlag = 1;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.hrdParamsPresentFlag = 1;//0;
    tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.numUnitsInTicks = 1000;


    tStaticParam.videoStaticParams.h264EncStaticParams.IDRFrameInterval = 1;//I2P;//2;


    if(((PocType < 0)) || (PocType > 2)) PocType = 0;

    if (AdvEncoderConfig.eBFrames == AVC_BFrame_ENABLE) PocType = 0;

    //Added as per ES-264 Stream
    printf("########### Picture Order Count Type is %d ##################\n",PocType);
    tStaticParam.videoStaticParams.h264EncStaticParams.picOrderCountType = PocType;//IH264_POC_TYPE_2;

    tStaticParam.videoStaticParams.h264EncStaticParams.enableGMVSei = 0;
    tStaticParam.videoStaticParams.h264EncStaticParams.enableWatermark = 0;
    tStaticParam.videoStaticParams.h264EncStaticParams.framePackingSEIParams.framePackingPreset = 0;
    tStaticParam.videoStaticParams.h264EncStaticParams.stereoInfoParams.stereoInfoPreset = 0;


    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY;

    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.removeExpensiveCoeff = OMX_TRUE;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePRC = OMX_TRUE;

    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enableHRDComplianceMode = OMX_TRUE;

    if(EncoderConfig.RateCtrl == ControlRate_Constant)
    {
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = OMX_FALSE; //OMX_TRUE;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip = OMX_FALSE;//OMX_TRUE;
    }
    else if(EncoderConfig.RateCtrl == ControlRate_ConstantSkipFrames)
    {
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = OMX_TRUE;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip = OMX_TRUE;

    }

    if((EncoderConfig.RateCtrl == ControlRate_Constant) || (EncoderConfig.RateCtrl == ControlRate_ConstantSkipFrames))
    {
    tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_LOW_DELAY;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY;
    tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.maxBitRate = EncoderConfig.Bitrate*1000;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip = 1;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = 1;
    }
    else
    {
    tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_STORAGE;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC;

    tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.maxBitRate = EncoderConfig.Bitrate*1000;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip = 0;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = 0;
    }

    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.HRDBufferSize = ((EncoderConfig.Bitrate*1000) * 0.5);
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.initialBufferLevel = ((EncoderConfig.Bitrate*1000) * 0.5);


    eError = OMX_SetParameter (hEncoder, OMX_TI_IndexParamVideoStaticParams,&tStaticParam);


    if((AdvEncoderConfig.eEntropy == CTI_ENTROPY_CAVLC) && (AdvEncoderConfig.nEnableSlicing == 1)) CTI_IL_Client_EnableSlicing(hEncoder);

    printf("=========================================== h264 Params Applied ============================================\n");

    return eError;

    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    Regards
    R.Abdul Rahman.
  • Hi Margarita,

    Did you get a chance to verify my encoder settings ?
    Please HELP us to resolve this issue as soon as possible.

    Regards
    R.Abdul Rahman.
  • Hello Abdul,

    I am sorry I will check it these days.

    BR
    Margarita
  • Hello,

    Could you try:

    tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_Med_Speed_High_Quality;

    In my case they these are set as :

    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip = 1;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = 1;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.HRDBufferSize = pAppData->nBitRate * 0.5;
    tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.initialBufferLevel = pAppData->nBitRate * 0.5;

    The Nalu values are:

    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence |= 0x11A0;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture |= 0x11A0;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIntraPicture |= 0x11A0;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskNonIntraPicture |= 0x1002;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskEndOfSequence |= 0x1C00;

    bit 12 is set.

    You could try to set maxPicSizeRatioI as well.

    Try these values and let me know.

    When the intraFrameInterval is set to 1 all the frames are I. But for 500kB the quality is very low depending on the how complex are the scenes.


    BR
    Margarita
  • Hi Margarita,

    Thanks a lot for your settings.
    But this also did not resolve the issue.
    we also tried settings maxPicSizeRatioI = 1;

    we are very much concern about the Breathing effect please help us
    to resolve the breathing issue first.

    Do you thing the GDR will help us to resolve the breathing effect
    if so please give us the GDR settings we will try that and let you know.

    FYI: we are ready to compromise the Quality but we are very much concern about the Breathing effect issue and the Bitrate jumping

    Regards
    R.Abdul Rahman
  • Hello,

    Abdul Rahman Rasool said:
    Breathing effect issue

    What is this issue I do not remember here we to discussed something different from the CBR?

    BR

    Margarita

  • Hello Margarita,

    No, we talking about the CBR Only
    say for example if the intraFrameInterval is < 10 we are seeing the breathing effect ( The Quality of the I frame is less compare to P frame in lower bitare (in CBR mode).

    Regards
    R.Abdul Rahman
  • Hello Margarita,

    FYI :
    Basically we are facing following issues in CBR mode
    1. if we set the intraFrameInterval=1 the o/p bitrate goes high
    2. if we set the intraFrameInterval < 10 we are seeing the breathing effect ( basically the I frame Quality is less compare to P frame)
    3. The Bitrate is double while we try to Encode the Interlaced video.

    Regards
    R.Abdul Rahman.
  • Hi Abdul,

              

    Abdul Rahman Rasool said:
    1. if we set the intraFrameInterval=1 the o/p bitrate goes high

    With IntraFrameInterval = 1, all frames will be encoded as Intra frames. So the bitrate will goes high & this behaviour is expected.

    Abdul Rahman Rasool said:
    2. if we set the intraFrameInterval < 10 we are seeing the breathing effect ( basically the I frame Quality is less compare to P frame)

    Increase the maxPicSizeRatioI. This will resolve your problem. The quality of I frame improve comparitively P frames. Please take of below condition

     maxPicSizeRatioI <= (intraFrameInterval << 5)

    Abdul Rahman Rasool said:
    3. The Bitrate is double while we try to Encode the Interlaced video.

    This behavior is not expected. Can you cross check the output filesizes generated for progressive & interlace for same no of frames (i.e 30 frames,60 fileds).

    If its still not clear & you are expected the double the bitrate, please send me those bistreams.

    Regards

    Gajanan

  • Hello,

    Abdul Rahman Rasool said:
    3. The Bitrate is double while we try to Encode the Interlaced video.


    Could you check my previous posts, with intraframeinterval =60 , 90 I lined you a image with bitrate viewer that the video with you share with me the bitrate is ~ 500 KB.

    Also check again maxPicSizeRatioI as I said in some of my previous posts, probably that is why I am not seeing this effect.

    What is the encoder version that you are using?

    Let me know the results.

    One more have you tried to set HF-VBR?

    My understanding of this issue it that the bitrate shall be not > 500KB

    If HF-VBR is used  the targetBitrate and  maxBitrate should be set. In the user guide you will see that for scene with normalcomplexity, the RC operates at targetBitrate. When the scene complexity increases, the RC increases the operating bitrate to a higher value. However it is not allowed to exceed
    maxBitrate.



    BR

    Margarita

  • Hello Margarita,

    My EZSDK version is 5.05.02.00
    H264 Encoder version is 2.0

    We will try the maxPicSizeRatioI and let you know.

    Can you please tell us to Enable the HF-VBR in this SDK.

    Could you please send your settings for maxPicSizeRatioI for testing .

    Thanks a lot for your help.

    Regards
    R.Abdul Rahman.
  • Hello,

    Search in the user guide for maxPicSizeRatioI there you could find the values.

    In the user guide you will find "Appendix N Rate Control - High Fidelity VariableBitrate"

    BR
    Margarita
  • Hi Abdul

            If you set MaxBitrate >= 1.5 * Bitrate, Then HFVBR will be enabled.

    Please Note that, with HFVBR there will less chances of achieving bitrate for lower bitrate. Since it will take lot of time to stabilize the bit-rate & always try to achieve the better quality.

             You need to take call on High priority is Bit-rate Achievement or Quality .

    Regards

    Gajanan

  • Hi Gajanan,

    We are very much concern about the Bit-rate.
    we are not concern about the Quality.

    Is there any way to reduce the bit-rate stabilization time in HF-VBR ?


    Regards
    R.Abdul Rahman.
  • Hi Abdul,

    If you are concerned about he bitrate then don't use HFVBR. Stick to CBR or VBR.
    Indirectly don't set Maxbitrate >= 1.5 TargetBitrate.

    Regards
    Gajanan
  • Hi Margarita,

    Did you find anything on the CBR settings.
    Please help us to resolve the Issue.

    In the User guide they gave only the valid values for maxPicSizeRatioI
    there is no enough information regarding this variable settings.

    Could you please tell us what is the suggested value for maxPicSizeRatioI


    Regards
    R.Abdul Rahman.
  • Hi Abdul,

             As I said before in the previous replies, the maxPicsizeratio should be as per below statement. 

    maxPicSizeRatioI <= (intraFrameInterval << 5)

                With IntraFrameInterval = 1, all frames will be encoded as Intra frames.The bit-rate achievement is sequence dependent. For complex sequences, 500 kbps for 720p resolution is not achievable. So this is expected behavior.

    Please send me the bit-stream where you observed this issue. I can analyse if something further can be done to reduce the bit-rate.

    Regards

    Gajanan

  • Hello Abdul,

    Have you tried Gajanan's suggestion?

    BR
    Margarita
  • Hello Magarita,

    Yes we tried Gajanan's suggestion, but that is also failed.
    because valid max value for maxPicSizeRatioI is 960.
    Usually we are using the intraframeInsteval = 60. it exceeds the
    max range of maxPicSizeRatioI so the Encoder Component is Crashing.

    we tried with intraframeInsteval = 30 that is also not helped us to resolve the issue.

    Please help us to resolve the issue we tried almost all the settings as per the user guide
    but still we are having the problem.

    My major issues are
    1. Breathing Effect ( the quality of ' I ' frame ) we tested this with "IPQualityFactor" settings
    it is not giving the expected result

    2.Bitrate variation - the Expected bitrate variation is +/- 50 Kbps, bit it goes beyond that based
    on the Image complicity ( we noticed that the Bitrate is going high only for 'I' frame ) so we hoping
    if we fix the ' I ' Only frame coding with the desired bitrate this issue will be fixed.
  • Hello,

    On my side maxPicSizeRatioI was set to 640.

    I also tried intraframeInsteval=90 here is the bitrate with the video which you shared with me:

    For resolution 1280x720 when all frames are I at 500Kbps would be achievable in case if the video is simple(no complex scenes). The video which you shared with me is not simple. Please increase the intraframeinterval value, you could try with  90. 

    Could you try with the default encode demo in EZSDK but place my settings(check my previous posts).

    BR

    Margarita

  • Hi Margarita,

    Thanks a lot for your Quick response

    we will compare the settings with default encode demo code and get back to you.

    One more thing, if we reduce the target frame rate that time also the bit rate goes high, can you please check this in your side
    let us know

    Regards
    R.Abdul Rahman.
  • Hi Margarita,

    I have compared the EZSDK encode demo settings and my settings both are same except the following changes
    1. Custom NAL unit control
    2. HRD buffersize
    3. rateControlParamsPreset

    TI Settings (encode demo application settings)
    1. Custom NAL unit control -- not controlled by application
    2. HRD buffersize = targetbitrate * 2
    3. rateControlParamsPreset = IH264_RATECONTROLPARAMS_DEFAULT;

    My Encoder Settings
    1. Custom NAL unit control -- Initialized as per my requirement (value = 0x13BE)
    2. HRD buffersize = targetbitrate * 0.5
    3. rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;


    Please let me know what is wrong in my settings.
    (I have alrady posted my full encoder settings for your ref)

    Can you please share you encoder 'c' file, it will be VERY HELPFUL for me


    Regards
    R.Abdul Rahman.
  • Hello,

    0383.ilclient_utils.c.txt
    /*
     *  Copyright (c) 2010-2011, Texas Instruments Incorporated
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *  *  Redistributions of source code must retain the above copyright
     *     notice, this list of conditions and the following disclaimer.
     *
     *  *  Redistributions in binary form must reproduce the above copyright
     *     notice, this list of conditions and the following disclaimer in the
     *     documentation and/or other materials provided with the distribution.
     *
     *  *  Neither the name of Texas Instruments Incorporated nor the names of
     *     its contributors may be used to endorse or promote products derived
     *     from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *  Contact information for paper mail:
     *  Texas Instruments
     *  Post Office Box 655303
     *  Dallas, Texas 75265
     *  Contact information:
     *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
     *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
     *  ============================================================================
     *
     */
    
    #include <stdlib.h>
    #include <stdio.h>
    #include <pthread.h>
    #include <unistd.h>
    #include <xdc/std.h>
    #include <memory.h>
    #include <getopt.h>
    
    /*-------------------------program files -------------------------------------*/
    #include "ti/omx/interfaces/openMaxv11/OMX_Core.h"
    #include "ti/omx/interfaces/openMaxv11/OMX_Component.h"
    #include "OMX_TI_Common.h"
    #include "OMX_Video.h"
    #include "OMX_TI_Video.h"
    #include "ilclient.h"
    #include "ilclient_utils.h"
    #include <omx_venc.h>
    #include <omx_vfpc.h>
    #include <omx_vfdc.h>
    #include <omx_ctrl.h>
    #include <omx_vfcc.h>
    #include <OMX_TI_Index.h>
    /*---------------------- function prototypes ---------------------------------*/
    /* None */
    
    void usage (IL_ARGS *argsp)
    {
      printf
        ("encode_a8host_debug.xv5T \n"
         "-o | --output          output filename \n"
         "-i | --input           input filename \n"
         "-f | --framerate       encode frame rate \n"
         "-b | --bitrate         encode bit rate \n"
         "-w | --width           encode width \n"
         "-h | --height          encode height \n"
         "-c | --codec           h264, mpeg4, h263 \n"
       );                      
      printf(" example -    ./encode_a8host_debug.xv5T -o sample.h264 -i sample.yuv -f 60 -b 1000000 -w 1920 -h 1080 -c h264\n");
      
      exit (1);
    }
    
    /* ========================================================================== */
    /**
    * parse_args() : This function parses the input arguments provided to app.
    *
    * @param argc             : number of args 
    * @param argv             : args passed by app
    * @param argsp            : parsed data pointer
    *
    *  @return      
    *
    *
    */
    /* ========================================================================== */
    
    void parse_args (int argc, char *argv[], IL_ARGS *argsp)
    {
      const char shortOptions[] = "o:i:w:h:f:b:c:";
      const struct option longOptions[] =
      {
        {"output", required_argument, NULL, ArgID_OUTPUT_FILE},
        {"input", required_argument, NULL, ArgID_INPUT_FILE},
        {"width", required_argument, NULL, ArgID_WIDTH},
        {"height", required_argument, NULL, ArgID_HEIGHT},
        {"framerate", required_argument, NULL, ArgID_FRAMERATE},
        {"bitrate", required_argument, NULL, ArgID_BITRATE},
        {"codec", required_argument, NULL, ArgID_CODEC},
        {0, 0, 0, 0}
      };
    
      int index, outfile = 0, infile = 0, codec = 0, width = 0, height =0;
      int argID;
    
      for (;;)
      {
        argID = getopt_long (argc, argv, shortOptions, longOptions, &index);
    
        if (argID == -1)
        {
          break;
        }
    
        switch (argID)
        {
          case ArgID_OUTPUT_FILE:
          case 'o':
            strncpy (argsp->output_file, optarg, MAX_FILE_NAME_SIZE);
            outfile = 1;
            break;
          case 'i':
            strncpy (argsp->input_file, optarg, MAX_FILE_NAME_SIZE);
            infile = 1;
            break;
          case ArgID_FRAMERATE:
          case 'f':
            argsp->frame_rate = atoi (optarg);
            break;
          case ArgID_WIDTH:
          case 'w':
            argsp->width = atoi (optarg);
            width = 1;
            break;
          case ArgID_HEIGHT:
          case 'h':
            argsp->height = atoi (optarg);
            height = 1;
            break;
          case ArgID_BITRATE:
          case 'b':
            argsp->bit_rate = atoi (optarg);
            break;
          case ArgID_CODEC:
          case 'c':
            strncpy (argsp->codec, optarg, MAX_CODEC_NAME_SIZE);
            codec = 1;
            break;
          default:
            usage (argsp);
            exit (1);
        }
      }
    
      if (optind < argc)
      {
        usage (argsp);
        exit (EXIT_FAILURE);
      }
    
      if (argsp->bit_rate == 0 || !outfile || !infile || argsp->frame_rate == 0  || !width || !height || !codec)
      {
        usage (argsp);
        exit (1);
      }
    
      printf ("output file: %s\n", argsp->output_file);
      printf ("input file: %s\n", argsp->input_file);
      printf ("bit_rate: %d\n", argsp->bit_rate);
      printf ("frame_rate: %d\n", argsp->frame_rate);
      printf ("codec: %s\n", argsp->codec);
      printf ("width: %d\n", argsp->width);
      printf ("height: %d\n", argsp->height);
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientInit() : This function is to allocate and initialize the application
    *                   data structure. It is just to maintain application control.
    *
    * @param pAppData          : appliaction / client data Handle 
    * @param width             : stream width
    * @param height            : stream height
    * @param frameRate         : encode frame rate
    * @param bitrate           : encoder bit rate
    * @param numFrames         : encoded number of frames
    * @param displayId         : display instance id
    *
    *  @return      
    *
    *
    */
    /* ========================================================================== */
    
    void IL_ClientInit (IL_Client **pAppData, int width, int height, int frameRate,
                        int bitRate, char *codec)
    {
      int i;
      IL_Client *pAppDataPtr;
      IL_CLIENT_INPORT_PARAMS *inPortParamsPtr;
      IL_CLIENT_OUTPORT_PARAMS *outPortParamsPtr;
    
      /* Allocating data structure for IL client structure / buffer management */
    
      pAppDataPtr = (IL_Client *) malloc (sizeof (IL_Client));
      memset (pAppDataPtr, 0x0, sizeof (IL_Client));
    
      /* update the user provided parameters */
      pAppDataPtr->nFrameRate   = frameRate;
      pAppDataPtr->nBitRate     = bitRate;
      /* pAppDataPtr->nEncodedFrms = numFrames; */
      
      pAppDataPtr->nHeight      = height;
      pAppDataPtr->nWidth       =  width; 
    
      if (strcmp (codec, "h264") == 0)
      {
        pAppDataPtr->eCompressionFormat = OMX_VIDEO_CodingAVC;
      }
      else if (strcmp (codec, "mpeg4") == 0)
      {
        pAppDataPtr->eCompressionFormat = OMX_VIDEO_CodingMPEG4;
      }
      else if (strcmp (codec, "h263") == 0)
      {
        pAppDataPtr->eCompressionFormat = OMX_VIDEO_CodingH263;
      }
      
      /* alloacte data structure for each component used in this IL Client */
      pAppDataPtr->encILComp =
        (IL_CLIENT_COMP_PRIVATE *) malloc (sizeof (IL_CLIENT_COMP_PRIVATE));
      memset (pAppDataPtr->encILComp, 0x0, sizeof (IL_CLIENT_COMP_PRIVATE));
    
      /* these semaphores are used for tracking the callbacks received from
         component */
      pAppDataPtr->encILComp->eos = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp->eos, 0);
    
      pAppDataPtr->encILComp->done_sem = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp->done_sem, 0);
    
      pAppDataPtr->encILComp->port_sem = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp->port_sem, 0);
    
      pAppDataPtr->encILComp->numInport = 1;
      pAppDataPtr->encILComp->numOutport = 1;
      pAppDataPtr->encILComp->startOutportIndex = 1;
    
      pAppDataPtr->encILComp->inPortParams =
        malloc (sizeof (IL_CLIENT_INPORT_PARAMS) *
                pAppDataPtr->encILComp->numInport);
      memset (pAppDataPtr->encILComp->inPortParams, 0x0,
              sizeof (IL_CLIENT_INPORT_PARAMS));
    
      pAppDataPtr->encILComp->outPortParams =
        malloc (sizeof (IL_CLIENT_INPORT_PARAMS) *
                pAppDataPtr->encILComp->numOutport);
      memset (pAppDataPtr->encILComp->outPortParams, 0x0,
              sizeof (IL_CLIENT_OUTPORT_PARAMS));
    
      for (i = 0; i < pAppDataPtr->encILComp->numInport; i++)
      {
        inPortParamsPtr = pAppDataPtr->encILComp->inPortParams + i;
        inPortParamsPtr->nBufferCountActual = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
        /* input buffers size for yuv buffers, format is YUV420 hence 3/2 */
        inPortParamsPtr->nBufferSize =
          (pAppDataPtr->nHeight * pAppDataPtr->nWidth * 3) >> 1;
        /* this pipe is used for taking buffers from file read thread; in this
           example, file read is not used */
        pipe ((int *) inPortParamsPtr->ipBufPipe);
      }
      for (i = 0; i < pAppDataPtr->encILComp->numOutport; i++)
      {
        outPortParamsPtr = pAppDataPtr->encILComp->outPortParams + i;
        outPortParamsPtr->nBufferCountActual = IL_CLIENT_ENC_OUTPUT_BUFFER_COUNT;
        /* this size could be smaller than this value */
        outPortParamsPtr->nBufferSize =
          (pAppDataPtr->nHeight * pAppDataPtr->nWidth * 3) >> 1;
    
        /* This pipe is used if output is directed to file write thread, */
        pipe ((int *) outPortParamsPtr->opBufPipe);
      }
      /* each componet will have local pipe to take bufffers from other component
         or its own consumed buffer, so that it can be passed to other connected
         components */
      pipe ((int *) pAppDataPtr->encILComp->localPipe);
    
      /* populate the pointer for allocated data structure */
      *pAppData = pAppDataPtr;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientInit() : This function is to deinitialize the application
    *                   data structure.
    *
    * @param pAppData          : appliaction / client data Handle 
    *  @return      
    *
    *
    */
    /* ========================================================================== */
    
    void IL_ClientDeInit (IL_Client * pAppData)
    {
      int i;
      IL_CLIENT_INPORT_PARAMS *inPortParamsPtr;
      IL_CLIENT_OUTPORT_PARAMS *outPortParamsPtr;
    
    
      close ((int) pAppData->encILComp->localPipe);
    
      for (i = 0; i < pAppData->encILComp->numInport; i++)
      {
        inPortParamsPtr = pAppData->encILComp->inPortParams + i;
        /* This pipe is used if output is directed to file write thread, in this
           example, file read is not used */
        close ((int) inPortParamsPtr->ipBufPipe);
      }
      for (i = 0; i < pAppData->encILComp->numOutport; i++)
      {
        outPortParamsPtr = pAppData->encILComp->outPortParams + i;
        close ((int) outPortParamsPtr->opBufPipe);
      }
    
      free (pAppData->encILComp->inPortParams);
    
      free (pAppData->encILComp->outPortParams);
    
      /* these semaphores are used for tracking the callbacks received from
         component */
      semp_deinit (pAppData->encILComp->eos);
      free(pAppData->encILComp->eos);
    
      semp_deinit (pAppData->encILComp->done_sem);
      free(pAppData->encILComp->done_sem);
    
      semp_deinit (pAppData->encILComp->port_sem);
    
      free(pAppData->encILComp->port_sem);
    
      free (pAppData->encILComp);
    
      free (pAppData);
    
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientErrorToStr() : Function to map the OMX error enum to string
    *
    * @param error   : OMX Error type
    *
    *  @return      
    *  String conversion of the OMX_ERRORTYPE
    *
    */
    /* ========================================================================== */
    
    OMX_STRING IL_ClientErrorToStr (OMX_ERRORTYPE error)
    {
      OMX_STRING errorString;
    
      /* used for printing purpose */
      switch (error)
      {
        case OMX_ErrorNone:
          errorString = "OMX_ErrorNone";
          break;
        case OMX_ErrorInsufficientResources:
          errorString = "OMX_ErrorInsufficientResources";
          break;
        case OMX_ErrorUndefined:
          errorString = "OMX_ErrorUndefined";
          break;
        case OMX_ErrorInvalidComponentName:
          errorString = "OMX_ErrorInvalidComponentName";
          break;
        case OMX_ErrorComponentNotFound:
          errorString = "OMX_ErrorComponentNotFound";
          break;
        case OMX_ErrorInvalidComponent:
          errorString = "OMX_ErrorInvalidComponent";
          break;
        case OMX_ErrorBadParameter:
          errorString = "OMX_ErrorBadParameter";
          break;
        case OMX_ErrorNotImplemented:
          errorString = "OMX_ErrorNotImplemented";
          break;
        case OMX_ErrorUnderflow:
          errorString = "OMX_ErrorUnderflow";
          break;
        case OMX_ErrorOverflow:
          errorString = "OMX_ErrorOverflow";
          break;
        case OMX_ErrorHardware:
          errorString = "OMX_ErrorHardware";
          break;
        case OMX_ErrorInvalidState:
          errorString = "OMX_ErrorInvalidState";
          break;
        case OMX_ErrorStreamCorrupt:
          errorString = "OMX_ErrorStreamCorrupt";
          break;
        case OMX_ErrorPortsNotCompatible:
          errorString = "OMX_ErrorPortsNotCompatible";
          break;
        case OMX_ErrorResourcesLost:
          errorString = "OMX_ErrorResourcesLost";
          break;
        case OMX_ErrorNoMore:
          errorString = "OMX_ErrorNoMore";
          break;
        case OMX_ErrorVersionMismatch:
          errorString = "OMX_ErrorVersionMismatch";
          break;
        case OMX_ErrorNotReady:
          errorString = "OMX_ErrorNotReady";
          break;
        case OMX_ErrorTimeout:
          errorString = "OMX_ErrorTimeout";
          break;
        default:
          errorString = "<unknown>";
      }
    
      return errorString;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientEncUseInitialOutputResources() :  This function gives initially all
    *                                         output buffers to a component.
    *                                         after consuming component would keep
    *                                         in local pipe for connect thread use. 
    *
    * @param pAppdata   : application data structure
    *
    *  @return      
    *  String conversion of the OMX_ERRORTYPE
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientEncUseInitialOutputResources (IL_CLIENT_COMP_PRIVATE 
                                                           *thisComp)
    {
      OMX_ERRORTYPE err = OMX_ErrorNone;
      unsigned int i = 0;
    
      for (i = 0; i < thisComp->outPortParams->nBufferCountActual; i++)
      {
        /* Pass the output buffer to the component */
        err = OMX_FillThisBuffer (thisComp->handle,
                                  thisComp->outPortParams->pOutBuff[i]);
      }
    
      return err;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientDecUseInitialInputResources() : This function gives initially all
    *                                          input buffers to decoder component.
    *                                          after consuming decoder would keep
    *                                          in ipbufpipe for file read thread. 
    *
    * @param pAppdata   : application data structure
    *
    *  @return      
    *  String conversion of the OMX_ERRORTYPE
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientEncUseInitialInputResources (IL_Client *pAppdata)
    {
    
      OMX_ERRORTYPE err = OMX_ErrorNone;
      unsigned int i = 0;
      int frameSize = 0;
      IL_CLIENT_COMP_PRIVATE *encILComp = NULL;
      encILComp = ((IL_Client *) pAppdata)->encILComp;
    
      /* Give input buffers to component which is limited by no of input buffers
         available. Rest of the data will be read on the callback from input data
         read thread */
      for (i = 0; i < encILComp->inPortParams->nBufferCountActual; i++)
      {
        frameSize = (pAppdata->nHeight * pAppdata->nWidth * 3) >> 1;
        /* Get the size of one frame at a time */
        frameSize = fread (encILComp->inPortParams->pInBuff[i]->pBuffer, 1, frameSize, pAppdata->fIn);
    
        /* Exit the loop if no data available */
        if (!frameSize)
        {
          break;
        }
    
        encILComp->inPortParams->pInBuff[i]->nFilledLen = frameSize;
        encILComp->inPortParams->pInBuff[i]->nOffset = 0;
        encILComp->inPortParams->pInBuff[i]->nAllocLen = frameSize;
        encILComp->inPortParams->pInBuff[i]->nInputPortIndex = 0;
    
        /* Pass the input buffer to the component */
    
        err = OMX_EmptyThisBuffer (encILComp->handle,
                                   encILComp->inPortParams->pInBuff[i]);
    
      }
      return err;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientSetEncodeParams() : Function to fill the port definition 
    * structures and call the Set_Parameter function on to the Encode
    * Component
    *
    * @param pAppData   : Pointer to the application data
    *
    *  @return      
    *  OMX_ErrorNone = Successful 
    *
    *  Other_value = Failed (Error code is returned)
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientSetEncodeParams (IL_Client *pAppData)
    {
      OMX_ERRORTYPE eError = OMX_ErrorUndefined;
      OMX_HANDLETYPE pHandle = NULL;
      OMX_VIDEO_PARAM_PROFILELEVELTYPE tProfileLevel;
      OMX_VIDEO_PARAM_ENCODER_PRESETTYPE tEncoderPreset;
      OMX_VIDEO_PARAM_BITRATETYPE tVidEncBitRate;
      //OMX_VIDEO_PARAM_PORTFORMATTYPE tVideoParams;
      OMX_PARAM_PORTDEFINITIONTYPE tPortDef;
      OMX_VIDEO_CONFIG_DYNAMICPARAMS tDynParams;
      OMX_VIDEO_PARAM_STATICPARAMS   tStaticParam;
      //OMX_VIDEO_PARAM_FRAMEDATACONTENTTYPE  tFrameType;
      
      pHandle = pAppData->pEncHandle;
    
      /* Number of frames to be encoded, not used by defaualt */
      pAppData->encILComp->numFrames = pAppData->nEncodedFrms;
    
    
      OMX_INIT_PARAM (&tPortDef);
      /* Get the Number of Ports */
    
      tPortDef.nPortIndex = OMX_VIDENC_INPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      /* set the actual number of buffers required */
      tPortDef.nBufferCountActual = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
      /* set the video format settings */
      tPortDef.format.video.nFrameWidth = pAppData->nWidth;
      tPortDef.format.video.nStride = pAppData->nWidth;
      tPortDef.format.video.nFrameHeight = pAppData->nHeight;
      tPortDef.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
      /* settings for OMX_IndexParamVideoPortFormat */
      tPortDef.nBufferSize = (pAppData->nWidth * pAppData->nHeight * 3) >> 1;
      eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode OMX_IndexParamPortDefinition for input \n");
      }
    
      OMX_INIT_PARAM (&tPortDef);
    
      tPortDef.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      /* settings for OMX_IndexParamPortDefinition */
      /* set the actual number of buffers required */
      tPortDef.nBufferCountActual = IL_CLIENT_ENC_OUTPUT_BUFFER_COUNT;
      tPortDef.format.video.nFrameWidth = pAppData->nWidth;
      tPortDef.format.video.nFrameHeight = pAppData->nHeight;
      tPortDef.format.video.eCompressionFormat = pAppData->eCompressionFormat;
      tPortDef.format.video.xFramerate = (pAppData->nFrameRate << 16);
      tPortDef.format.video.nBitrate = pAppData->nBitRate;
      /* settings for OMX_IndexParamVideoPortFormat */
    
      eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode OMX_IndexParamPortDefinition for output \n");
      }
    
      /* For changing bit rate following index can be used */
      OMX_INIT_PARAM (&tVidEncBitRate);
    
      tVidEncBitRate.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoBitrate,
                                 &tVidEncBitRate);
    
      tVidEncBitRate.eControlRate = OMX_Video_ControlRateConstant;  
    
      tVidEncBitRate.nTargetBitrate = pAppData->nBitRate;
      eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoBitrate,
                                 &tVidEncBitRate);
    
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode bitrate \n");
      }
      /* Set the profile and level for H264 */
      OMX_INIT_PARAM (&tProfileLevel);
      tProfileLevel.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
    
      eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent,
                                 &tProfileLevel);
    
      /* set as profile / level */
      if(pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) { 
      tProfileLevel.eProfile = OMX_VIDEO_AVCProfileHigh;
      tProfileLevel.eLevel = OMX_VIDEO_AVCLevel42;
      }
      else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
      tProfileLevel.eProfile = OMX_VIDEO_MPEG4ProfileSimple;
      tProfileLevel.eLevel = OMX_VIDEO_MPEG4Level5;
       }
      else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
      tProfileLevel.eProfile = OMX_VIDEO_H263ProfileBaseline;
      tProfileLevel.eLevel = OMX_VIDEO_H263Level40;
       }
      
    
      eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent,
                                 &tProfileLevel);
      if (eError != OMX_ErrorNone)
        ERROR ("failed to set encoder pfofile \n");
      /* before creating use set_parameters, for run-time change use set_config
         all codec supported parameters can be set using this index       */
      
      /* example for h264 parameters settings */
         
      if(pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) {   
      
      /* Encoder Preset settings */
      OMX_INIT_PARAM (&tEncoderPreset);
      tEncoderPreset.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset,
                                 &tEncoderPreset);
    
    #if ENABLE_GDR 							 
      tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_User_Defined;    
    #else
       
      tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_Med_Speed_High_Quality;
      
    #endif
    
    
      tEncoderPreset.eRateControlPreset = OMX_Video_RC_Low_Delay;
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset,
                                 &tEncoderPreset);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to Encoder Preset \n");
      }
      
      OMX_INIT_PARAM (&tDynParams);
    
      tDynParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams,
                                 &tDynParams);
      
      /* setting I frame interval */
     tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetFrameRate = pAppData->nFrameRate * 1000;
     tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetBitRate = pAppData->nBitRate;
    
      
    #if ENABLE_GDR  
      /*Parameter setting for GDR*/
      
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;  
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshRate = 4;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
      /* updating rows to be intra refresh */
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraRefreshRateGDRDynamic = 4;
      /* updating overlap rows */
     tDynParams.videoDynamicParams.h264EncDynamicParams.gdrOverlapRowsBtwFramesDynamic = 0;
    #else
    
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY; 
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.allowFrameSkip = 1;
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.enablePartialFrameSkip  = 1;
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.HRDBufferSize = pAppData->nBitRate * 0.5;
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.initialBufferLevel = pAppData->nBitRate * 0.5;
    
    #endif
      
      tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.intraFrameInterval = 90;      
                             
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams,
                                 &tDynParams);
    
      OMX_INIT_PARAM (&tStaticParam);
    
      tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams,
                                 &tStaticParam);
     
    
     
    #if ENABLE_GDR    
      /*Parameter setting for GDR*/
     
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_USER_DEFINED;    
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraRefreshRate = 4;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
    #else 
     
      
    
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset =  XDM_USER_DEFINED;
    
    //If ratecontrolpreset is set as user defined then the rcAlgo should be set. In case is set as IVIDEO_LOW_DELAY the rcAlgo should be not set
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_LOW_DELAY; 
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED; 
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY; 
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.maxBitRate = pAppData->nBitRate; 
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.enablePartialFrameSkip  = 1;
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.allowFrameSkip = 1;
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.HRDBufferSize = pAppData->nBitRate * 0.5;
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.initialBufferLevel = pAppData->nBitRate * 0.5;
      
    
    		
    
    
    
    tStaticParam.videoStaticParams.h264EncStaticParams.numTemporalLayer = IH264_TEMPORAL_LAYERS_1;
    
    
    /* for base profile */
    tStaticParam.videoStaticParams.h264EncStaticParams.transformBlockSize = IH264_TRANSFORM_ADAPTIVE;
    tStaticParam.videoStaticParams.h264EncStaticParams.entropyCodingMode = IH264_ENTROPYCODING_CAVLC;
    
    
    
    
     
    // for the mask bits, please refer to codec user guide
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluControlPreset = IH264_NALU_CONTROL_USERDEFINED;
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence |=  0x11A0; 
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture |=  0x11A0; 
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIntraPicture |= 0x11A0; 
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskNonIntraPicture |= 0x1002; 
    tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskEndOfSequence |= 0x1C00; 
      
    #endif /* ENABLE_GDR */ 
      
      
                              
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams,
                                 &tStaticParam);
      }
      if((pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) || 
         (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263))
      {
        OMX_INIT_PARAM(&tStaticParam);
        tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
    
        eError =
            OMX_GetParameter(pHandle, OMX_TI_IndexParamVideoStaticParams,
                             &tStaticParam);
        if (eError != OMX_ErrorNone)
        {
          ERROR ("failed to Encoder OMX_GetParameter StaticParams \n");
        }
    
        tStaticParam.videoStaticParams.mpeg4EncStaticParams.videnc2Params.encodingPreset
                                                         = XDM_USER_DEFINED;
        tStaticParam.videoStaticParams.mpeg4EncStaticParams.vopTimeIncrementResolution
                                                         = pAppData->nFrameRate;
    
        eError =
            OMX_SetParameter(pHandle, OMX_TI_IndexParamVideoStaticParams,
                             &tStaticParam);
        if (eError != OMX_ErrorNone)
        {
          ERROR ("failed to Encoder OMX_SetParameter StaticParams \n");
        }
      }
    
      return eError;
    }
    
    /* Nothing beyond this point */
    
    

    or you could refer to the topic.

    BR

    Margarita

  • Hello Margarita,

    I used your settings still the output bitrate is bumping while encoding the complex video.
    and referred the Link.

    Here our problem is CBR is working but it is not strictly following the Output bitrate.
    This problem is not only in Lower bitrates , it is happening in higher bitrates also
    example 4000kbps is my target bitrate but sometime it goes upto 4300kbps.

    Regards
    R.Abdul Rahman
  • Hi abdul,

    1. For I frame if bitrate is going high then reduce the value of the maxPicSizeRatioI.
    2. If you are using the rateControlParamPreset = userdefined then ,
    set qpMaxI = 51, qpMaxP = 51

    This may resolve your bitrate issue.

    Regards
    Gajanan
  • Hi Gajanan,

    Thanks for your suggestion.
    But this is also not resolved my problem.
    The output bitrate is still bumping beyond the fixed level.
    ( I need the strict CBR output)
    for example the target-bitrate is 512kb means it should give the output bitrate <= 512kb
    but the current encoder output is goes up to 750kb.

    Please share your Ideas to fix this issue.
    If you have any encoder settings for CBR Please share with us.

    Thanks a lot for your help.

    Regards
    R.Abdul Rahman
  • Hi Abdul,

             Can you share your bit-stream where you had observed the bit-stream shootup.

    I can analyse & provide feedback. This will be faster solution. 

    Regards

    Gajanan

  • Hi Gajanan

    File attached for your ref.

    Please do the needful 

    BitStream.zip

    Regards

    R.Abdul Rahman

  • Hi Abdul,

             For the attached bit-stream bit-rate is achieved even with 60fps configuration.

            The stream is very complex & 500kbps for this stream is difficult to achieve with decent quality. To achieve bit-rate in worst cases any encoder will do below things. If its not possible with below settings we need to increase the bit-rate.  I guess you are setting encoder with 60fps which even degrades the quality to achieve the bit-rate. 

    1 - use maximum QP = 51

    2 - use frameskips for P frames

    Regards

    Gajanan

  • Hi Gajanan & Margarita,

    I have tried all the settings suggested you both. but none of them helped us to resolved the issue.
    so we planned to reduce the FPS (example 15 FPS), but if i set the lower FPS then the output bitrate goes
    higher than the full fps bitrate.

    Can you please help us to resolve the issue.

    Thanks a lot for your help.

    Regards
    R.Abdul Rahman