Search code examples
c++visual-studio-2010opencvmjpeg

Extract still image from MJPEG file?


I need to modify each jpg-image of a mjpeg file.

I have to use Visual Studio C++ 2010.

So far, i need to a) load a mjpeg file from source and b) extract an bitmap (CImage, byte array, ...)

In pseudo code it should look like:

fun getBitmap(filename, timestamp)
{
  MJPEG myInput = Open(filename);
  BITMAP myOutput = myInput.getBitmap(timestamp);
  return myOutput;
}

What would be a got way to solve this problem? I already tried come along with OpenCV2.1.0 but there is always a LNK2001 error. (Tutorial from the official site).

Is OpenCV the correct way or does anyone knows a way more easy?


Solution

  • Do you want to use the JPEG images in the video or would you decompress them anyway?

    An MJPEG stream consists of lots of JPEG images, without the usual JPEG header (and the code dictionaries). So if you want to extract them losslessly and get a lot of JPEG files in a directory, another tools may suit you better.

    However, if you would modify them anyway, you'll need to decompress them. OpenCV is a nice way to do that as long as you have the necessary backends to decode the stream (some codecs for Windows... on Linux, the ffmpeg libraries will decode almost everything for you).

    So I would do something like this:

    CvCapture *capture = cvCaptureFromFile("filename.avi");
    IplImage *current_frame = NULL;
    while(current_frame = cvQueryFrame(capture)) {
      process(current_frame); // that's your modification code
    }
    

    See this:

    http://opencv.willowgarage.com/documentation/c/highgui_reading_and_writing_images_and_video.html

    For the linker error: LNK2001 is "unresolved external symbol", so... have you added the library? (Additional Dependencies, add all four libs (cv210.lib cxcore210.lib, cvaux210.lib and highgui210.lib, or... check your OpenCV installation for correct names). Ensure that your project is compiled for 32 bits (or the same as OpenCV), and do not forget to add the path to the libraries.