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.

Dynamic bitrate configuration

Hi,

Im working on a h.264 encoder based application on DM8168 where i need to change bitrate dynamically. I have referred to TI's user guide for this and lot of posts but I'm not able to achieve this.

Here's what I'm doing in a nutshell -

{

OMX_VIDEO_CONFIG_DYNAMICPARAMS tDynParams;

<some initialization here>

OMX_GetConfig(enc_comp, OMX_TI_IndexConfigVideoDynamicParams, &tDynParams);

tDynParams.videoDynamicParams.h264EncDynamicParams.\
videnc2DynamicParams.targetBitRate =  <my_target_bitrate>;

OMX_SetConfig(enc_comp, OMX_TI_IndexConfigVideoDynamicParams, &tDynParams);

...

}

This does not give any error

I have collected logs from loggerDump also. Below is snippet of what it shows - 

...

N:Video P:1 #:05345 T:000006fb86551235 M:xdc.runtime.Main S:OMX_TI_VIDENC_Process::Line 5089::VENC->Before VIDENC2_control XDM_SETPARAMS
N:Video P:1 #:05348 T:000006fb865a8023 M:xdc.runtime.Main S:OMX_TI_VIDENC_Process::Line 5112::VENC->VIDENC2_control XDM_SETPARAMS Successful
N:Video P:1 #:05349 T:000006fb865b6f97 M:xdc.runtime.Main S:OMX_TI_VIDENC_Process::Line 5130::VENC->VIDENC2_control XDM_GETSTATUS Successful
N:Video P:1 #:05350 T:000006fb865bf76b M:xdc.runtime.Main S:OMX_TI_VIDENC_Process::Line 5145::VENC->VIDENC2_control XDM_SETPARAMS Complete
N:Video P:1 #:05351 T:000006fb865da075 M:xdc.runtime.Main S:OMX_TI_VIDENC_Process::Line 5257::VENC->First VIDENC2_process after VIDENC2_control:XDM_SETPARAMS command

...

Again, no error reported

But what I'm seeing is that the bitrate change is not taking effect, except for the first time. 

Can anyone let me know if this behaviour is expected or is there any way around this

I'm using EZSDK v5_05_02_00

Regards,

Manu

  • Hello,

    I would recommend you to check h264 user guide and .

    Are you setting CBR or VBR?

    Could you post the encoder setting that you are using?

    BR
    Margarita

  • Hi Margarita,

    I have looked into the user guide and the wiki also. The info in Wiki is not fully applicable for ezsdk 5.05.02.00 (I need to use OMX_getConfig and OMX_setConfig instead of OMX_get/setParameter. Otherwise the OMX component throws error)

    I have the following settings -  

    1. encodingPreset = XDM_USER_DEFINED,

    2. rateControlPreset = IVIDEO_USER_DEFINED

    3. rateControlParams.rateControlParamsPreset  = IH264_RATECONTROLPARAMS_USERDEFINED;

    4. rateControlParams.rcAlgo = IH264_RATECONTROL_PRC; (For VBR and interlaced modes)

        rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY; (For progressive CBR mode)

    (In short, I have tried both CBR and VBR)

    Please find the encoder configurations in the file attached 

    constraintSetFlags              :0
    interlaceCodingType             :3
    bottomFieldIntra                :1
    gopStructure                    :0
    entropyCodingMode               :1
    transformBlockSize              :2
    log2MaxFNumMinus4               :c
    picOrderCountType               :0
    IDRFrameInterval                :1
    pConstantMemory             	:0
    maxIntraFrameInterval           :7fffffff
    debugTraceLevel             	:0
    lastNFramesToLog                :0
    enableAnalyticinfo              :0
    enableGMVSei                    :0
    enableRCDO                  	:0
    enableLongTermRefFrame          :0
    LTRPPeriod                      :0
    numTemporalLayer                :1
    referencePicMarking             :0
    
    
     intra coding params
    Intra coding preset                         :0
    Luma Intra Block size4x4                    :0
    Luma Intra Block size8x8                    :ff
    Luma Intra Block size16x16                  :f
    Chroma Intra Block size8x8                  :f
    chromaComponentEnable                       :1
    intraRefreshMethod                          :0
    intraRefreshRate                            :0
    gdrOverlapRowsBtwFrames                     :0
    constrainedIntraPredEnable                  :0
    intraCodingBias                             :0
    
    
     inter coding params
    Inter coding preset                         :0
    Inter Block size                            :0
    Inter Block sizeB                           :0
    searchRangeHorP                             :0
    searchRangeVerP                             :0
    interCodingBias                             :1
    skipMVCodingBias                            :1
    meAlgoMode                                  :0
    Level                    					:2a
    Profile                    					:64
    Entropy coding mode                         :1
    
    
     LOOP filter params
    loopfilterPreset:                            0
    filterOffsetA:                               0
    filterOffsetB:                               0
    
    
     Flexible Macroblock Ordering params
    fmoCodingPreset:                            0
    numSliceGroups:                             1
    sliceGroupMapType:                          4
    sliceGroupChangeDirectionFlag:              0
    sliceGroupChangeRate:                       0
    sliceGroupChangeCycle:                      0
    
    
     video usability info
    vuiCodingPreset:                            1
    aspectRatioInfoPresentFlag:                 0
    aspectRatioIdc:                             0
    videoSignalTypePresentFlag:                 0
    videoFormat:                                2
    videoFullRangeFlag:                         0
    timingInfoPresentFlag:                      1
    hrdParamsPresentFlag:                       0
    numUnitsInTicks:                            3e8
    
    
     Stereo info params
    stereoInfoPreset:                            0
    topFieldIsLeftViewFlag:                      0
    viewSelfContainedFlag:                       0
    
    
     frame packing SEI params
    framePackingPreset:                             0
    framePackingType:                               0
    frame0PositionX:                                0
    frame0PositionY:                                0
    reservedByte:                                   0
    
    
     SVC params
    svcExtensionFlag:                            0
    dependencyID:                                0
    qualityID:                                   0
    enhancementProfileID:                        0
    layerIndex:                                  0
    refLayerDQId:                                0
    
    
    
     Default DYNAMIC PARAMS:
    video enc2 dynamic params
    videnc2DynamicParams.inputHeight:              438
    videnc2DynamicParams.inputWidth:               780
    videnc2DynamicParams.refFrameRate:             ea60
    videnc2DynamicParams.targetFrameRate:          7530
    videnc2DynamicParams.targetBitRate:       	   b71b00
    videnc2DynamicParams.intraFrameInterval:       258
    videnc2DynamicParams.generateHeader:           0
    videnc2DynamicParams.captureWidth:          	780
    videnc2DynamicParams.forceFrame:           		ffffffff
    videnc2DynamicParams.interFrameInterval:           		1
    videnc2DynamicParams.mvAccuracy:           				2
    videnc2DynamicParams.sampleAspectRatioHeight:           1
    videnc2DynamicParams.sampleAspectRatioWidth:           	1
    
    
     rate control params
    R C params Preset:                              1
    Scaling Matrix Preset:                          0
    rcAlgo:                                         1
    init_qp_I:                                      10
    max_qp_I:                                       33
    min_qp_I:                                       10
    init_qp_P:                                      10
    max_qp_P:                                       33
    min_qp_P:                                       10
    offset_qp_B:                                    0
    max_qp_B:                                       33
    min_qp_B:                                       10
    allow_Frame_Skip:                               0
    remove_Expensive_Coeff:                         0
    chroma_QPIndex_Offset:                          0
    IP_Quality_Factor:                              0
    initial_Buffer_Level:                           16e360
    HRD buffer size:                                2dc6c0
    min_Pic_Size_Ratio I:                           2
    max_Pic_Size_Ratio I:                           2
    min_Pic_Size_Ratio P:                           2
    max_Pic_Size_Ratio P:                           2
    PRC enable:                                     1
    Partial Frame Skip enable:                      0
    discard Saved Bits:                             0
    reserved:                                       0
    VBRDuration:                                    0
    VBRsensitivity:                                 0
    skipDistributionWindowLength:                   0
    numSkipInDistributionWindow:                    0
    enableHRDComplianceMode:                        0
    frameSkipThMulQ5:                               0
    vbvUseLevelThQ5:                                0
    
    
     inter coding params
    inter Coding Preset:                            0
    search Range Hor P:                             0
    search Range Ver P:                             0
    search Range Hor B:                             0
    search Range Ver P:                             0
    inter Coding Bias:                              1
    skip MV Coding Bias:                            1
    min Block Size P:                               0
    min Block Size B:                               0
    meAlgoMode:                                     0
    
    
     Intra coding preset                         	:0
    Luma Intra Block size4x4                    	:0
    Luma Intra Block size8x8                    	:0
    Luma Intra Block size16x16                  	:0
    Chroma Intra Block size8x8                  	:0
    chromaComponentEnable                           :0
    intraRefreshMethod                              :0
    intraRefreshRate                                :0
    gdrOverlapRowsBtwFrames                         :0
    constrainedIntraPredEnable                      :0
    intraCodingBias                                 :0
    slice coding params
    slice Coding Preset:                            1
    slice Mode:                                     1
    slice Unit Size:                                5a0
    slice start offset:                             0
    stream Format:                                  0
    Slice Group Change Cycle:                       0
    search Center:                                  0
    enable Static MB Count:                         0
    reserved Dynamic Params:                        56e1812c
    enableROI:                                      0
    Port Index:                                     1
    Version:                                        101
    Size:                                           f8

    Additionally, the forceFrame parameter (for force inserting key frames) is taking effect and it is being triggered similar to bitrate change

    Regards,

    Manu

  • Hello,

    I do not see the setting for params like HRDBufferSize and initialBufferLevel .

    Could you set these as well.


    BR
    Margarita

  • Hi,

    In my last post I have might have missed a few configurations. I'm setting the HRD buffer parameters. The values are -

    rateControlParams.initialBufferLevel= 10000000; //decimal value
    rateControlParams.HRDBufferSize = 10000000;

    Regards,
    Manu
  • Hello Manu,

    The HRDBufferSize is 2*targetBitRate for VBR  and 1⁄2*targetBitRate  for CBR. This values should be set depending of the targetbitrate that you are setting.

    I would recommend you to check is it the dynamic change of bitrate is applied for CBR. For VBR the target bitrate will depend on the video stream that you are encoding. This means that for complex video scenes the bit rate will try to reach the target bit that you are setting.

    BR

    Margarita

  • Hi Margarita,

    Thank you very much for the answer!! I'm able to see the dynamic change in bitrate with the change you suggested

    I have confirmed this behavior for both CBR and VBR modes. One thing I did not understand is that both 2xtargetBitRate and 1/2xtargetBitRate seem to be working for both CBR and VBR. My question is whether only 2x and 1/2x factors are supported or is it that I have to maintain the ratio of targetBitrate to HRDBufferSize whenever I change bitrate (even if the ratio is not 2x or 1/2x)

    Regards,
    Manu
  • Hello Manu,

    The HDRBufferSize is the buffer size this size controls the frame skip logic of the encoder.For low delay applications this size should be
    small. The initialBufferLevel should be same as the HDRBufferSize. InitialBuffer is Initial buffer level for HRD compliance. It informs
    thatencoder can start depending on the fullness of the HRD buffer. For the VBR this value shall be 2*targetbitrate per encoder user guide. For CBR is 1/2 of the target bit rate. These values is the default the max size of HDRBufferSize could be any value which is level compliant.
    Per the user guide the initalBufferLevel max value could be Any value between –(2^31 -10^8) to (2^31 -10^8). You could check in the H264 encoder user guide for more information.
    One more point when the CBR is set I would recommend you to set the IH264ENC_NALUControlParams control mask especially in use case of higher resolution->lower bitrate.

    BR
    Margarita

  • Margarita,

    Thanks for the info. This is very helpful

    Regards
    Manu
  • If you need further details let us know.

    BR
    Margarita