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 7192547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:57:45+00:00 2026-05-28T19:57:45+00:00

I am using ffmpeg to decode a video file in C. I am struggling

  • 0

I am using ffmpeg to decode a video file in C. I am struggling to get either the count of the current frame I am decoding or the timestamp of the frame. I have read numerous posts that show how to calculate an estimated frame no based on the fps and frame timestamp, however I am not able to get either of those.

What I need: fps of video file, timestamp of current frame or frame no(not calculated)

What I have: I am able to get the time of the video using

pFormatCtx->duration/AV_TIME_BASE

I am counting the frames currently as I process them, and getting a current frame count, this is not going to work longterm though. I can get the total frame count for the file using

pFormatCtx->streams[currentStream->videoStream]->nb_frames

I have read this may not work for all streams, although it has worked for every stream I have tried.

I have tried using the time_base.num and time_base.den values and packet.pts, but I can’t make any sense of the values that I am getting from those, so I may just need to understand better what those values are.

Does anyone know of resources that show examples on how to get this values?

  • 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-28T19:57:47+00:00Added an answer on May 28, 2026 at 7:57 pm

    This url discusses why the pts values may not make sense and how to get sensible ones:
    An ffmpeg and SDL Tutorial by Dranger

    Here is an excerpt from that link, which gives guidance on exactly what you are looking for in terms of frame numbers and timestamps. If this seems useful to you then you may want to read more of the document for a fuller understanding:

    So let’s say we had a movie, and the frames were displayed like: I B B
    P. Now, we need to know the information in P before we can display
    either B frame. Because of this, the frames might be stored like this:
    I P B B. This is why we have a decoding timestamp and a presentation
    timestamp on each frame. The decoding timestamp tells us when we need
    to decode something, and the presentation time stamp tells us when we
    need to display something. So, in this case, our stream might look
    like this:

    PTS:    1 4 2 3
    DTS:    1 2 3 4
    Stream: I P B B
    

    Generally the PTS and DTS will only differ when the stream we are
    playing has B frames in it.

    When we get a packet from av_read_frame(),
    it will contain the PTS and DTS values for the information inside that
    packet. But what we really want is the PTS of our newly decoded raw
    frame, so we know when to display it.

    Fortunately, FFMpeg supplies us with a "best effort" timestamp, which
    you can get via, av_frame_get_best_effort_timestamp()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been trying to decode an MP3 file to pcm, using ffmpeg API,
I am using ffmpeg to decode a file and play it back on an
I convert a file using ffmpeg command in which audio and video bitrate are
How do I decode a file with hardware acceleration with ffmpeg? I have written
I have just started using ffmpeg for splitting up a video into images. What
I created an .png image from a video using ffmpeg tool and i want
i found some articles, some projects to create thumbnail of a video, using ffmpeg.exe,
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am using ffmpeg to decode an rtsp stream which is displayed using DirectShow
I am trying to decode a H263 4CIF(704x576) resolution file with ffmpeg, but it

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.