Take the tour ×

I would like to open a small video file and map every frames in memory (to apply some custom filter). I don't want to handle the video codec, I would rather let the library handle that for me.

I've tried to use Direct Show with the SampleGrabber filter (using this sample http://msdn.microsoft.com/en-us/library/ms787867(VS.85).aspx), but I only managed to grab some frames (not every frames!). I'm quite new in video software programming, maybe I'm not using the best library, or I'm doing it wrong.

I've pasted a part of my code (mainly a modified copy/paste from the msdn example), unfortunately it doesn't grabb the 25 first frames as expected...


hr = pGrabber->SetOneShot(TRUE);
hr = pGrabber->SetBufferSamples(TRUE);

pControl->Run(); // Run the graph.
pEvent->WaitForCompletion(INFINITE, &evCode); // Wait till it's done.

// Find the required buffer size.
long cbBuffer = 0;
hr = pGrabber->GetCurrentBuffer(&cbBuffer, NULL);


    char *pBuffer = new char[cbBuffer];
    hr = pGrabber->GetCurrentBuffer(&cbBuffer, (long*)pBuffer);

    hr = pGrabber->GetConnectedMediaType(&mt);
    pVih = (VIDEOINFOHEADER*)mt.pbFormat;



Is there somebody, with video software experience, who can advise me about code or other simpler library?


Edit: Msdn links seems not to work (see the bug)

share|improve this question
add comment

6 Answers

up vote 21 down vote accepted

Currently these are the most popular video frameworks available on Win32 platforms:

  1. Video for Windows: old windows framework coming from the age of Win95 but still widely used because it is very simple to use. Unfortunately it supports only AVI files for which the proper VFW codec has been installed.

  2. DirectShow: standard WinXP framework, it can basically load all formats you can play with Windows Media Player. Rather difficult to use.

  3. Ffmpeg: more precisely libavcodec and libavformat that comes with Ffmpeg open- source multimedia utility. It is extremely powerful and can read a lot of formats (almost everything you can play with VLC) even if you don't have the codec installed on the system. It's quite complicated to use but you can always get inspired by the code of ffplay that comes shipped with it or by other implementations in open-source software. Anyway I think it's still much easier to use than DS (and much faster). It needs to be comipled by MinGW on Windows, but all the steps are explained very well here (in this moment the link is down, hope not dead).

  4. QuickTime: the Apple framework is not the best solution for Windows platform, since it needs QuickTime app to be installed and also the proper QuickTime codec for every format; it does not support many formats, but its quite common in professional field (so some codec are actually only for QuickTime). Shouldn't be too difficult to implement.

  5. Gstreamer: latest open source framework. I don't know much about it, I guess it wraps over some of the other systems (but I'm not sure).

All of this frameworks have been implemented as backend in OpenCv Highgui, except for DirectShow. The default framework for Win32 OpenCV is using VFW (and thus able only to open some AVI files), if you want to use the others you must download the CVS instead of the official release and still do some hacking on the code and it's anyway not too complete, for example FFMPEG backend doesn't allow to seek in the stream. If you want to use QuickTime with OpenCV this can help you.

share|improve this answer
add comment

I have used OpenCV to load video files and process them. It's also handy for many types of video processing including those useful for computer vision.

share|improve this answer
add comment

Using the "Callback" model of SampleGrabber may give you better results. See the example in Samples\C++\DirectShow\Editing\GrabBitmaps.

There's also a lot of info in Samples\C++\DirectShow\Filters\Grabber2\grabber_text.txt and readme.txt.

share|improve this answer
add comment

Try using the OpenCV library. It definitely has the capabilities you require.

This guide has a section about accessing frames from a video file.

share|improve this answer
add comment

If it's for AVI files I'd read the data from the AVI file myself and extract the frames. Now use the video compression manager to decompress it.

The AVI file format is very simple, see: http://msdn.microsoft.com/en-us/library/dd318187(VS.85).aspx (and use google).

Once you have the file open you just extract each frame and pass it to ICDecompress() to decompress it.

It seems like a lot of work but it's the most reliable way.

If that's too much work, or if you want more than AVI files then use ffmpeg.

share|improve this answer
add comment

OpenCV is the best solution if video in your case only needs to lead to a sequence of pictures. If you're willing to do real video processing, so ViDeo equals "Visual Audio", you need to keep up track with the ones offered by "martjno". New windows solutions also for Win7 include 3 new possibilities additionally:

  1. Windows Media Foundation: Successor of DirectShow; cleaned-up interface
  2. Windows Media Encoder 9: It does not only include the programm, it also ships libraries for coding
  3. Windows Expression 4: Successor of 2.

Last 2 are commercial-only solutions, but the first one is free. To code WMF, you need to install the Windows SDK.

share|improve this answer
add comment

Your Answer


