Search code examples
c++opencvsave-image

How to save any frame of a video


I want to save some frame of my video. I try using CvsaveImage() in visual C++ 2010, but it cannot save many frame, because I don't know how to save the next frame with the different name. So, the old frame will be overwritten by the next one.

Can anybody help me to save many frame with different name?


Solution

  • Use a counter, such as the frame number or an integer that you increment each time you save a new file. Append the value of this counter at the end of you file name and you'll get a unique filename until the counter overflows (more than 4 billion frames for an unsigned integer).

    static unsigned int counter = 0;
    [...]
    char pFileName[MAX_PATH] = {0};
    sprintf(pFileName, "<YourFilePath>\\Frame_%u.jpg", counter++);
    [...]