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.

DM8168:H264 Video Quality related issue with Encode-Decode Combine application

Hi All,

I am implementing the decode-encode combine application which performs the following actions:-

- Reads the h264 frame from the file

- Passes this h264 frame to decoder

- Decoder decodes this frame and passes the decoded frame to encoder

- encoder encodes the decoded frame and generate h264 frame

- writes the encoded h264 frame to file.

While testing this application I am facing following issue:-

Generated h264 file is not playing properly. The color quality of the encoded file is very bad.

For debug purpose I am writing the decoded frame to file and it is playing properly.

Please let me know if you need more information.

Note: After removing the padded data from decoded buffer, I am passing the buffer to encoder component.

Thanks,

Vijay

  • I doubt is that Looks like there might be some goof up happening  in the process of

    Vijay Patel said:
    After removing the padded data from decoded buffer, I am passing the buffer to encoder component.

    Technically, this additional process is not needed, and one can play around with the pitch parameter.

    Also can you share the encoding parameters?

    Regards,

    Venu

  • Hi Venu,

    Thanks for the response.

    Following is my encoder config function:-

    MX_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;
      //tPortDef.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
      /* 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_DirOutput;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoBitrate,
                                 &tVidEncBitRate);

      tVidEncBitRate.eControlRate = OMX_Video_ControlRateDisable;
      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_AVCProfileBaseline;
      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);

      tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_Med_Speed_High_Quality;
      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.intraFrameInterval = 90;

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


     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;
    }

    Regards,

    Vijay