Using cvSetCaptureProperty() you can cycle through frames, either in miliseconds or by ordinal frame number.
int cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
property_id is a property you would need to use. It can be one of the following:
- CV_CAP_PROP_POS_MSEC - position in milliseconds from the file beginning
- CV_CAP_PROP_POS_FRAMES - position in frames
- CV_CAP_PROP_POS_AVI_RATIO - position in relative units (0 - start of the file, 1 - end of the file)
- CV_CAP_PROP_FRAME_WIDTH - width of frames in the video stream (only for cameras)
- CV_CAP_PROP_FRAME_HEIGHT - height of frames in the video stream (only for cameras)
- CV_CAP_PROP_FPS - frame rate (only for cameras)
- CV_CAP_PROP_FOURCC - 4-character code of codec (only for cameras).
The first two is of your interest.
EDIT: more info :)
You can cycle through frames just by repeatedly calling the mentioned function with various frame indices.
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, frameIndex);
Example:
IplImage* frame;
CvCapture* capture = cvCreateFileCapture("test.avi");
/* iterate through first 10 frames */
for (int i = 0; i < 10; i++)
{
/* set pointer to frame index i */
cvSetCaptureProperty(capture, CV_CAP_POS_FRAMES, i);
/* capture the frame and do sth with it */
frame = cvQueryFrame(capture);
}
You could put similar code to execute each time user clicks a button to forward/rewind the video.
The C++ method (OpenCV 2 and higher) would be to use this method instead with the same property_id and value.
bool VideoCapture::set(int property_id, double value)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…