cv::VideoCapture::set not working with OpenCV version 2.x (Bug #481)


Added by Sean Strout over 4 years ago. Updated about 2 years ago.


Status:Cancelled Start date:
Priority:High Due date:
Assignee:- % Done:

0%

Category:highgui-video
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Calls to set video capture properties, i.e. to randomly seek to a frame in a video file (CV_CAP_PROP_POS_FRAMES), have no effect in version 2 of OpenCV.

I have tested with OpenCV 1.X and verified the function works as documented.


Related issues (Add)

duplicates Bug #203: CV_CAP_PROP_POS_* doesn't work for all filetypes Cancelled Delete

History

Updated by PaulSolt@gmail.com - about 4 years ago

The only workaround that I've discovered (OpenCV 2.1) is to use videos that have been encoded with all key frames. Using Quicktime 7 I can re-encode videos to include all key frames and this allows me to seek to random positions.

Quick notes:
H.264 and JPEG videos will work without issues
MPEG4 videos don't behave the same way. To get the same functionality I need to set the frame/query frame twice. I've also noticed the initial frame being off, unless I add an initial call to my SeekToFrame(0) function below.

Code in C# using Emgu.CV-2.1.0.0 (OpenCV 2.1)

public void [[SeekToFrame]](int frame) {
            if(null != capture) {
                Debug.WriteLine("VideoController.SeekToFrame(" + frame + ")");
                capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES, (double)frame);

                frameImage = capture.QueryFrame();

                double framePos = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
                Debug.WriteLine("VideoController.SeekToFrame() 1: " + framePos);

                // MPEG4 Seeking Workaround: Paul Solt @ 10-13-10
                // The frame needs to be set twice and queried twice in order to seek to the correct position
                // Seeking twice should not affect JPEG and H.264 codec videos
                capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES, (double)frame);
                frameImage = capture.QueryFrame();

                framePos = capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
                Debug.WriteLine("VideoController.SeekToFrame() 2:" + framePos);
            }
}

Replying to sstrout:

Calls to set video capture properties, i.e. to randomly seek to a frame in a video file (CV_CAP_PROP_POS_FRAMES), have no effect in version 2 of OpenCV.

I have tested with OpenCV 1.X and verified the function works as documented.

Updated by Vadim Pisarevsky over 3 years ago

duplicate of #203

  • Status changed from Open to Done
  • Pull request set to duplicate

Updated by Andrey Kamaev over 2 years ago

  • Status changed from Done to Cancelled

Updated by Andrey Kamaev about 2 years ago

  • Category changed from highgui-images to highgui-video

Also available in: Atom PDF