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.

TMS320C6678: H264 Encoder configuration issues

Part Number: TMS320C6678

Hi

I'm trying to configure the H264 encoder on the C6678 for low bitrate operation.

using the latest version (1.0.3)

My video resolution is 320x240, very simple image, no motion.

configured for 50kbps

I've tried both CBR and VBR but the result is always the same -> outputting close to 250kbps regardless of my setting of rcalgo, targetbitrate, ratecontrol preset, initial QI , initial QP. 

1. is there a newer version of this encoder (1.0.3 is from 2015)?

2. Does this encoder support low bitrates (sub 64kbps)?

3. is there some other parameter that I might be missing?

Thanks

  • Hi Dhar, could you please send all the configuration parameters you are using? I recall we have rcAlgo parameters which could be CBR without Frames Skip.. this could be the reason low bit rate couldn't be achieved.

    I found below information in my notes. Maybe actual number assignation for rcAlgo changed in H264HP_E 01_00_03_00, so please double check. Below information is just to give you an idea of a possible reason.

    rcAlgo =>
    0: Variable Bitrate,
    1 : Constant bitrate (low dealy),
    2: Constrained CBR (No Frame Skips),
    3:Constrained CBR (No Frame Skips with no scene change detection)

    thank you,
    Paula
  • Hi
    Here are the config values I use, any other config parameters are as per default:

    gConfig.nCores = 1;
    gConfig.coreTeamMap[0] = '0';
    gConfig.encodingPreset = 2;// # encoding preset 0: DEFAULT, 1: HIGH_QUALITY, 2: HIGH_SPEED, 3:USER_DEFINED
    gConfig.rateControlPreset = 5;// # 5: IVIDEO_USER_DEFINED, 4: IVIDEO_NONE, 2: IVIDEO_STORAGE, 1: IVIDEO_LOW_DELAY
    gConfig.maxWidth = 1920;// # Max Frame width
    gConfig.maxHeight = 1088;// # Max Frame height
    gConfig.inputChromaFormat = 1;// # 1 => XDM_YUV_420P, Only 1 is supported.
    gConfig.inputContentType = 0;// # Input buffer content type, 0 -> Progressive Type, 1-> Interlaced.
    gConfig.mvAccuracy = 2;//# Pixel accuracy of the motion vector, 0 => integer pel 2=> quarter pel
    gConfig.generateHeader = 0;// # 1: Encode only header, 0: Encode entire access unit, including the headers
    gConfig.forceFrame = -1 ;//# -1: IVIDEO_NA_FRAME, 3: IVIDEO_IDR_FRAME
    gConfig.dataLayout = 0 ;
    gConfig.sampleAspectRatioHeight = 1 ;//# Aspect Ratio Height
    gConfig.sampleAspectRatioWidth = 1 ;//# Aspect Ratio Width
    gConfig.rateControlParamsPreset = 1;
    gConfig.qpI = 25;// # Initial QP for I/IDR frames, -1 indicates codec chosen
    gConfig.qpP = 25;// # Initial QP for P frames
    gConfig.qpOffsetB = 4;// # Offset of B frames QP from P frames
    gConfig.CbQPIndexOffset = 0 ;//# Specifies offset to be added to luma QP for addressing QPC values table for Cb components
    gConfig.CrQPIndexOffset = 0 ;//# Specifies offset to be added to luma QP for addressing QPC values table for Cr components
    gConfig.initialBufferLevel = basic_encoder_params.targetBitRate*2 ;
    gConfig.HRDBufferSize = basic_encoder_params.targetBitRate*2 ;
    gConfig.enablePRC = 1;// # Control Flag to enable MB level Perceptual Rate Control, 0 => Disable, 1 => Enable
    gConfig.frameSkipAfterSceneChange = 1;
    gConfig.scalingMatrixPreset = 0 ;
    gConfig.suppressHighFreqCoeffs = 0 ;
    gConfig.interCodingPreset = 1 ;//# Inter coding mode preset, 0 => deafult values, 1 => user defined
    gConfig.MvRangeVerP = 32 ;// # Vertical Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496
    gConfig.MvRangeHorP = 144;// # Horizontal Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496
    gConfig.MvRangeVerB = 32 ;// # Vertical Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496
    gConfig.MvRangeHorB = 144 ;//# Horizontal Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496
    gConfig.maxMVperMB = 4 ;//# Maximum MV per MB (Values of 1 & 4 are valid)
    gConfig.intraCodingPreset = 1 ;//# Intra coding mode preset, 0 => deafult values, 1 => user defined
    gConfig.enableIntraPartition = 4 ;
    gConfig.intraRefreshMethod = 0 ;//# IH264_INTRAREFRESH_NONE = 0, IH264_INTRAREFRESH_CYCLIC_MBS = 1
    gConfig.intraRefreshRate = 0 ;
    gConfig.constrainedIntraPredEnable = 0;// # Controls the intra macroblock coding in inter slices
    gConfig.entropyCodingMode = 0;// # Enropy coding type, (0 => CAVLC, 1 => CABAC)

    gConfig.sliceCodingPreset = 0 ;//# Preset value for slice coding mode, 0 => deafult values, 1 => user defined
    gConfig.streamFormat = 0;// # Type of bitstream to be encoded, 0 => Byte stream format, 1=> NALU format(without start code)
    gConfig.sliceMode = 0 ;
    gConfig.sliceUnitSize = 1200 ;//# Number of macroblocks per slice
    gConfig.loopfilterPreset = 1 ;//# Preset value for loop filter operation parameters, 0 => default values, 1 => user defined
    gConfig.loopfilterDisableIDC = 2 ;//# Disable H.264 loop filter, (0=Filter, 1= NoFilter, 2 = No loop filter across slices)
    gConfig.filterOffsetA = 0 ;//# Alpha offset for loop filter
    gConfig.filterOffsetB = 0 ;//# Beta offset for loop filter
    gConfig.vuiCodingPreset = 1;// # Preset value for VUI Control Params, 0 => deafult values, 1 => user defined
    gConfig.aspectRatioInfoPresentFlag = 1 ;//# Controls the insertion of aspect ratio information in VUI part of bit-stream
    gConfig.aspectRatioIdc = 1 ;//# Aspect ratio ID
    gConfig.videoSignalTypePresentFlag = 0 ;//# controls the insertion of video signal type in VUI part of bit-stream
    gConfig.videoFormat = 2 ;//# Video signal type
    gConfig.videoFullRangeFlag = 0 ;//# Flag to specigy Range of the pixels
    gConfig.colourDescriptionPresentFlag = 1 ;
    gConfig.colourPrimaries = 5;// # chromaticity coordinates of the source primaries(Table E-3 in standard)
    gConfig.transferCharacteristics = 5;// # opto-electronic transfer characteristic of the source picture(Table E-4 in standard)
    gConfig.matrixCoefficients = 5;
    gConfig.timingInfoPresentFlag = 1;// # Controls the insertion of timing info related parameters in VUI part of bit-stream
    gConfig.gopStructure = 0 ;//# GOP structure, 0 => Open or Non uniform(IBBPBBP), 1 => Closed or Uniform (BBIBBPBB)
    gConfig.log2MaxFNumMinus4 = 0;
    gConfig.picOrderCountType = 0 ;// # Picture order count type
    gConfig.transformBlockSize = 0 ;// # Tranform type, 0:4x4 only, 1: 8x8 only - 4x4 for BP, 8x8 for HP
    gConfig.topFieldFirstFlag = 1 ;// # Flag to indicate field order in interlaced content
    gConfig.interlaceCodingType = 4 ;//# Interlced field coding type selection, 2 => MRF 3=> ARF 4=> SPF
    gConfig.debugTraceLevel = 0 ;//# Debug trace Enable 0 - Disable, 1- Level1, 2 - Level2, 3 - Level3,
    gConfig.lastNFramesToLog = 5 ;//# Last N frames to log into debug trace buffer

    gConfig.maxInterFrameInterval = 1;
    gConfig.profile = 66; // = 66;// # Encoding profile 100 => HP, 77 => MP, 66 => BP.
    gConfig.level = 40; // = 40;// # Level IDC (e.g. 20 = level 2.0)
    gConfig.inputWidth = 352; // = 352;// # width of image
    gConfig.inputHeight = 240; // = 240;// # Height of image
    gConfig.targetFrameRate = 30000;
    gConfig.targetBitRate = 50000;// # Target Bit Rate in Bits per second.
    gConfig.intraFrameInterval = 15;
    gConfig.interFrameInterval = 1;
    gConfig.qpMaxI = 35;// # was 51 Maximum QP for I/IDR frames
    gConfig.qpMinI = 1;// # Minimum QP for I/IDR frames
    gConfig.qpMaxP = 35;// # was 51 Maximum QP for P frames
    gConfig.qpMinP = 1;// # Minimum QP for P frames
    gConfig.qpMaxB = 51 ;//# Maximum QP for B frames
    gConfig.qpMinB = 1 ;//# Minimum QP for B frames
    gConfig.rcAlgo = 0;
    gConfig.IDRFrameInterval = 2;




    I've tried with rcAlgo at 0 and 1
    I've tried different values for HRDbufferize

    single core, Base profile, level 4.0


    What I see is the encoder quickly move towards qpMin and stays there. So whatever I set for qpMinI and qpMinP is where it ends up encoding.

    Thanks
    Dhar
  • Hi Dhar, could you please try

    gConfig.entropyCodingMode = 1;// # Enropy coding type, (0 => CAVLC, 1 => CABAC)
    gConfig.qpMaxI = 51;// # was 51 Maximum QP for I/IDR frames
    gConfig.qpMinI = 1;// # Minimum QP for I/IDR frames
    gConfig.qpMaxP = 51;// # was 51 Maximum QP for P frames
    gConfig.qpMinP = 1;// # Minimum QP for P frames
    gConfig.qpMaxB = 51 ;//# Maximum QP for B frames
    gConfig.qpMinB = 1 ;//# Minimum QP for B frames
    gConfig.rcAlgo = 1;

    Let us know if this helps.

    thank you,
    Paula
  • Hi

    CABAC is only possible if you are configured for High Profile. 

    I tried High Profile with CABAC entropy encoding and the Min and Max Q values as you suggested and the result is the same.

    I also tried changing the initial Q values to -1, again no effect.

    I've tried changing the rateControlpreset from 5 to 1 or 2 and still no effect.

    as an aside

    Running  B frames (in HIGH PROFILE) will cause the B frames to be encoded with a different quantization than the rest of the frame. This might offer a clue to what is happening.

    Thanks

    Dhar

  • Hi Dhar, yes HP, CABAC and B frames, and Skip frames are to way to go in order to achieve high compression (low bit-rate).

    A question, have you tried to encode the same clip with a reference encoder with similar configuration params? if so, have you been able to get sub 64Kbps bitstreams?

    Maybe we can give a try attached params?

    gConfig.nCores = 1;
     gConfig.coreTeamMap[0] = '0';
     gConfig.encodingPreset = 3;// # encoding preset 0: DEFAULT, 1: HIGH_QUALITY, 2: HIGH_SPEED, 3:USER_DEFINED
     gConfig.rateControlPreset = 5;// # 5: IVIDEO_USER_DEFINED, 4: IVIDEO_NONE, 2: IVIDEO_STORAGE, 1: IVIDEO_LOW_DELAY
     gConfig.maxWidth = 352;// # Max Frame width
     gConfig.maxHeight = 240;// # Max Frame height
     gConfig.inputChromaFormat = 1;// # 1 => XDM_YUV_420P, Only 1 is supported.
     gConfig.inputContentType = 0;// # Input buffer content type, 0 -> Progressive Type, 1-> Interlaced.
     gConfig.mvAccuracy = 2;//# Pixel accuracy of the motion vector, 0 => integer pel 2=> quarter pel
     gConfig.generateHeader = 0;// # 1: Encode only header, 0: Encode entire access unit, including the headers
     gConfig.forceFrame = -1 ;//# -1: IVIDEO_NA_FRAME, 3: IVIDEO_IDR_FRAME
     gConfig.dataLayout = 0 ;
     gConfig.sampleAspectRatioHeight = 1 ;//# Aspect Ratio Height
     gConfig.sampleAspectRatioWidth = 1 ;//# Aspect Ratio Width
     gConfig.rateControlParamsPreset = 1;
     gConfig.qpI = -1;// # Initial QP for I/IDR frames, -1 indicates codec chosen
     gConfig.qpP = -1;// # Initial QP for P frames
     gConfig.qpOffsetB = 4;// # Offset of B frames QP from P frames
     gConfig.CbQPIndexOffset = 0 ;//# Specifies offset to be added to luma QP for addressing QPC values table for Cb components
     gConfig.CrQPIndexOffset = 0 ;//# Specifies offset to be added to luma QP for addressing QPC values table for Cr components
     gConfig.initialBufferLevel = basic_encoder_params.targetBitRate*2 ;
     gConfig.HRDBufferSize = basic_encoder_params.targetBitRate*2 ;
     gConfig.enablePRC = 1;// # Control Flag to enable MB level Perceptual Rate Control, 0 => Disable, 1 => Enable
     gConfig.frameSkipAfterSceneChange = 1;
     gConfig.scalingMatrixPreset = 0 ;
     gConfig.suppressHighFreqCoeffs = 1 ;
     gConfig.interCodingPreset = 1 ;//# Inter coding mode preset, 0 => deafult values, 1 => user defined
     gConfig.MvRangeVerP = 32 ;// # Vertical Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496
     gConfig.MvRangeHorP = 144;// # Horizontal Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496
     gConfig.MvRangeVerB = 32 ;// # Vertical Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496
     gConfig.MvRangeHorB = 144 ;//# Horizontal Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496
     gConfig.maxMVperMB = 4 ;//# Maximum MV per MB (Values of 1 & 4 are valid)
     gConfig.intraCodingPreset = 1 ;//# Intra coding mode preset, 0 => deafult values, 1 => user defined
     gConfig.enableIntraPartition = 4 ;
     gConfig.intraRefreshMethod = 0 ;//# IH264_INTRAREFRESH_NONE = 0, IH264_INTRAREFRESH_CYCLIC_MBS = 1
     gConfig.intraRefreshRate = 0 ;
     gConfig.constrainedIntraPredEnable = 0;// # Controls the intra macroblock coding in inter slices
     gConfig.entropyCodingMode = 1;// # Enropy coding type, (0 => CAVLC, 1 => CABAC)
    
     gConfig.sliceCodingPreset = 0 ;//# Preset value for slice coding mode, 0 => deafult values, 1 => user defined
     gConfig.streamFormat = 0;// # Type of bitstream to be encoded, 0 => Byte stream format, 1=> NALU format(without start code)
     gConfig.sliceMode = 0 ;
     gConfig.sliceUnitSize = 1200 ;//# Number of macroblocks per slice
     gConfig.loopfilterPreset = 1 ;//# Preset value for loop filter operation parameters, 0 => default values, 1 => user defined
     gConfig.loopfilterDisableIDC = 2 ;//# Disable H.264 loop filter, (0=Filter, 1= NoFilter, 2 = No loop filter across slices)
     gConfig.filterOffsetA = 0 ;//# Alpha offset for loop filter
     gConfig.filterOffsetB = 0 ;//# Beta offset for loop filter
     gConfig.vuiCodingPreset = 1;// # Preset value for VUI Control Params, 0 => deafult values, 1 => user defined
     gConfig.aspectRatioInfoPresentFlag = 1 ;//# Controls the insertion of aspect ratio information in VUI part of bit-stream
     gConfig.aspectRatioIdc = 1 ;//# Aspect ratio ID
     gConfig.videoSignalTypePresentFlag = 0 ;//# controls the insertion of video signal type in VUI part of bit-stream
     gConfig.videoFormat = 2 ;//# Video signal type
     gConfig.videoFullRangeFlag = 0 ;//# Flag to specigy Range of the pixels
     gConfig.colourDescriptionPresentFlag = 1 ;
     gConfig.colourPrimaries = 5;// # chromaticity coordinates of the source primaries(Table E-3 in standard)
     gConfig.transferCharacteristics = 5;// # opto-electronic transfer characteristic of the source picture(Table E-4 in standard)
     gConfig.matrixCoefficients = 5;
     gConfig.timingInfoPresentFlag = 1;// # Controls the insertion of timing info related parameters in VUI part of bit-stream
     gConfig.gopStructure = 0 ;//# GOP structure, 0 => Open or Non uniform(IBBPBBP), 1 => Closed or Uniform (BBIBBPBB)
     gConfig.log2MaxFNumMinus4 = 0;
     gConfig.picOrderCountType = 0 ;// # Picture order count type
     gConfig.transformBlockSize = 1 ;// # Tranform type, 0:4x4 only, 1: 8x8 only - 4x4 for BP, 8x8 for HP
     gConfig.topFieldFirstFlag = 1 ;// # Flag to indicate field order in interlaced content
     gConfig.interlaceCodingType = 4 ;//# Interlced field coding type selection, 2 => MRF 3=> ARF 4=> SPF
     gConfig.debugTraceLevel = 0 ;//# Debug trace Enable 0 - Disable, 1- Level1, 2 - Level2, 3 - Level3,
     gConfig.lastNFramesToLog = 5 ;//# Last N frames to log into debug trace buffer
    
     gConfig.maxInterFrameInterval = 3;
     gConfig.profile = 100; // = 66;// # Encoding profile 100 => HP, 77 => MP, 66 => BP.
     gConfig.level = 40; // = 40;// # Level IDC (e.g. 20 = level 2.0)
     gConfig.inputWidth = 352; // = 352;// # width of image
     gConfig.inputHeight = 240; // = 240;// # Height of image
     gConfig.targetFrameRate = 30000;
     gConfig.targetBitRate = 50000;// # Target Bit Rate in Bits per second.
     gConfig.intraFrameInterval = 15;
     gConfig.interFrameInterval = 3;
     gConfig.qpMaxI = 51;// # was 51 Maximum QP for I/IDR frames
     gConfig.qpMinI = 1;// # Minimum QP for I/IDR frames
     gConfig.qpMaxP = 51;// # was 51 Maximum QP for P frames
     gConfig.qpMinP = 1;// # Minimum QP for P frames
     gConfig.qpMaxB = 51 ;//# Maximum QP for B frames
     gConfig.qpMinB = 1 ;//# Minimum QP for B frames
     gConfig.rcAlgo = 2;
     gConfig.IDRFrameInterval = 0;

    let us know your results.. if QPs are still not changing please attach your output .264 clip

    thank you,

    Paula

  • Hi

    Those setting appear to work a little better, however there are still a few issues.

    1. With the Constrained Bit Rate setting I was expecting to see the output bit rate closer to the target bit rate, currently it's running about 30%-50% above.

    2. I'm attaching a small encoded file which shows what appears to be an issue with transitioning from a B frame to an I frame. My settings are Intra interval 15, inter interval 3, IDR interval 2, 30fps. I don't know what is going on there, but it seems like the I frames are encoded with different quantization from the B frames. 

    3. What does this parameter do - qpOffsetB = 4 ?  (I tried changing to 0 but no apparent effect).

    Thanks

    Dhar

    200kbps_79frames.zip

  • Hi Dhar, let me attach you a configuration doc, which has a little bit more details on the options.

    As you can see there,  qpOffsetB is for defining and extra QP offset between P and B frames. In other words, QP between type of frames is different. So if you see differences between QPs in I and B (as mentioned above) I won't be surprise.

    H264enc_params_example.cfg

    Also, do you really need IDR frames every to I frames? IDR are bigger than I-frames..

    thank you,

    Paula

  • Hi

    I had switched to baseline profile with CAVLC entropy because of performance issues. I can work around that as long as the HP works ok. The issue I have is that in order to get the targetBitRate parameter to work I need to enable B frames. With B frames in the stream the stored file is not played properly. It looks like the B frames are either not decoded or displayed in the correct order.

    my config includes:

    timingInfoPresentFlag = 1

    picOrderCountType = 0 

    Thanks

    Dhar

  • Hi Dhar, could you please send me a clip that shows the issue with B-frames? Your previously attached one played correctly in Elecard StreamEye analyzer

    thank you,
    Paula
  • Hi

    please see attached file

    Apart from not playing properly I see a couple of things in the file that I don't understand.

    timingInfoPresentFlag is 0 (while I have it set to 1 in my config)

    frame_num is 0 for all frames

    Thanks

    Dhar

    bigbuck300kbps.zip

  • Hi Dhar, which decoder are you using? I tested your clip with Elecard StreamEye analyzer and it plays correctly. However, VLC decodes with wrong picture order.

    Could you please also attached configuration params used for bigbuck300kps clip?

    I will ask our video experts to see if there is anything else missing here...

    Finally for a quick test could you try:

    Option1
    - IDRFrameInterval = 0; 0 # Interval b/w two IDR frames 0=>IDR BBP I BBP I, 1=>IDR BBP IDR BBP IDR, 2=>IDR BBP I BBP IDR, 3=>IDR BBP I BBP I BBP IDR
    - gopStructure = 0; gopStructure = 0 # GOP structure, 0 => Open or Non uniform(IBBPBBP), 1 => Closed or Uniform (BBIBBPBB)

    Option2
    - IDRFrameInterval = 1; 0 # Interval b/w two IDR frames 0=>IDR BBP I BBP I, 1=>IDR BBP IDR BBP IDR, 2=>IDR BBP I BBP IDR, 3=>IDR BBP I BBP I BBP IDR
    - gopStructure = 1; gopStructure = 0 # GOP structure, 0 => Open or Non uniform(IBBPBBP), 1 => Closed or Uniform (BBIBBPBB)

    If I recall correctly in open GOP B-frames can search for reference before their I-frame, then IDRFrameInterval has to be 0. .

    thank you,
    Paula
  • Hi

    I used ffplay, vlc and windows media player, they all show the same issue.

    Both option 1 and option 2 you suggested above display the same problem.

    Attached is my config (please note that encoding preset of 2 and 3 also show the same problem).

    Of Note:

    timingInfoPresentFlag = 1 in config, timingInfoPresentFlag = 0 in output stream

    frame_num always 0 in output stream

    Thanks

    Dhar

    	gConfig.nCores = 1;
    	gConfig.coreTeamMap[0] = '0';
    	gConfig.encodingPreset        	= 2;// # encoding preset 0: DEFAULT, 1: HIGH_QUALITY, 2: HIGH_SPEED, 3:USER_DEFINED
    	gConfig.rateControlPreset     	= 5;// # 5: IVIDEO_USER_DEFINED, 4: IVIDEO_NONE, 2: IVIDEO_STORAGE, 1: IVIDEO_LOW_DELAY
    
    	gConfig.maxWidth              	= 1920;// # Max Frame width
    	gConfig.maxHeight             	= 1088;// # Max Frame height
    	gConfig.inputChromaFormat     	= 1;// # 1 => XDM_YUV_420P, Only 1 is supported.
    	gConfig.inputContentType      	= 0;// # Input buffer content type, 0 -> Progressive Type, 1-> Interlaced.
    	gConfig.mvAccuracy          	= 2 ;//# Pixel accuracy of the motion vector, 0 => integer pel 2=> quarter pel
    	gConfig.generateHeader        	= 0;// # 1: Encode only header, 0: Encode entire access unit, including the headers
    	gConfig.forceFrame            	= -1 ;//# -1: IVIDEO_NA_FRAME, 3: IVIDEO_IDR_FRAME
    	gConfig.dataLayout            	= 0 ;//# input data buffer layout 0=> interleaved, 1=> seprated. Only 0 is supported and applicable only for interlace content.
    	gConfig.sampleAspectRatioHeight = 1 ;//# Aspect Ratio Height
    	gConfig.sampleAspectRatioWidth  = 1 ;//# Aspect Ratio Width
    
    	gConfig.rateControlParamsPreset = 1;// # Preset value for selecting rate control params, 0: default (other parameters in this category will be decided by Codec internally), 1: user defined
    	gConfig.qpI                     = -1;// # Initial QP for I/IDR frames, -1 indicates codec chosen
    	gConfig.qpP                     = -1;// # Initial QP for P frames
    	gConfig.qpOffsetB               = 4;// # Offset of B frames QP from P frames
    	gConfig.CbQPIndexOffset         = 0 ;//# Specifies offset to be added to luma QP for addressing QPC values table for Cb components
    	gConfig.CrQPIndexOffset         = 0 ;//# Specifies offset to be added to luma QP for addressing QPC values table for Cr components
    	gConfig.initialBufferLevel      = 2000000 ;//# Initial Buffer level for HRD compliance, keep same as HRDBufferSize for best quality
    	gConfig.HRDBufferSize           = 2000000 ;//# Hypothetical Reference Decoder Buffer Size in bits - 2*bitrate for VBR
    	gConfig.enablePRC               = 1;// #  Control Flag to enable MB level Perceptual Rate Control, 0 => Disable, 1 => Enable
    	gConfig.frameSkipAfterSceneChange = 0;// # 0=> no forced skip after scenechange, 1 => force skip frame after coding scene change frame.
    	gConfig.scalingMatrixPreset      = 0 ;//# Scaling Matrix selection of encoder, 0: no scaling matrices, 1: normal, 2: noisy, 3 : standard default, 4 : user defined
    	gConfig.suppressHighFreqCoeffs  = 1 ;//#0=> No High Freq Suppression #1=>Adaptively enabled only for noise streams when Qp reaches it max & suppression for more than half of the coeffs 2 => Enabled for all streams when Qp reaches it max & suppression for half of the coeffs 3 => Enabled for all streams when Qp reaches it max & suppression for more than half of the coeffs
    
    	gConfig.interCodingPreset    = 1 ;//# Inter coding mode preset, 0 => deafult values, 1 => user defined
    	gConfig.MvRangeVerP          = 32 ;// # Vertical Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496
    	gConfig.MvRangeHorP          = 144;// # Horizontal Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496
    	gConfig.MvRangeVerB          = 32 ;// # Vertical Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496
    	gConfig.MvRangeHorB          = 144 ;//# Horizontal Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496
    	gConfig.maxMVperMB           = 4 ;//# Maximum MV per MB (Values of 1 & 4 are valid)
    
    	gConfig.intraCodingPreset             = 1 ;//# Intra coding mode preset, 0 => deafult values, 1 => user defined
    	gConfig.enableIntraPartition          = 4 ;//# 0 => INTRA_PARTITION_NONE , 1 => INTRA_PARTITION_ISLICES, 2 => INTRA_PARTITION_IPSLICES, 3 => INTRA_PARTITION_IBSLICES, 4 => INTRA_PARTITION_IPBSLICES.
    	gConfig.intraRefreshMethod            = 0 ;//# IH264_INTRAREFRESH_NONE  = 0, IH264_INTRAREFRESH_CYCLIC_MBS = 1
    	gConfig.intraRefreshRate              = 0 ;//# Rate at which intra MB Refresh is done. e.g. 10 indicates every 10th MB will coded as Intra in inter pictures.
    	gConfig.constrainedIntraPredEnable    = 0;// # Controls the intra macroblock coding in inter slices
    
    	gConfig.entropyCodingMode               = 1;// # Enropy coding type, (0 => CAVLC, 1 => CABAC)
    
    	gConfig.sliceCodingPreset            = 0 ;//# Preset value for slice coding mode, 0 => deafult values, 1 => user defined
    	gConfig.streamFormat                 = 0;// # Type of bitstream to be encoded, 0 => Byte stream format, 1=> NALU format(without start code)
    	gConfig.sliceMode                    = 0 ;//# Type of slice coding, 0 => slice coding mode is frame based, 1 => Slices are controlled based upon number of Macroblocks
    	gConfig.sliceUnitSize                = 1200 ;//# Number of macroblocks per slice
    
    	gConfig.loopfilterPreset	           = 1 ;//# Preset value for loop filter operation parameters, 0 => default values, 1 => user defined
    	gConfig.loopfilterDisableIDC               = 2 ;//# Disable H.264 loop filter, (0=Filter, 1= NoFilter, 2 = No loop filter across slices)
    	gConfig.filterOffsetA                      = 0 ;//# Alpha offset for loop filter
    	gConfig.filterOffsetB                      = 0 ;//# Beta offset for loop filter
    
    	gConfig.vuiCodingPreset                = 1;// # Preset value for VUI Control Params, 0 => deafult values, 1 => user defined
    	gConfig.aspectRatioInfoPresentFlag     = 1 ;//# Controls the insertion of aspect ratio information in VUI part of bit-stream
    	gConfig.aspectRatioIdc                 = 1 ;//# Aspect ratio ID
    	gConfig.videoSignalTypePresentFlag     = 0 ;//# controls the insertion of video signal type in VUI part of bit-stream
    	gConfig.videoFormat                    = 2 ;//# Video signal type
    	gConfig.videoFullRangeFlag             = 0 ;//# Flag to specigy Range of the pixels
    	gConfig.colourDescriptionPresentFlag   = 1 ;//# Specifies whether colour_primaries, transfer_characteristics and matrix_coefficients are present or not.
    	gConfig.colourPrimaries         	 = 5;// # chromaticity coordinates of the source primaries(Table E-3 in standard)
    	gConfig.transferCharacteristics 	 = 5;// # opto-electronic transfer characteristic of the source picture(Table E-4 in standard)
    	gConfig.matrixCoefficients      	 = 5;// # matrix coefficients used in deriving Y,Cb,Cr signals from the G,B,R primaries(Table E-5 in standard)
    	gConfig.timingInfoPresentFlag          = 1;// # Controls the insertion of timing info related parameters in VUI part of bit-stream
    
    	gConfig.gopStructure               = 0 ;//# GOP structure, 0 => Open or Non uniform(IBBPBBP), 1 => Closed or Uniform (BBIBBPBB)
    	gConfig.log2MaxFNumMinus4          = 0;// # sliceParams::frame_num syntax element will be reset after every (1<< (log2MaxFNumMinus4 + 4)) frames
    	gConfig.picOrderCountType          = 0 ;// # Picture order count type
    	gConfig.transformBlockSize         = 1 ;// # Tranform type, 0:4x4 only, 1: 8x8 only  - 4x4 for BP, 8x8 for HP
    	gConfig.topFieldFirstFlag          = 1 ;// # Flag to indicate field order in interlaced content
    	gConfig.interlaceCodingType        = 4 ;//# Interlced field coding type selection, 2 => MRF 3=> ARF 4=> SPF
    	gConfig.debugTraceLevel            = 0 ;//# Debug trace Enable 0 - Disable, 1- Level1, 2 - Level2, 3 - Level3,
    	gConfig.lastNFramesToLog           = 5 ;//# Last N frames to log into debug trace buffer
    
    	gConfig.maxInterFrameInterval  = 3;// I to P frame distance. 1 indicates no B frames. Value >1 indicates presence of B frames.
    	gConfig.profile                = 100;// # Encoding profile 100 => HP, 77 => MP, 66 => BP.
    	gConfig.level                  = 40;// # Level IDC   (e.g. 20 = level 2.0)
    	gConfig.inputWidth             = 320;// # width of image
    	gConfig.inputHeight            = 240;// # Height of image
    	gConfig.targetFrameRate        = 30000;// # Target frame rate in fps * 1000
    	gConfig.targetBitRate          = 300000;// # Target Bit Rate in Bits per second.
    	gConfig.intraFrameInterval     = 15;//  # Interval between two consecutive intra frames, 0 => Only first frame to be intra coded, 1 => All intra frames, N => One intra frame and N-1 inter frames, where N > 1
    	gConfig.interFrameInterval     = 3;//  M: Number of (M-1) B frames between two reference frames. 1 indicates no B frame.
    	gConfig.qpMaxI                 = 51;// #  Maximum QP for I/IDR frames
    	gConfig.qpMinI                 = 1;// # Minimum QP for I/IDR frames
    	gConfig.qpMaxP                 = 51;// #  Maximum QP for P frames
    	gConfig.qpMinP                 = 3;// # Minimum QP for P frames
    	gConfig.qpMaxB                 = 51 ;//# Maximum QP for B frames
    	gConfig.qpMinB                 = 3 ;//# Minimum QP for B frames
    	gConfig.rcAlgo                 = 2;// # Rate control algorithm used, 0: Variable Bitrate, 1 : Constant bitrate (low dealy), 2: Constrained CBR (No Frame Skips), 3:Constrained CBR (No Frame Skips with no scene change detection)
    	gConfig.IDRFrameInterval       = 2;// # Interval b/w two IDR frames  0=>IDR BBP I BBP I,  1=>IDR BBP IDR BBP IDR,  2=>IDR BBP I BBP IDR, 3=>IDR BBP I BBP I BBP IDR
    

  • I believe I have the decoder order problem solved, the stream now contains the correct frame_num values and the frames play in the correct order.

    The only outstanding issue is why the timing info is not present.
  • Hi Dhar, that is great! how did you solve it?. I will work on getting one of our experts to take a look on timing info

    thank you,
    Paula
  • I was issuing an XDM_SETPARAMS command while the handle was activated. I deactivated the handle before changing the dynamic params and then activate after and that fixed the frame_num issue.
  • Hi Dhar, checking the code it seems timingInfoPresentFlag should be set to 1 as you are using vuiCodingPreset=1 (user defined) .
    In CCS could you add a breakpoint to
    params->vuiCodingParams.timingInfoPresentFlag = gConfigParams->timingInfoPresentFlag; ?
    inside ..\h264hp_enc\Client\Test\Src\Common\h264hpvenc_ti_config.c. Maybe try to track down params->vuiCodingParams.timingInfoPresentFlag and see if it changes the value.

    An idea for a quick and dirty test could be to change the default value timingInfoPresentFlag from 0 to 1 (..\h264hp_enc\Src\Common\h264hpvenc_ti_ialg.c, just to see if still it is reported as 0..

    thank you,
    Paula
  • Hi

    I am using hpenc version 1.0.3.0

    h264hpvenc_ti_ialg.c is not in the src/common folder.

    Is there a different version?

    I checked that lparams->timingInfoPresentFlag is set before the H264HPVENC_create(), and it's always 1, never changes.

    Thanks

    Dhar

  • Hi
    I have the timingInfopresentFlag working now.

    It appears when you select encodingPreset = 2 it ignores a number of config values, and the timingInfoPresentFlag is one of them

    Thanks
    Dhar
  • Great thanks for let us know.
    Paula
  • I'm still not getting the expected effect with the target bit rate parameter

    With HP and B frames I do get lower bit rates produced but it doesn't seem to meet the target bit rate number.
    The Bit rate produced appears to be proportional to the target bit rate configured but higher by a factor or 3 to 5
  • I'm attaching an output files that shows the frame sizes

    Image size is 320x240

    rcalgo 2

    targetbitrate 50000

    suppressHighFreqCoeffs = 1

    frameSkipAfterSceneChange = 0;

    here you can see frames #38 and #84 producing a massive amount of data.

    #38   : IVIDEO_B_FRAME        : Bits  : 726528

    The raw YUV frame is 921600 bits.

    is this normal?

    Do I need to enable frame skip to get the bit rate target? ( EDIT: tried frame skip, doesn't change the bit rate produced)

    The videoFormat has a default value of 2, can't find any info on what that means, assuming it means PAL because the timing info in the file seems off. I set target frame rate to 30000 and the timing info in the file is showing 25fps.

    Thanks

    Dhar

    Output Stream : ..\Test\TestVecs\Output\bigbuck.264
    
    
     #NA   : IVIDEO_NA_FRAME       : Bits  : 0         
     #NA   : IVIDEO_NA_FRAME       : Bits  : 0         
     #NA   : IVIDEO_NA_FRAME       : Bits  : 0         
     #NA   : IVIDEO_NA_FRAME       : Bits  : 0         
     #0    : IVIDEO_IDR_FRAME      : Bits  : 6960      
     #1    : IVIDEO_P_FRAME        : Bits  : 2944      
     #2    : IVIDEO_B_FRAME        : Bits  : 2648      
     #3    : IVIDEO_B_FRAME        : Bits  : 784       
     #4    : IVIDEO_B_FRAME        : Bits  : 2768      
     #5    : IVIDEO_B_FRAME        : Bits  : 2456      
     #6    : IVIDEO_P_FRAME        : Bits  : 6752      
     #7    : IVIDEO_B_FRAME        : Bits  : 2000      
     #8    : IVIDEO_B_FRAME        : Bits  : 1960      
     #9    : IVIDEO_B_FRAME        : Bits  : 1880      
     #10   : IVIDEO_B_FRAME        : Bits  : 1352      
     #11   : IVIDEO_I_FRAME        : Bits  : 14912     
     #12   : IVIDEO_B_FRAME        : Bits  : 1440      
     #13   : IVIDEO_B_FRAME        : Bits  : 848       
     #14   : IVIDEO_B_FRAME        : Bits  : 1648      
     #15   : IVIDEO_B_FRAME        : Bits  : 1440      
     #16   : IVIDEO_P_FRAME        : Bits  : 4344      
     #17   : IVIDEO_B_FRAME        : Bits  : 1904      
     #18   : IVIDEO_B_FRAME        : Bits  : 720       
     #19   : IVIDEO_B_FRAME        : Bits  : 1840      
     #20   : IVIDEO_B_FRAME        : Bits  : 1784      
     #21   : IVIDEO_P_FRAME        : Bits  : 5040      
     #22   : IVIDEO_B_FRAME        : Bits  : 2176      
     #23   : IVIDEO_B_FRAME        : Bits  : 832       
     #24   : IVIDEO_B_FRAME        : Bits  : 1848      
     #25   : IVIDEO_B_FRAME        : Bits  : 1536      
     #26   : IVIDEO_IDR_FRAME      : Bits  : 12456     
     #27   : IVIDEO_B_FRAME        : Bits  : 9768      
     #28   : IVIDEO_B_FRAME        : Bits  : 10088     
     #29   : IVIDEO_B_FRAME        : Bits  : 9848      
     #30   : IVIDEO_B_FRAME        : Bits  : 9288      
     #31   : IVIDEO_P_FRAME        : Bits  : 1384      
     #32   : IVIDEO_B_FRAME        : Bits  : 1448      
     #33   : IVIDEO_B_FRAME        : Bits  : 768       
     #34   : IVIDEO_B_FRAME        : Bits  : 1872      
     #35   : IVIDEO_B_FRAME        : Bits  : 2416      
     #36   : IVIDEO_P_FRAME        : Bits  : 6400      
     #37   : IVIDEO_B_FRAME        : Bits  : 3536      
     #38   : IVIDEO_B_FRAME        : Bits  : 726528    
     #39   : IVIDEO_B_FRAME        : Bits  : 3392      
     #40   : IVIDEO_B_FRAME        : Bits  : 2776      
     #41   : IVIDEO_I_FRAME        : Bits  : 11632     
     #42   : IVIDEO_B_FRAME        : Bits  : 2120      
     #43   : IVIDEO_B_FRAME        : Bits  : 2408      
     #44   : IVIDEO_B_FRAME        : Bits  : 2584      
     #45   : IVIDEO_B_FRAME        : Bits  : 1824      
     #46   : IVIDEO_P_FRAME        : Bits  : 4392      
     #47   : IVIDEO_B_FRAME        : Bits  : 1512      
     #48   : IVIDEO_B_FRAME        : Bits  : 792       
     #49   : IVIDEO_B_FRAME        : Bits  : 1456      
     #50   : IVIDEO_B_FRAME        : Bits  : 1296      
     #51   : IVIDEO_P_FRAME        : Bits  : 4696      
     #52   : IVIDEO_B_FRAME        : Bits  : 1720      
     #53   : IVIDEO_B_FRAME        : Bits  : 1568      
     #54   : IVIDEO_B_FRAME        : Bits  : 1632      
     #55   : IVIDEO_B_FRAME        : Bits  : 1312      
     #56   : IVIDEO_IDR_FRAME      : Bits  : 11752     
     #57   : IVIDEO_B_FRAME        : Bits  : 8536      
     #58   : IVIDEO_B_FRAME        : Bits  : 9008      
     #59   : IVIDEO_B_FRAME        : Bits  : 8624      
     #60   : IVIDEO_B_FRAME        : Bits  : 8424      
     #61   : IVIDEO_P_FRAME        : Bits  : 1424      
     #62   : IVIDEO_B_FRAME        : Bits  : 1056      
     #63   : IVIDEO_B_FRAME        : Bits  : 936       
     #64   : IVIDEO_B_FRAME        : Bits  : 1072      
     #65   : IVIDEO_B_FRAME        : Bits  : 1040      
     #66   : IVIDEO_P_FRAME        : Bits  : 9712      
     #67   : IVIDEO_B_FRAME        : Bits  : 1904      
     #68   : IVIDEO_B_FRAME        : Bits  : 1272      
     #69   : IVIDEO_B_FRAME        : Bits  : 1680      
     #70   : IVIDEO_B_FRAME        : Bits  : 1800      
     #71   : IVIDEO_I_FRAME        : Bits  : 13920     
     #72   : IVIDEO_B_FRAME        : Bits  : 1776      
     #73   : IVIDEO_B_FRAME        : Bits  : 1024      
     #74   : IVIDEO_B_FRAME        : Bits  : 1272      
     #75   : IVIDEO_B_FRAME        : Bits  : 1248      
     #76   : IVIDEO_P_FRAME        : Bits  : 2832      
     #77   : IVIDEO_B_FRAME        : Bits  : 2072      
     #78   : IVIDEO_B_FRAME        : Bits  : 928       
     #79   : IVIDEO_B_FRAME        : Bits  : 2088      
     #80   : IVIDEO_B_FRAME        : Bits  : 2072      
     #81   : IVIDEO_P_FRAME        : Bits  : 3264      
     #82   : IVIDEO_B_FRAME        : Bits  : 1344      
     #83   : IVIDEO_B_FRAME        : Bits  : 1416      
     #84   : IVIDEO_B_FRAME        : Bits  : 709312    
     #85   : IVIDEO_B_FRAME        : Bits  : 1864      
     #86   : IVIDEO_IDR_FRAME      : Bits  : 12152     
     #87   : IVIDEO_B_FRAME        : Bits  : 8448      
     #88   : IVIDEO_B_FRAME        : Bits  : 8856      
     #89   : IVIDEO_B_FRAME        : Bits  : 8912      
     #90   : IVIDEO_B_FRAME        : Bits  : 9040      
     #91   : IVIDEO_P_FRAME        : Bits  : 2480      
     #92   : IVIDEO_B_FRAME        : Bits  : 1088      
     #93   : IVIDEO_B_FRAME        : Bits  : 1320      
     #94   : IVIDEO_B_FRAME        : Bits  : 1056      
     #95   : IVIDEO_B_FRAME        : Bits  : 1056      
     #96   : IVIDEO_P_FRAME        : Bits  : 18536     
     #97   : IVIDEO_B_FRAME        : Bits  : 1744      
     #98   : IVIDEO_B_FRAME        : Bits  : 1560      
     #99   : IVIDEO_B_FRAME        : Bits  : 1712      
     #100  : IVIDEO_B_FRAME        : Bits  : 1624      
     #101  : IVIDEO_I_FRAME        : Bits  : 16608     
     #102  : IVIDEO_B_FRAME        : Bits  : 1824      
     #103  : IVIDEO_B_FRAME        : Bits  : 1184      
     #104  : IVIDEO_B_FRAME        : Bits  : 1616      
     #105  : IVIDEO_B_FRAME        : Bits  : 1464      
     #106  : IVIDEO_P_FRAME        : Bits  : 8080      
     #107  : IVIDEO_B_FRAME        : Bits  : 2136      
     

  • Dhar, some questions and possible tests:

    - Can you try to encode it with a reference encoder. is target bitrate achievable?
    - Could you try suppressHighFreqCoeffs = 3
    - Could you set params for only 1 IDR (first I-frame). that bitrate improve?
    - Could you try a longer GOP (30 or 45?)
    - Could you try IBBBP structure? any improvement?

    suppressHighFreqCoeffs
    #0=> No High Freq Suppression
    #1=> Adaptively enabled only for noise streams when Qp reaches it max & suppression for more than half of the coeffs
    #2 => Enabled for all streams when Qp reaches it max & suppression for half of the coeffs
    #3 => Enabled for all streams when Qp reaches it max & suppression for more than half of the coeffs

    thank you,
    Paula
  • Hi
    I'll have to run the reference encoder overnight (it loads raw data over JTAG which takes hrs to get enough frames)

    For my encoder changing the suppressHighFreqCoeffs to 3 didn't make any difference.

    The other 3 params did not have any effect either (Intra interval to 45, inter interval to 5, IDR interval to 0

    What I see is occasionally you get B or P frames that are massive (almost the same size as a raw frame) this keeps the bit rate very high.

    I will run the reference encoder tonight and see what I get.

    Dhar

  • Hi Dhar, just for your reference, this another E2E thread w.r.t suppressHighFreqCoeffs that you can take a look for more details and reference configuration files. For that specific customer, they needed fixed GOP size. I think in your case you are OK with frame skipping enabled

    thank you,

    Paula

  • Hi

    Running the reference encoder with the same config values averaged 57kbps over 1000 frames. This is reasonable. I guess there is a problem in the initialisation somewhere but everything is returning ok.

     

  • Hi Dhar, I want to confirm. For testing are you using TI's EVM TMS320C6678 ? or your own board?

    Also, are you using test application from http://software-dl.ti.com/dsps/dsps_public_sw/codecs/C6678/H264HP_E/latest/index_FDS.html ? or your own application?

    I believe you modified OOB test application, and probably your are using your own HW. If this is true, I was wondering if you can run a test using TMS320C6678 evaluation board, and OOB H264 encoder testapplication with your latest and greatest configuration params. Just to confirm results are the same.

    thank you,

    Paula

     

  • Above proposed sanity check is to confirm all the params are applied and configured correctly. As you mentioned few post above timingInfoPresentFlag and frame_num were not correctly setup. You were able to fix it, however, I was wondering if there are more params that we are currently not initializing with the desire values..

    thank you,
    Paula
  • Hi 

    I'm running my own application on my own hardware (C6657).

    I can run the (modified) reference encoder on the C6657 without any problems.

    There are a few changes that were made in order to run in my environment. The main problem is that everything is returning ok and while it appears to encode properly it's ignoring some config params. There is no indication why. 

    I spent the weekend starting from scratch again, moving the encoder to my application and making the necessary changes. Now after it produces the first I frame it only produces I frames. There's no indication why.

    Thanks

    Dhar

  • Dhar, ideally, if you have a TI's EVM, I would suggest to tune first H264 configurations params there, using our OOB C66x Encoder application, and then do a byte wise comparison with your hardware/software output bitsteam. Or, if bitstream comparison is not possible (maybe your application does other things), then at least it would be a good reference for comparing h264 headers.

    thank you,
    Paula
  • 2055.Output.zipHi

    The output from the reference encoder seems to track the target bit rate reasonably well.

    The output from mine with the same config value does not.

    I've attached 2 files which are the outputs from each with the same config values, you'll notice the frames are completely different. The same YUV source used for both.

    Dhar

  • Hi Dhar, thanks for sharing h264 clips. I am glad you have a reference, that is always helpful. I hope you can find what is missing in your new ported application.
    Paula
  • Hi

    The problem was that one or more of the config params on the encoder stack needs to be in internal memory. If they are in external memory all the init 

    Last question on this topic:

    What is the minimum value allowed for targetBitRate?

    Thanks

    Dhar

  • Hi Dhar, I am glad to hear you fixed the issue.
    About minimum bit rate I found below define:
    #define MIN_BIT_RATE (16*1024)

    thank you,
    Paula