VFR: obtain FR/duration/timestamp of a given frame?

asked 2020-09-28 11:52:06 -0600

kebwi gravatar image

I have a video which freezes for a few seconds. I know for a fact that the freeze spans a real window of time during which the camera or camera-to-storage system simple failed to save frames, but thanks for a timecode generator on the camera, the camera is able to label the frozen frame as of long duration spanning the freeze, so that a video player knows to pause at the frozen frame during playback in order to maintain realtime playback. Likewise, MediaInfo reports that the video has a very low minimum frame rate of .083 FPS, obviously corresponding to the frozen frame of course. So I know the metadata for the freeze is in there. QT Player knows to pause at that point during playback and MediaInfo can see the min FR.

I need to obtain this information during Python CV2 analysis. I know about CAP_PROP_FPS of course, but that isn't helpful for a VFR, and I know that I can seek to a given timestamp to retrieve a frame with CAP_PROP_POS_MSEC, and of course if I seek within the frozen period I simply receive the same frame over and over until I seek to some timestamp outside the freeze, so OpenCV can give me the frame for each timestamp, but I want to ask how long a given frame should last? If I simply read frames in sequence via read(), I want to know how long each frame should last. In effect, if I'm emulating playback, like QT player, how do I know how long to pause on each frame, ala the variable frame rate and all that?


edit retag flag offensive close merge delete



opencv is a computer-vision library, not a video player (i think, you're barking up the wrong tree)

berak gravatar imageberak ( 2020-09-29 01:43:38 -0600 )edit

@berak I'm in roughly the same boat as OP and I need OpenCv to draw a crosshair on top of the video using eye movement data and hence I need to be able to get accurate timestamps.

jdevoldere gravatar imagejdevoldere ( 2020-09-29 02:29:41 -0600 )edit

frames do not "last". they are presented at a "presentation timestamp" (PTS). that's a common notion in video container formats. you could figure the "length" of a frame from the interval to the next frame's PTS. that'll fail for the last frame since it has no successor. if decoding and getting POS_MSEC happens to give you correct information, go with that. it may simply be frame number * average FPS, or it may be accurate. that depends on a lot of factors. if you need absolute certainty, use a media library such as ffmpeg.

crackwitz gravatar imagecrackwitz ( 2020-09-30 08:46:03 -0600 )edit

@crackwitz I can get the PTS of the current frame with CAP_PROP_POS_MSEC, but how do I get it for the upcoming frame?

jdevoldere gravatar imagejdevoldere ( 2020-10-02 04:09:22 -0600 )edit

read frame, get time, wait until due, show

crackwitz gravatar imagecrackwitz ( 2020-10-12 16:21:10 -0600 )edit