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.

Encoder drops frames instead of reducing frame size.

Problem statement:

Using the "H.264 Base/Main/High Profile Decoder on DM365/DM368 Version 02.00.00"

We are trying to encode 2 I frame only interleaved channels at 1FPS per channel. The encoder is dropping frames regardless of the bitrate we use. We know we are dropping frames because the call to Venc1_process returns 0 (no error) but the bytes used in the destination buffer is 0. (Buffer_getNumBytesUsed(hDstBuf)==0) The comment in the reference code states:

/* If the encoder cannot meet the constraints of the constant bitrate becuase previous frames * have been to large, it will drop frames to compensate. When this happens, the encode process * succeeds, but the bytes used will be 0. */

and later:

/* The encoder hasn't been able to meet bitrate constraints and has intended to drop * the frame. In order to prevent frame drop, we must dump this frame and continue. */

We are trying to vary the bitrate so that the encoder does not drop frames but when we increase the bitrate the compression goes down, that is the frames coming out of the encoder get bigger so we get the same result - dropped frames.

This is a table for a comples image:

Bitrate       Dropped/kept frames            Frame size as output from decoder

0.5MBps    8/1                                        250KBytes

1               3/1                                          255kBytes

1.5             2/1                                        300KBytes

2               2/1                                        400-500Kbytes

Why does the compressed frame size increase this way at the expense of dropping frames?

When we have simple compressible images we have no issue.

The question is how do we stop the encoder dropping frames?

Here are our current constant settings for the encoder:  

   /* Set up MAXIMUM codec parameters. We round up the height to accomodate for    

* alignment restrictions from codecs; width has to be aligned to 16. */

   params->maxWidth         = 1920;    

   params->maxHeight        = 1088;    

   params->encodingPreset   = (int)XDM_HIGH_SPEED;    

   params->inputContentType = (int)IVIDEO_PROGRESSIVE;    

   params->inputChromaFormat  = (int)XDM_YUV_420SP;    

    params->reconChromaFormat  = (int)XDM_CHROMA_NA; //XDM_YUV_420SP;

   /* Set NO B frames */    

   params->maxInterFrameInterval = 0;

   params->rateControlPreset  = (int)IVIDEO_LOW_DELAY;    

   params->maxBitRate   = 10000000; 

   params->maxFrameRate       = 60000;

   /*********************************************************************     * Set H264 Specific parameters     *********************************************************************/

   /* Encapsulate generic parameters inside the H264 specific parameters structures    

* and pass to encoder init. */    

   h264params.videncParams     = *params;    

   h264params.videncParams.size    = sizeof(h264params);    

   h264params.numTemporalLayers    = 0;    

   h264params.profileIdc      = 66; /* base profile 66 */    

   h264params.entropyMode      = 0;    

   h264params.transform8x8FlagInterFrame  = 0;    

   h264params.transform8x8FlagIntraFrame  = 0;   

  h264params.seqScalingFlag     = 0;    

  h264params.levelIdc      = 30;    

   h264params.encQuality     = 2; 

   h264params.enableARM926Tcm    = 0;   

  h264params.enableDDRbuff    = 0;    

  h264params.enableVUIparams    = 0;

   /* Added as advised by TI message board */    

    h264dparams.resetHDVICPeveryFrame  = 0;

   /* NAL Stream Type -------------------    

*   0 -> encoded stream in NAL unit format,    

* 1 -> encoded stream in bytes stream format = STARTCODE + NAL    

* NOTE: When set to 0, the byte stream format is not recognised by FFMPEG */    

h264params.sliceFormat     = 1;

The dynamic settings are:    

/*********************************************************************     * Set dynamic parameters    

* These represent details relevant to the next frame to be encoded.    

*********************************************************************/

   /* This ensures the initial frame rate isn't invalid. */    

   new_framerate = 2000;

   /* Codec required frame rates as multiples of 500 */    

   new_framerate += 250;    

    new_framerate /= 500;    

   new_framerate *= 500;

   dynParams->refFrameRate    = new_framerate;

    /* NOTE: H264 Encoder cannot be set with frame rate that is not a multiple    

     * of 500 - so it cannot be set to 29.97 only 29.5 or 30 */   

   dynParams->targetFrameRate = dynParams->refFrameRate;   

    dynParams->targetBitRate   = BR_0_5M; // (500 KBPS)

   aFFD = acraVideoFrameDetails[gblGetFrameFormat()];

   /* The encoder requires these frame sizes be a multiple of 2 - but can otherwise be    

* set to the correct frame size even if not a multiple of 16. The buffer sizes must    

* however be compliant with the alignement restrictions of the codec */    

   dynParams->inputWidth    = Dmai_roundUp(aFFD.frameWidth,16); 

   dynParams->inputHeight    = Dmai_roundUp(aFFD.frameHeight,16);

   /* This value must be the same as the input buffer line width    

* which should already be set to a multiple of 32 */    

  dynParams->captureWidth   = Dmai_roundUp(aFFD.frameWidth,32);

   dynParams->intraFrameInterval  = P_I_NO_I_FRAMES;

   dynParams->interFrameInterval  = 0;      /* NO B frames */

   /*********************************************************************     * Set H264 Specific 'dynamic' parameters    

* These represent details relevant to the next frame to be encoded.     *********************************************************************/    h264dparams.videncDynamicParams    = *dynParams;    

  h264dparams.videncDynamicParams.size   = sizeof(h264dparams);    

  h264dparams.enableBufSEI      = 0;    

  h264dparams.enablePicTimSEI     = 0;    

  h264dparams.VUI_Buffer       = &H264VENC_TI_VUIPARAMBUFFER;    

  h264dparams.VUI_Buffer->numUnitsInTicks  = 1;   

  h264dparams.VUI_Buffer->timeScale    = 30;

   /* How often to send SPS/PPS    

* Setting to the same as the I frame period as it will    

* generate an I frame anyway. */    

  h264dparams.idrFrameInterval   = dynParams->intraFrameInterval;

   /* Defined CBR */    

    h264dparams.rcAlgo = 0;