Search code examples
c++opencvffmpegbuffervideo-processing

Where is opencv2's cvcapture and their subclass?


I checked this Topic(process video stream from memory buffer), and I would like to do the same in this 1st answer. I tried to create a new class file that inherited from cvCapture_FFMPEG, and to override the "open" function. But I can't find any OpenCV module where there is a class named "cvCapture_FFMPEG".

I’m assuming that "cvCapture_FFMPEG" is nowhere in OpenCV and their API. Am I right? If so, could you tell me the best way to handle a buffer in OpenCV?

Please help.


Solution

  • As you can see here, there exists a constructor for cv::Mat in which you directly give the buffer representing a frame. Why not try to use this alongside memcpy to update the content of the Mat object whenever the buffer has new content?

    Something like that:

    /*myBuffer is a void* pointing on your data.
    myBufferType is very important as it will give the number of bytes to 
    be read for each element*/
    cv::Mat myImage(height, width, myBufferType, myBuffer); 
    
    while(1){
    
        if(myBufferHasBeenUpdated)
            std::memcpy(Mat.data, myBuffer, numberOfBytesToCopy);
    
        //Performing some operations on the Mat object
    }   
    

    EDIT: I saw you changed the title of your question. Here is the documentation about cv::VideoCapture that is in the highgui module of OpenCV. If you want to read a video directly from a file, it's the best way to proceed. However, if you want to read a video already in a buffer in memory like the topic you mentioned, I don't think there is a way to easily use it.