As you can see, the framecount is negative, and I cannot set CAP_PROP_FRAME_COUNT. Hence, I am forced to read through all earlier frames, but there are many of them in my application (not this simplified example).
Place your raw video files (h264) in containers (avi, mp4 etc.)
A raw video file such as h264 has no header infomation allowing you to seek to a specific point withing the file (frame) or detailing how many frames are available, it is simply the raw encoded video data with all the information required to decode it.
Thanks for bringing this to my attention. Although that specific post didn’t contain obvious falsehoods, other posts by that user did. The "<lang>Copy code" strings showed up in several posts.
I would expect any (properly containered) video to at least report a correct video duration, which should be accurate… but I think I remember that OpenCV doesn’t expose such a property, although it does expose a frame count, which is merely calculated from duration and self-reported frame rate.
True but the user’s question was with reference to a raw .h264 file which unless I am mistaken doesn’t have any meta information regarding number of frames etc. It 100% can’t if its streamed from a camera but maybe it can in other circumstances when its length as apposed to start coded prefixed?