Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:36:26+00:00 2026-05-25T20:36:26+00:00

I have one file in which only h264 frames are there in form of

  • 0

I have one file in which only h264 frames are there in form of NAL unit.
So now is there any method so i can count the duration of that file?

I dont know how many frames are there in file.
I have only file size.

PS: All i want to do is in C language and on Linux platform.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:36:27+00:00Added an answer on May 25, 2026 at 8:36 pm

    Container file

    First, there is no such a thing as H264 file. There can be a container file (MP4, AVI, MKV) that holds the H264 encoded video. That container format usually also holds the data telling you the contained video duration. So you have to parse that file, check the format documentation to see where the duration is saved, and then extract it.

    Easiest way is to use FFMPEG like Augusto suggested.

    NAL Byte Stream

    If your file is only NAL units saved one after another, like in a NAL byte stream, there IS NO WAY that you can get the video duration! Since H264 encoded picture doesn’t hold timing information.

    If that is the case, you still can make an approximation if you know the video FPS… You need to count all frames in the file excluding:

    • Sequence Parameter Sets
    • Picture Parameter Sets
    • End Of Stream
    • End Of Sequence
    • Filter Data
    • Access Unit Delimiter

    And then do the math: NUMBER_OF_FRAMES / FPS = DURATION_IN_SECONDS

    RTP stream

    If you are wrong and there is RTP header on top of each NAL unit, you can easily get the video duration by checking the RTP time of each RTP header. What the bytes in RTP Header mean, you can find out here: http://www.networksorcery.com/enp/protocol/rtp.htm. You want to get the TIMESTAMP part (4 bytes integer) from each one. The code should do this:

    int last_timestamp = GetNextTimestamp();
    double duration_in_ms = 0;
    
    while(true)
    {
        int next = GetNextTimestamp();
        duration_in_ms += (next - last_timestamp)/90000.0;
        last_timestamp = next;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file which contains only one class. how can I know
I tried to read a text file which have only one line. File size
I have a site which has only ONE file: index.html . I just want
I have one file in my project, (the readme file,) which I would like
i have one php file which process adding of record in Database fro array.
I have just one cs file in my repository which Git seems to think
I have an XML file which has many section like the one below: <Operations>
I have recently converted 10 JavaScript files into one file, which I then run
I have an Excel file with one column which is filled with numbers. I
I have a file called webpart.cs which is called by one of my masterpages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.