• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Embedded Software » Multimedia Software Codecs » Multimedia Software Codecs forum » How to corretcly insert timestamps to h264 stream on dm365 using h264 encoder 2.20
Share
Multimedia Software Codecs
  • Forum
Options
  • Subscribe via RSS

Forums

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

This question is answered
Jan Pohanka
Posted by Jan Pohanka
on Apr 05 2012 08:56 AM
Expert1290 points

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 

dm365 h264 encoder timestamp
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Yashwant Dutt
    Posted by Yashwant Dutt
    on Apr 05 2012 14:34 PM
    Genius15110 points

    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

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jan Pohanka
    Posted by Jan Pohanka
    on Apr 06 2012 02:44 AM
    Expert1290 points

    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

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jan Pohanka
    Posted by Jan Pohanka
    on Apr 06 2012 03:34 AM
    Expert1290 points

    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 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Veeranna Hanchinal
    Posted by Veeranna Hanchinal
    on Apr 09 2012 01:14 AM
    Expert5345 points

    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

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jan Pohanka
    Posted by Jan Pohanka
    on Apr 10 2012 07:34 AM
    Expert1290 points

    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 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jan Pohanka
    Posted by Jan Pohanka
    on Apr 10 2012 07:59 AM
    Verified Answer
    Verified by Jan Pohanka
    Expert1290 points

    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 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use