Search code examples
opencvvideovideo-processing

I want to convert video to jpg image


I'm going to analyze video.

I want to convert video to image per sec.

I mean if the video which I want to analyze is 1 hour. The program which I want to make will make output 3600 image files.

How can I make it?

Is there any solution for it?

The worst case is that I have to run the video and take snapshot per second.

I need your help. Thank you.


Solution

  • All you need is to load the video and save individual frames in a loop. This is not exactly a snapshot, but, you are just saving each and every frame.

    Please mind the resolution of the video can also affect the speed in which the frames are processed.

    I am going to assume you are using C++. For this, the code will look like this:

    VideoCapture cap("Your_Video.mp4");
    // Check if camera opened successfully
    if(!cap.isOpened())
    {
    cout << "Error opening the video << endl;
    return -1;
    }
    
    while(1)
    {
    Mat frame;
    cap.read(frame);
    if (frame.empty())
    {
    break;
    }
    
    // This is where you save the frame
    imwrite( "Give your File Path", frame );
    
    }
    cap.release();
    destroyAllWindows();
    return 0;
    }