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.

dm365 h263 codec implementation



HI,

I use h263 codec on dm365 platform and get the test.mpeg4 with the encode demo.(dvsdk_3_10_00_19/dm365_codecs_03_10_00_07)

But I'not sure the test.mpeg4 is real h263.

when I use H263PLAY.exe to play the test.mpeg4,the H263PLAY.exe report error:ERROR:Picture Header not match.

3443.263PLAY.rar

 

the file 263PLAY.rar include H263PLAY.exe,test.mpeg4 and the real h263 video missqcif.263 for test.

flow with my create h263 codec engine code:

    VIDENC1_Params          defaultParams       = Venc1_Params_DEFAULT;
    VIDENC1_DynamicParams   defaultDynParams    = Venc1_DynamicParams_DEFAULT;
    IMP4HDVICPENC_Params mp4hdvicpParams;
    IMP4HDVICPENC_DynamicParams mp4hdvicpDynParams;

    mp4hdvicpParams = IMPEG4VENC_PARAMS;

    mp4hdvicpParams.videncParams.maxWidth = 1920;
    mp4hdvicpParams.videncParams.maxHeight = 1088;
    mp4hdvicpParams.videncParams.maxInterFrameInterval = 1;
    mp4hdvicpParams.videncParams.inputChromaFormat = IMP4HDVICPENC_YUV_420IUV;
    mp4hdvicpParams.videncParams.reconChromaFormat =IMP4HDVICPENC_YUV_420IUV;
    mp4hdvicpParams.videncParams.size = sizeof(IMP4HDVICPENC_Params);
    mp4hdvicpParams.videncParams.maxBitRate = 20000000;
    mp4hdvicpParams.videncParams.maxFrameRate = 30000;
    mp4hdvicpParams.videncParams.dataEndianness = XDM_BYTE;
    mp4hdvicpParams.videncParams.inputContentType = IVIDEO_PROGRESSIVE;


    memcpy(&mp4hdvicpDynParams,&defaultDynParams,sizeof(defaultDynParams));
    mp4hdvicpDynParams.videncDynamicParams.size = sizeof(IMP4HDVICPENC_DynamicParams);

    /*h.263 baseline profile level 10*/
    mp4hdvicpParams.MPEG4_mode = 0;
    mp4hdvicpParams.levelIdc = 10; 
    mp4hdvicpParams.useVOS = 1;
    mp4hdvicpParams.useGOV = 0;
    mp4hdvicpParams.useDataPartition = 0;
    mp4hdvicpParams.useRVLC =0;          
    mp4hdvicpParams.aspectRatio = IMP4HDVICPENC_AR_DEFAULT;
    mp4hdvicpParams.pixelRange = IMP4HDVICPENC_PR_DEFAULT;
    mp4hdvicpParams.timerResolution = 30000;
    mp4hdvicpParams.ME_Type = 0;           
    mp4hdvicpParams.UMV = 1;               
    mp4hdvicpParams.EncQuality_mode = 0;
    mp4hdvicpParams.hdvicpHandle = NULL;

    memcpy(( VIDENC1_Params *)&mp4hdvicpParams,envp->params ? envp->params : &defaultParams,sizeof(VIDENC1_Params));

    mp4hdvicpDynParams.maxDelay = 1000;
    mp4hdvicpDynParams.PacketSize = 0;
    mp4hdvicpDynParams.Four_MV_mode = 0;
    mp4hdvicpDynParams.qpIntra = 10;
    mp4hdvicpDynParams.qpInter = 10;
    mp4hdvicpDynParams.useHEC = 0;
    mp4hdvicpDynParams.airRate = 0;
    mp4hdvicpDynParams.useGOBSync = 1;
    mp4hdvicpDynParams.RcAlgo = 8;
    mp4hdvicpDynParams.QPMax = 31;
    mp4hdvicpDynParams.QPMin = 2;
    mp4hdvicpDynParams.qpInit = 8;
    mp4hdvicpDynParams.PerceptualRC = 0;
    mp4hdvicpDynParams.mvSADoutFlag = 0;

    params = envp->params ? envp->params : (VIDENC1_Params *)&mp4hdvicpParams;
    dynParams = envp->dynParams ? envp->dynParams : (VIDENC1_DynamicParams  *)&mp4hdvicpDynParams;

    /* Set up codec parameters */
    params->maxWidth          = envp->imageWidth;
    params->maxHeight         = envp->imageHeight;
    params->encodingPreset    = XDM_HIGH_SPEED;
    if (colorSpace ==  ColorSpace_YUV420PSEMI) {
        params->inputChromaFormat = XDM_YUV_420SP;
    } else {
        params->inputChromaFormat = XDM_YUV_422ILE;
    }
    params->reconChromaFormat = XDM_YUV_420SP;
    params->maxFrameRate      = envp->videoFrameRate;

    /* Set up codec parameters depending on bit rate */
    if (envp->videoBitRate < 0) {
        /* Variable bit rate */
        params->rateControlPreset = IVIDEO_NONE;

        /*
         * If variable bit rate use a bogus bit rate value (> 0)
         * since it will be ignored.
         */
        params->maxBitRate        = 0;
    }
    else {
        /* Constant bit rate */
        params->rateControlPreset = IVIDEO_STORAGE;
        params->maxBitRate        = envp->videoBitRate;
    }

    dynParams->targetBitRate   = params->maxBitRate;
    dynParams->inputWidth      = params->maxWidth;
    dynParams->inputHeight     = params->maxHeight;   
    dynParams->refFrameRate    = params->maxFrameRate;
    dynParams->targetFrameRate = params->maxFrameRate;
    dynParams->interFrameInterval = 0;
   
    /* Create the video encoder */
    hVe1 = Venc1_create(hEngine, envp->videoEncoder, params, dynParams);

    if (hVe1 == NULL) {
        ERR("Failed to create video encoder: %s\n", envp->videoEncoder);
        cleanup(THREAD_FAILURE);
    }

can anyone help me?

Thanks very much.

  • Hi James,

    test.mpeg4 is not a h.263 file. It is mpeg4 SP stream. The parameters looks fine if i check at a gross level. I will fwd this question to the codec owner so that he can check in more detail and reply.

    regards

    Yashwant 

  • HI Yashwant ,

      Thank you and wait for codec owner's reply.

      What we want is to use the codec to get the stream of QCIF,10~15fps,48kbps,H263 profile 0 level 10. Would you like to tell me the right settings of codec (dvsdk_3_10_00_19/dm365_codecs_03_10_00_07)?

    Best regards,

    James

  • Hi James,

     
    The test.mpeg4 stream you have uploaded is indeed a raw mpeg4 stream and not a h263 stream.

    On close analysis of param initialization (from the code posted earlier) it appears that codec is initialized with base size while extended size is required to initialize in H263 mode.

    It is true that extended params like MPEG4_mode, levelIdc etc are initialized and mp4hdvicpParams.videncParams.size is set to sizeof(IMP4HDVICPENC_Params) early on.
    However I do see a memcpy after the extended params initialization which can possibly override the mp4hdvicpParams.videncParams.size to sizeof(IVIDENC_Params).


    To be precise "memcpy(( VIDENC1_Params *)&mp4hdvicpParams,envp->params ? envp->params : &defaultParams,sizeof(VIDENC1_Params));" seems to be overriding the size of init params to base params size which will result in mpeg4 encode. Can you please verify this ? You can check the size of params just before Venc1_create().

    Regards,
    Jay

     

     

     

     

     

     

         

  • Hi Jay,

    Thanks for your advice,I adjust the codec params and get h263 video.

    1004.test.rar

    And I have another two questions.

    1:I want to get 12~15 fps h263 video stream,but when I set the parameter targetFrameRate in videncDynamicParams to 15000,the fps is still 25 .I don't know why?

    2:The h263 video is  not clear.Which params can be adjusted to enhance the h263 video quality?

    my codec params as follows:

        mp4hdvicpParams.videncParams.size = sizeof(IMP4HDVICPENC_Params);
        mp4hdvicpParams.videncParams.encodingPreset = XDM_DEFAULT;
        mp4hdvicpParams.videncParams.rateControlPreset = IVIDEO_LOW_DELAY;
        mp4hdvicpParams.videncParams.maxHeight = 720;
        mp4hdvicpParams.videncParams.maxWidth = 1280;
        mp4hdvicpParams.videncParams.maxFrameRate = 30000;
        mp4hdvicpParams.videncParams.maxBitRate = 6000000;
        mp4hdvicpParams.videncParams.dataEndianness = XDM_BYTE;
        mp4hdvicpParams.videncParams.maxInterFrameInterval = 0;
        mp4hdvicpParams.videncParams.inputChromaFormat = XDM_YUV_420P;
        mp4hdvicpParams.videncParams.inputContentType = IVIDEO_PROGRESSIVE;
        mp4hdvicpParams.videncParams.reconChromaFormat = XDM_CHROMA_NA;

        /*h.263 baseline profile level 10*/
        mp4hdvicpParams.MPEG4_mode = 0;
        mp4hdvicpParams.levelIdc = 10; 
        mp4hdvicpParams.useVOS = 0;
        mp4hdvicpParams.useGOV = 0;
        mp4hdvicpParams.useDataPartition = 0;
        mp4hdvicpParams.useRVLC =0;          
        mp4hdvicpParams.aspectRatio = IMP4HDVICPENC_AR_DEFAULT;
        mp4hdvicpParams.pixelRange = IMP4HDVICPENC_PR_DEFAULT;
        mp4hdvicpParams.timerResolution = 30000;
        mp4hdvicpParams.ME_Type = 1;           
        mp4hdvicpParams.UMV = 1;               
        mp4hdvicpParams.EncQuality_mode = 1;
        mp4hdvicpParams.hdvicpHandle = NULL;

        mp4hdvicpDynParams.videncDynamicParams.size = sizeof(IMP4HDVICPENC_DynamicParams);
        mp4hdvicpDynParams.videncDynamicParams.inputHeight = 720;
        mp4hdvicpDynParams.videncDynamicParams.inputWidth = 1280;
        mp4hdvicpDynParams.videncDynamicParams.refFrameRate = 15000;
        mp4hdvicpDynParams.videncDynamicParams.targetFrameRate = 15000;
        mp4hdvicpDynParams.videncDynamicParams.targetBitRate = 48000;
        mp4hdvicpDynParams.videncDynamicParams.intraFrameInterval = 30;
        mp4hdvicpDynParams.videncDynamicParams.generateHeader = XDM_ENCODE_AU;
        mp4hdvicpDynParams.videncDynamicParams.captureWidth = 0;
        mp4hdvicpDynParams.videncDynamicParams.forceFrame = IVIDEO_NA_FRAME;
        mp4hdvicpDynParams.videncDynamicParams.interFrameInterval = 1;
        mp4hdvicpDynParams.videncDynamicParams.mbDataFlag = 0;

        mp4hdvicpDynParams.maxDelay = 1000;
        mp4hdvicpDynParams.PacketSize = 0;
        mp4hdvicpDynParams.Four_MV_mode = 0;
        mp4hdvicpDynParams.qpIntra = 10;
        mp4hdvicpDynParams.qpInter = 10;
        mp4hdvicpDynParams.useHEC = 0;
        mp4hdvicpDynParams.airRate = 0;
        mp4hdvicpDynParams.useGOBSync = 1;
        mp4hdvicpDynParams.RcAlgo = 8;
        mp4hdvicpDynParams.QPMax = 31;
        mp4hdvicpDynParams.QPMin = 8;
        mp4hdvicpDynParams.qpInit = 8;
        mp4hdvicpDynParams.PerceptualRC = 0;
        mp4hdvicpDynParams.mvSADoutFlag = 0;

        params = envp->params ? envp->params : (VIDENC1_Params *)&mp4hdvicpParams;
        dynParams = envp->dynParams ? envp->dynParams : (VIDENC1_DynamicParams  *)&mp4hdvicpDynParams;

        /* Set up codec parameters */
        params->maxWidth          = envp->imageWidth;
        params->maxHeight         = envp->imageHeight;
        params->encodingPreset    = XDM_HIGH_SPEED;
        if (colorSpace ==  ColorSpace_YUV420PSEMI) {
            params->inputChromaFormat = XDM_YUV_420SP;
        } else {
            params->inputChromaFormat = XDM_YUV_422ILE;
        }
        params->reconChromaFormat = XDM_YUV_420SP;
        params->maxFrameRate      = envp->videoFrameRate;

        /* Set up codec parameters depending on bit rate */
        if (envp->videoBitRate < 0) {
            /* Variable bit rate */
            params->rateControlPreset = IVIDEO_NONE;

            /*
             * If variable bit rate use a bogus bit rate value (> 0)
             * since it will be ignored.
             */
            params->maxBitRate        = 0;
        }
        else {
            /* Constant bit rate */
            params->rateControlPreset = IVIDEO_STORAGE;
            params->maxBitRate        = envp->videoBitRate;
        }

        //dynParams->targetBitRate   = params->maxBitRate;
        dynParams->inputWidth      = params->maxWidth;
        dynParams->inputHeight     = params->maxHeight;   
        //dynParams->refFrameRate    = params->maxFrameRate;
        //dynParams->targetFrameRate = params->maxFrameRate;
        dynParams->interFrameInterval = 0;

        /* Create the video encoder */
        hVe1 = Venc1_create(hEngine, envp->videoEncoder, params, dynParams);

        if (hVe1 == NULL) {
            ERR("Failed to create video encoder: %s\n", envp->videoEncoder);
            cleanup(THREAD_FAILURE);
        }

    codec run print:


    ARM Load: 0% Video fps: 25 fps Video bit rate: 80 kbps Sound bit rate: 0 kbps Time: 00:00:38 Demo: Encode Display: D1 PAL Video Codec: MPEG4 Video Resolution: 176x144 Sound Codec: N/A Sampling Freq: N/A

    ARM Load: 0% Video fps: 25 fps Video bit rate: 80 kbps Sound bit rate: 0 kbps Time: 00:00:39 Demo: Encode Display: D1 PAL Video Codec: MPEG4 Video Resolution: 176x144 Sound Codec: N/A Sampling Freq: N/A

    ARM Load: 0% Video fps: 25 fps Video bit rate: 80 kbps Sound bit rate: 0 kbps Time: 00:00:40 Demo: Encode Display: D1 PAL Video Codec: MPEG4 Video Resolution: 176x144 Sound Codec: N/A Sampling Freq: N/A

    Best Regards,
    James

  • Hi James,

    Good to know that you are able to encode H263 video now. Here are the answers to rest of the questions.

    Answers to question 1:
     I think you are referring to 25fps prints coming from the demo package (See the bottom of logs)
     This appears to be some bug in the demo package that you are using.
     As I have no idea how the demo package determines the fps (or assumes any fps) it is better if you ignore the 25fps print from demo package.
     
     Regarding frame rate signaling in H263 bitstream, H263 base line profile does not support signaling frame rates in bitstreams.
     The default frame rate in H263 baseline is 30000/1001=29.97fps.
     The frame rates in H263 can only be signaled using CPCFC (custom picture clock frequency code) which is part of H263++ profile which we do not support.
     However the codec does support encoding using any target frame rate (like 15fps as in your case) but there is no way for decoder to find the frame rate.

    Answer to question 2:
     On the quality side the default search range is restricted to +-16 in H263 base line profile.
     Additionally baseline H263 does not support  tools like deblocking, intraprediction,4MV etc which are part of various annexures in H263.(not supported in  baseline encoder)
     So the only way to improve quality is increase the bitrate to something higher than 96kpbs (currently set).

    Regards,
    Jay

  • Hi Jay,

        Thank you for your help.

    Best regards,

    James