Simple frame decoder library

I am looking for a simple c / C ++ library that will allow you to extract the first frame of a video as an uchar array. And have easy access to access the next.

I know FFMPEG, but I need to play with the package, etc., and I am surprised that nowhere on the network can I find a lib that allows something like:

Video v = openVideo ("path"); uchar * data = v.getFrame (); v.nextFrame ();

I just need to extract the frames of the video to use it as a texture ... there is no need to transcode after or something else ...

of course, something that reads more format than was possible would be great, for example, built on libavcodec; p

And I use Windows 7

Thank!

+3
source share
3 answers

Here is an example with OpenCV:

#include <cv.h>
#include <highgui.h>

int
main(int argc, char **argv)
{       
    cv::VideoCapture capture(argv[1]);
    if (capture.grab())
    {   
        cv::Mat_<char> frame;
        capture.retrieve(frame);
        //
        // Convert to your byte array here
        //
    }    
    return 0;
}

It has not been tested, but I cannibalized it from some existing working code, so you do not need to wait long for it to work.

cv::Mat_<unsigned char>essentially a byte array. If you really need something explicitly type unsigned char *, then you can malloc the space of the appropriate size and iterate over the matrix with

You can convert cv::Matto an array of bytes using pixel positions ( cv::Mat_::at()) or iterators ( cv::Mat_::begin()and friends).

There are many reasons why libraries rarely provide image data as a simple pointer, for example:

  • , . .
  • ( - RGB-, ?) .
  • ( ..).

, , .

+3
+1

Use DirectShow. Here is the article: http://www.codeproject.com/KB/audio-video/framegrabber.aspx There are add-ons for DirectShow for decoding various video formats. Here is one of the sites where you can grab free DirectShow filter packages for decoding some common formats that are not directly supported by DirectShow: http://www.free-codecs.com/download/DirectShow_FilterPack.htm

0
source

Source: https://habr.com/ru/post/1766026/


All Articles