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.

How to corretcly insert timestamps to h264 stream on dm365 using h264 encoder 2.20

Dear all,

I'm capturing frames on the 5 fps and I need to insert this information into the h264 stream. On the wiki I have found that I should probably use the picture timing SEI message, but I was not able to find the correct settings yet. Bellow are parts of my code belonging to the issue.

VIDENC1_Params params;
IH264VENC_Params h264Params;
VIDENC1_DynamicParams dynParams;
IH264VENC_DynamicParams h246DynParams;

params = Venc1_Params_DEFAULT;
params.maxWidth = width;
params.maxHeight = height;
params.encodingPreset = XDM_HIGH_SPEED;
params.inputChromaFormat = XDM_YUV_420SP;
params.rateControlPreset = IVIDEO_NONE;
params.maxBitRate = 200000;

h264Params = IH264VENC_PARAMS;
h264Params.videncParams = params;
h264Params.enableVUIparams = 0x0f;
params.size = sizeof(IH264VENC_Params);

dynParams = Venc1_DynamicParams_DEFAULT;
dynParams.targetBitRate = params.maxBitRate;
dynParams.inputWidth = width;
dynParams.inputHeight = height;
dynParams.refFrameRate = 5000;
dynParams.targetFrameRate = 5000;
dynParams.interFrameInterval = 0;

h246DynParams = H264VENC_TI_IH264VENC_DYNAMICPARAMS;
h246DynParams.videncDynamicParams = dynParams;
h246DynParams.VUI_Buffer = &VUIPARAMBUFFER;
h246DynParams.VUI_Buffer->numUnitsInTicks = 1;
h246DynParams.VUI_Buffer->timeScale = 25;
dynParams.size = sizeof(IH264VENC_DynamicParams);

inArgs.size = sizeof(IH264VENC_InArgs);
inArgs.inputID = inBuf->index + 1;
inArgs.topFieldFirstFlag = 1;

inH264Args.videncInArgs = inArgs;
inH264Args.timeStamp = timestamp;
timestamp += 20;
inH264Args.insertUserData = 0;
inH264Args.lengthUserData = 0;
inH264Args.numOutputDataUnits = 0;

When I add a mkv header to the stream and play it with mplayer it is still plays with 25fps (default fps) with no regard to inH264Args.timeStamp value or VUI_Buffer->numUnitsInTicks and timeScale. I think I must be missing some parameter...

Could please someone give me an advice how to correctly set the timestamping to the codec?

with best regards
Jan 

  • Jan,

    I am not sure if you setting are correct. Can you try the below -

    Init value of -> timestamp = 0

    numUnitsInTicks =  1

    timeScale =  25

    timestamp = timestamp;

    timestamp += 5 ;

    OR

    numUnitsInTicks =  1

    timeScale =  5

    timestamp = timestamp;

    timestamp += 1 ;

     

    I have seen that few of players/tools does not really respect timestamp value sent in SEI message but directly get framerate from VUI. For such cases, 2 should also work. On top of it, many of conatiner format conversion tool may seek framerate explicitly though some argument. In that case, you have to give information explicitly

    to that tool.

    regards

    Yashwant

  • Hi Yashwant,

    thank you for the answer. I have tried your advice but unfortunately without success. I'm still not sure if the information about numUnitsInTicks etc. are really included in the resulting videostream. Could you please suggest me some analyzer tool which is able to verify the stream? 

    I'm using only the codec engine and dm365 h264 encoder - everything else is done just by plain v4l2 api (no dmai). I found on the wiki how to send parameters to a codec through generic codec engine structs by changing their size member and typecasting. I hope this is correct. I post my code again below (shortened):

    Engine_Handle hEngine = NULL;
    VIDENC1_Handle hEncode;
    VIDENC1_Params params;
    IH264VENC_Params h264Params;
    VIDENC1_DynamicParams dynParams;
    IH264VENC_DynamicParams h246DynParams;

    CERuntime_init();

    ...

    hEngine = Engine_open("encode", NULL, NULL);
    if (hEngine == NULL)
        exit(1);

    params = Venc1_Params_DEFAULT;
    params.maxWidth = width;
    params.maxHeight = height;
    params.encodingPreset = XDM_HIGH_SPEED;
    params.inputChromaFormat = XDM_YUV_420SP;
    params.rateControlPreset = IVIDEO_NONE;
    params.maxBitRate = 200000;

    h264Params = IH264VENC_PARAMS;
    h264Params.videncParams = params;
    h264Params.enableVUIparams = 0x0f; /* is this really needed? */
    params.size = sizeof(IH264VENC_Params);

    dynParams = Venc1_DynamicParams_DEFAULT;
    dynParams.targetBitRate = params.maxBitRate;
    dynParams.inputWidth = width;
    dynParams.inputHeight = height;
    dynParams.refFrameRate = 25000;
    dynParams.targetFrameRate = 25000;
    dynParams.interFrameInterval = 0;

    h246DynParams = H264VENC_TI_IH264VENC_DYNAMICPARAMS;
    h246DynParams.videncDynamicParams = dynParams;
    h246DynParams.VUI_Buffer = &VUIPARAMBUFFER;
    h246DynParams.VUI_Buffer->numUnitsInTicks = 1;
    h246DynParams.VUI_Buffer->timeScale = 5;
    dynParams.size = sizeof(IH264VENC_DynamicParams);

    hEncode = VIDENC1_create(hEngine, (String) encoder,
       (VIDENC1_Params *)&h264Params);
    ...
    status = VIDENC1_control(hEncode, XDM_SETPARAMS,
       (VIDENC1_DynamicParams *)&h246DynParams, &encStatus);

    ...

    timestamp = 0;
    while ( get_frame ...) {
       ...
       VIDENC1_InArgs inArgs;
       IH264VENC_InArgs inH264Args;
       VIDENC1_OutArgs outArgs;
       ...
       inArgs.size = sizeof(IH264VENC_InArgs);
       inArgs.inputID = inBuf->index + 1;
       inArgs.topFieldFirstFlag = 1;

       inH264Args.videncInArgs = inArgs;
       inH264Args.timeStamp = timestamp;
       timestamp += 1;
       inH264Args.insertUserData = 0;
       inH264Args.lengthUserData = 0;
       inH264Args.numOutputDataUnits = 0;

       status = VIDENC1_process(hEncode, &inBufDesc, &outBufDesc,
         (VIDENC1_InArgs *) &inH264Args, &outArgs);
       ...
    }

    best regards
    Jan

  • Hi Yashwant,

    I have found a bug in the code in the previous post. I was setting params.size and dynParams.size after the structs were copied to the h264Params and h264DynParams so it was all wrong. From the codec guide I think I must set the h264Params.enableVUIparams flag to use numUnitsInTick and timeScale, but after enabling it VIDENC1_control(hEncode, XDM_SETPARAMS, ...) call ends with error. What am I missing, please?

    best regards
    Jan 

  • Hi Jan,

    You can check extended error bit for fail or use debug version codec lib to check which param is going wrong. To use the debug just you need to remove _debug in the lib name.

    Thanks,

    Veeranna

  • Hi Veeranna,

    extended error flag is set to IH264VENC_ERR_TIMESCALE and debug version of the codec says:

    CODEC_DEBUG_ENABLE: Inside IRES Call to Activate All Resources -> H264VENC_TI_activateAllResources
    CODEC_DEBUG_ENABLE: Control Call With SETPARAM Command
    CODEC_DEBUG_ENABLE: Error Check Time Parameters

    All params that I send to codecs can be seen in previous posts, I still can't realize which time parmeter could be the one...
    I'm using default VUI parameters through VUIPARAMBUFFER so I hope these are fine...

    regards
    Jan 

  • Dear all,

    problem is solved. I have missed this information in the codec guide.

    timescale: This should be greater than or equal to frame rate in fps.

    best regards
    Jan