Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV: VideoCapture::get(CV_CAP_PROP_FPS) returns 0 FPS

I'm trying to timestamp the frames when recording video using OpenCV 3.1.0. However, when using VideoCapture::get(CV_CAP_PROP_POS_MSEC) to get the millisecond timestamp of the last frame grabbed the value returned is always 0.

The code I'm using:

int fps = 10;
VideoCapture cap(0); // open the default camera

cap.set(CV_CAP_PROP_FPS, fps);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1024);

if(!cap.isOpened())  // check if we succeeded
    return -1;

Mat testFrame;
cap >> testFrame;
cap >> testFrame;
cap >> testFrame;

Size outSize = Size(testFrame.cols, testFrame.rows);

VideoWriter writer("video.avi", CV_FOURCC('M','J','P','G'), fps, outSize, true);

for(; ;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera

    long stamp = cap.get( CV_CAP_PROP_POS_MEC ); // THIS DOESN'T SEEM TO WORK

    std::cout << "Timestamp: " << stamp << std::endl;

    writer.write(frame);
}

As output I always get many lines like the following:

Timestamp: 0

Could you help me understand what I'm doing wrong?

Thanks :)

OpenCV: VideoCapture::get(CV_CAP_PROP_FPS) VideoCapture::get(CV_CAP_PROP_POS_MSEC ) returns 0 FPS0

I'm trying to timestamp the frames when recording video using OpenCV 3.1.0. However, when using VideoCapture::get(CV_CAP_PROP_POS_MSEC) to get the millisecond timestamp of the last frame grabbed the value returned is always 0.

The code I'm using:

int fps = 10;
VideoCapture cap(0); // open the default camera

cap.set(CV_CAP_PROP_FPS, fps);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1024);

if(!cap.isOpened())  // check if we succeeded
    return -1;

Mat testFrame;
cap >> testFrame;
cap >> testFrame;
cap >> testFrame;

Size outSize = Size(testFrame.cols, testFrame.rows);

VideoWriter writer("video.avi", CV_FOURCC('M','J','P','G'), fps, outSize, true);

for(; ;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera

    long stamp = cap.get( CV_CAP_PROP_POS_MEC CV_CAP_PROP_POS_MSEC ); // THIS DOESN'T SEEM TO WORK

    std::cout << "Timestamp: " << stamp << std::endl;

    writer.write(frame);
}

As output I always get many lines like the following:

Timestamp: 0

Could you help me understand what I'm doing wrong?

Thanks :)