get() CAP_PROP_FRAME_COUNT ! opencv. :
int64_t CvCapture_FFMPEG::get_total_frames() const
{
int64_t nbf = ic->streams[video_stream]->nb_frames;
if (nbf == 0)
{
nbf = (int64_t)floor(get_duration_sec() * get_fps() + 0.5);
}
return nbf;
}
This means that it will first consider the stream header for nb_frames, which you can check with ffprobe. If there is no such field, then there is no better way to get the frame number than direct video decoding. Opencv made a rough estimate get_duration_sec() * get_fps() + 0.5, which, of course, does not mean accuracy.
Thus, in order to get the correct frame number, you must decode and read the entire stream, or you must ask the video generator to generate the correct stream header with a field nb_frames.
source
share