Opencv VideoCapture set CV_CAP_PROP_POS_FRAMES not working

后端 未结 4 1845
醉酒成梦
醉酒成梦 2020-12-09 12:41

I am using opencv to read frames from a video output from a Vivotek Camera using the mpeg compression. I am trying to use the function to start the video from a particular

4条回答
  •  情歌与酒
    2020-12-09 12:57

    Just as BlouBlou said, when you read some high compression video format with FFMPEG, it used "key frame" technology to decode video. So set CV_CAP_PROP_POS_FRAMES property will not work as you want.

    I tested 5 mpeg videos to read all frames from them. Get total frame count using long totalFrameNumber = capture.get(CV_CAP_PROP_FRAME_COUNT);

    Then I read each video twice, first time not set CV_CAP_PROP_POS_FRAMES to 0, second time set it.

    It did drop some frames when you set CV_CAP_PROP_POS_FRAMES to 0, about 10 frames each video. I guess because the key frame is not in the first frame of the video, so FFMPEG skip some frames to the first key frame. But some video format such as .avi won't appear such problem. I hope my real experience will save other people much time (well I spent to find this page not too long but enough).

    Anyway, highly recommend not to using CV_CAP_PROP_POS_FRAMES to get a specific frame when you face mpeg format video. It is a smart choice to set CV_CAP_PROP_POS_MSEC:)

提交回复
热议问题