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.

Change Third MJPEG stream to H264

Expert 1840 points

Dear,

I am working with dm8148 and RDK V3.5. I want to change the third stream in Tristream full feature usecase to H264. As I understood, the three buffers from IPCIn Video will be put in the enclink, the encode link will base on the encode parameters to use the proper encoder such as h264, MPEG4 or MJPEG. For that, I modified some part as below:

1. multich_tristream_fullfeature.c: setting the third channel in encPrm same as first channel.

2. ti_mcfw_ipcbits.c: correct the streamType and codecType follow the H264. 

3. - stream_env_ctrl.c:  fSetStreamConfig

    - file_msg_drv.c: fSetStreamConfig

    - wis-streamer.cpp

modify to make the correct stream format.

4. mem_mng.h, mem_mng.c: correct the mem layout, we use the same name of MJPEG constant setting for third stream, just change the value follow the MP4 setting.

5. cache_mng.c: modify the  Cache_mng_default with first element was changed from VIDEO_MJPG to VIDEO_MP4.

6. ti_venc.h: change the value of VENC_PRIMARY_CHANNELS to 3

#define VENC_PRIMARY_CHANNELS (3)
#define VENC_CHN_MAX (VENC_PRIMARY_CHANNELS + 1)

7. system_linkId.h: 

//#define SYSTEM_LINK_ID_VENC_1 VIDEO_LINK(SYSTEM_LINK_COMMON_LINKS_MAX_ID+2)
#define SYSTEM_LINK_ID_VENC_1 VIDEO_LINK(SYSTEM_LINK_COMMON_LINKS_MAX_ID+3)


I tried many ways and looked the source code carefully but I could not success to make the system run correctly.

I always got the error: 

[host] Error code: -1 at 429
[m3video] Extended error 20c000 for reqObjIndex 0

[host] Error code: -1 at 429
[m3video] 15819:WARN
[m3video] ENCLINK:ERROR in Enclink_h264EncodeFrameBatch.Status[-1] for IVAHD_0
[m3video] 15819:WARN
[m3video] ENC : IVAHDID : 0 ENCLINK:ERROR in EncLink_SubmitBatch.Status[-1]

I logged the buffer size of channel 3 in ti_mcfw_ipcbits.c but it has just available in some first frame, after that it is always 0, at that time error also happen.

I guess I missed some important things but it is really hard to figure it out. I wasted some weeks for this issues, please give me some hints or some ideas if you can.

Thank you very much!


  • Dear,

    I have just seen an answer but now it was deleted. I again confirm that I am using multich_tristream_fullfeature.c usecase. In this file, I think the important part to change the third stream from MJPEG to H264 is "encPrm" setting:


    /* Video Encoder Link params */
    MULTICH_INIT_STRUCT(EncLink_CreateParams, encPrm);
    {
    EncLink_ChCreateParams *pLinkChPrm;
    EncLink_ChDynamicParams *pLinkDynPrm;
    VENC_CHN_DYNAMIC_PARAM_S *pDynPrm;
    VENC_CHN_PARAMS_S *pChPrm;

    for (i = 0; i < VENC_PRIMARY_CHANNELS; i++)
    {
    pLinkChPrm = &encPrm.chCreateParams[i];
    pLinkDynPrm = &pLinkChPrm->defaultDynamicParams;

    pChPrm = &gVencModuleContext.vencConfig.encChannelParams[i];
    pDynPrm = &pChPrm->dynamicParam;
    OSA_printf("\n\n\n\n\n\n\n\nCombo codec %d\n\n\n\n\n\n\n", gUI_mcfw_config.demoCfg.codec_combo);
    switch(gUI_mcfw_config.demoCfg.codec_combo) {
    case 0: pLinkChPrm->format = IVIDEO_H264HP; break; //"SINGLE_H264"
    case 1: pLinkChPrm->format = IVIDEO_MPEG4SP; break; //"SINGLE_MPEG4"
    case 2: pLinkChPrm->format = IVIDEO_MJPEG; break; //"SINGLE_JPEG"
    case 3: pLinkChPrm->format = (i==0)? IVIDEO_H264HP:IVIDEO_MJPEG; break; //"H264_JPEG"
    case 4: pLinkChPrm->format = (i==0)? IVIDEO_MPEG4SP:IVIDEO_MJPEG; break; //"MPEG4_JPEG"
    case 5: pLinkChPrm->format = (i==0)? IVIDEO_H264HP:IVIDEO_H264HP; break; //"DUAL_H264"
    case 6: pLinkChPrm->format = (i==0)? IVIDEO_MPEG4SP:IVIDEO_MPEG4SP; break; //"DUAL_MPEG4"
    case 7: pLinkChPrm->format = (i==0)? IVIDEO_H264HP:IVIDEO_MPEG4SP; break; //"H264_MPEG4"
    case 8: pLinkChPrm->format = (i==0)? IVIDEO_H264HP:IVIDEO_H264HP; break; //"TRIPLE_H264"
    case 9: pLinkChPrm->format = (i==0)? IVIDEO_MPEG4SP:IVIDEO_MPEG4SP; break; //"TRIPLE_MPEG4"
    default: pLinkChPrm->format = IVIDEO_H264HP;break;
    }

    pLinkChPrm->profile = gVencModuleContext.vencConfig.h264Profile[i];
    pLinkChPrm->dataLayout = IVIDEO_PROGRESSIVE;
    pLinkChPrm->fieldMergeEncodeEnable = FALSE;
    pLinkChPrm->enableAnalyticinfo = pChPrm->enableAnalyticinfo;
    pLinkChPrm->maxBitRate = pChPrm->maxBitRate;
    pLinkChPrm->encodingPreset = pChPrm->encodingPreset;
    pLinkChPrm->rateControlPreset = IVIDEO_USER_DEFINED; //pChPrm->rcType;
    pLinkChPrm->enableHighSpeed = FALSE;
    pLinkChPrm->enableWaterMarking = pChPrm->enableWaterMarking;
    pLinkChPrm->StreamPreset = gUI_mcfw_config.StreamPreset[i];
    pLinkDynPrm->intraFrameInterval = pDynPrm->intraFrameInterval;

    pLinkDynPrm->targetBitRate = pDynPrm->targetBitRate;
    pLinkDynPrm->interFrameInterval = 1;
    pLinkDynPrm->mvAccuracy = IVIDENC2_MOTIONVECTOR_QUARTERPEL;
    pLinkDynPrm->inputFrameRate = pDynPrm->inputFrameRate;
    pLinkDynPrm->rcAlg = pDynPrm->rcAlg;
    pLinkDynPrm->qpMin = pDynPrm->qpMin;
    pLinkDynPrm->qpMax = pDynPrm->qpMax;
    pLinkDynPrm->qpInit = pDynPrm->qpInit;
    pLinkDynPrm->vbrDuration = pDynPrm->vbrDuration;
    pLinkDynPrm->vbrSensitivity = pDynPrm->vbrSensitivity;

    encPrm.numBufPerCh[i] = 4;
    gVencModuleContext.encFormat[i] = pLinkChPrm->format;

    }
    }

    /* Video Encoder Framerate */
    #ifdef IMGS_OMNIVISION_OV10630
    encPrm.chCreateParams[0].defaultDynamicParams.inputFrameRate = 30; // ENC_LINK_DEFAULT_ALGPARAMS_INPUTFRAMERATE;
    #elif defined IMGS_SONY_IMX104
    encPrm.chCreateParams[0].defaultDynamicParams.inputFrameRate = 30; // ENC_LINK_DEFAULT_ALGPARAMS_INPUTFRAMERATE;
    #elif defined IMGS_MICRON_MT9M034
    encPrm.chCreateParams[0].defaultDynamicParams.inputFrameRate = 30; //
    #else
    encPrm.chCreateParams[0].defaultDynamicParams.inputFrameRate = 60; // ENC_LINK_DEFAULT_ALGPARAMS_INPUTFRAMERATE;
    #endif
    encPrm.chCreateParams[1].defaultDynamicParams.inputFrameRate = 30; // ENC_LINK_DEFAULT_ALGPARAMS_INPUTFRAMERATE;

    encPrm.vsEnable = gUI_mcfw_config.vsEnable;

    if(gUI_mcfw_config.vaUseCase == TRUE)
    {
    encPrm.isVaUseCase = 1;
    }
    else
    {
    encPrm.isVaUseCase = 0;
    }

    for (i = VENC_PRIMARY_CHANNELS; i < (VENC_CHN_MAX - 1); i++)
    {
    OSA_printf("\n\n\n\n\n\n\n\n Go to setup for MJPEG \n\n\n\n\n\n\n\n\n");

    encPrm.chCreateParams[i].format = IVIDEO_MJPEG;
    encPrm.chCreateParams[i].profile = 0;
    encPrm.chCreateParams[i].dataLayout = IVIDEO_PROGRESSIVE;
    encPrm.chCreateParams[i].fieldMergeEncodeEnable = FALSE;
    encPrm.chCreateParams[i].defaultDynamicParams.intraFrameInterval = 0;
    encPrm.chCreateParams[i].encodingPreset = 0;
    encPrm.chCreateParams[i].enableAnalyticinfo = 0;
    encPrm.chCreateParams[i].enableWaterMarking = 0;
    encPrm.chCreateParams[i].defaultDynamicParams.inputFrameRate = 60;
    encPrm.chCreateParams[i].rateControlPreset = 0;
    encPrm.chCreateParams[i].defaultDynamicParams.targetBitRate = 100 * 1000;
    encPrm.chCreateParams[i].defaultDynamicParams.interFrameInterval = 0;
    encPrm.chCreateParams[i].defaultDynamicParams.mvAccuracy = 0;
    }

    In Original,  VENC_PRIMARY_CHANNELS = 2 and VENC_CHN_MAX = 4,the first, second channel will be set as H264 format, the third channel should be MJPEG. That is why I tried to change the value of  VENC_PRIMARY_CHANNELS to 3 and set all channel setting to H264. Please let me know that thinking is correct or not, and show me how to make the encoder link in M3 understand the third stream should be encoded as H264, not MJPEG for this usecase. I am seriously need your help.


  • Finally, I found out the problem. The wistream, system server, stream.c should be modified carefully to work with H264 instead of MJPEG. The wrong update setting, LOCK and unclock frame can make system freezed. thanks.

  • Hi Bioz,

    Is it possible to encode raw yuv to h264 and save the content in mp4 container using OpenMax API's rather than gstreamer.

    Regards,

    Baz

  • Hi ,

    I'm also facing the same problem which you already faced !!!

    What is the solution to solve this issue ? (Third stream MJPEG to H264)

    How to set the parameter values and all ?

    Let me know !

    Regards,

    Rajesh Kannan.S

  • Hi bioz,

    Now I'm trying to implement the third stream from MJPEG to MPEG4 .
    After changed the codec type in application (sys_server) side I'm getting the ERROR

    [m3video] 12076:ERR::linkID:10000025::channelID:2::errorCode:-4::FileName:links_m3video/iva_enc/encLink_mpeg4.c::linuNum:1269::errorCondition:(iresStatus == IRES_OK)
    [m3video] 12076: Assertion @ Line: 901 in links_m3video/iva_enc/encLink_common.c: retVal == ENC_LINK_S_SUCCESS : failed !!!

    Can you guide me to solve this issue ?

    Regards,

    Rajesh Kannan.S