Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you have to call cap.read() once for each image you want to read from the video, not only once.

also, you probably should not rely on values from CAP_PROP_POS_FRAMES or CAP_PROP_FRAME_COUNT, those might not be correct (or even supported), depending on the codec. then, while(frame_number <= video_length) is one too many. so:

int frame_number=0;
if (cap.isOpened())
{
    while(cap.read(frame)) //the last frame of the movie will be invalid. check for it !
    {
        Imgcodecs.imwrite(output + "/" + frame_number +".jpg", frame);
        frame_number++;
    }
    cap.release();
}