Ffmpeg c / c ++ get frame count or timestamp and fps

I am using ffmpeg to decode a video file in C. I am struggling to get either the score of the current frame that I am decoding or the timestamp of the frame. I read a lot of posts that showed how to calculate the estimated frame without any reason for the time and frame time, however, I can not get any of them.

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

What I have: I can get the time of the video using

pFormatCtx->duration/AV_TIME_BASE 

I am calculating frames at the moment when I process them, and I get the current number of frames, but this will not work for a long time. I can get the total number of frames for a file using

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

I read that this may not work for all threads, although it worked for every thread that I tried.

I tried using the values ​​of time_base.num and time_base.den and packet.pts, but I can’t understand what values ​​I get from them, so I may just need to better understand what these values ​​are.

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

+6
source share
1 answer

This url discusses why point values ​​may not make sense and how to get reasonable: ffmpeg and SDL tutorial from Dranger

Here is an expert on this link, which gives instructions on what exactly you are looking for in terms of the number of frames and timestamps. If this seems useful to you, you can read more of the document for a more complete understanding:

So, let's say we had a movie, and the frames were shown as: I'm BB P. Now we need to know the information in P before we can display either the B-frame. Because of this, frames can be stored as follows: I am PB B. That's why we have a decoding timestamp and presentation timestamp for each frame. The decoding timestamp tells us when we need to decode something, as well as the time at which the presentation time indicates when we need to display something. So, in this case, our stream may look like this:

 PTS: 1 4 2 3 DTS: 1 2 3 4 Stream: IPBB 

Typically, PTS and DTS will only differ when the game stream has B frames in it.

When we get the package from av_read_frame (), it will contain the PTS and DTS values ​​for the information inside the package. But we really want the PTS of our newly decoded raw frame, so we know when to show it.

Fortunately, FFMpeg provides us with the “best effort” timestamp, which you can go through av_frame_get_best_effort_timestamp ()

+4
source

Source: https://habr.com/ru/post/906911/


All Articles