Avcodec / avformat Number of frames in a file

I need to know how to find the total number of frames in a video file using avcodec / avformat.

I have a project that I am building from someone else who used ffmpeg libraries to decode video streams. I need to refine some functionality in order to search frame by frame, and therefore my first task is simply to calculate the total number of frames in the file. AVStream.nb_frames seems like a reasonable place to search, but it is always 0 with all the video files I tried. Does the total number of frames output from AVFormatContex.duration in the best way?

+4
source share
1 answer

The only way to find the exact number of frames is to go through all of them and count. I worried about it many times, tried many different tools (including ffmpeg) and read a lot. Sorry, but in general there is no other way. Some formats simply do not store this information, so you need to count.

+4
source

All Articles