Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ : What's the easiest library to open video file

Tags:

c++

windows

video

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);  for( int i = 0 ; i < 25 ; ++i ) {     pControl->Run(); // Run the graph.     pEvent->WaitForCompletion(INFINITE, &evCode); // Wait till it's done.      char *pBuffer = new char[cbBuffer];     hr = pGrabber->GetCurrentBuffer(&cbBuffer, (long*)pBuffer);      AM_MEDIA_TYPE mt;     hr = pGrabber->GetConnectedMediaType(&mt);     VIDEOINFOHEADER *pVih;     pVih = (VIDEOINFOHEADER*)mt.pbFormat;      [...] }  [...] 

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

Thanks

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

like image 844
Steve Gury Avatar asked Sep 01 '08 13:09

Steve Gury


People also ask

Is there a graphics library for C++?

h library − The graphic. h library is used to add graphics to your C++ program. For graphic programming, it is a must include library as it contains all required methods.

Where are C++ libraries located?

Usually, there is '/lib' folder on Windows or '/usr/lib' folder on Linux that contains all the libraries. Once the library is installed, the compiler and the linker know the path of the library to use, and the library is ready for use.

How many C++ libraries are there?

C++ comes with two standard libraries: the old C library (libc. lib), and the new C++ library (libcp. lib), which is logically divided into the stream library, and STL, the standard template library.


1 Answers

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.

like image 82
martjno Avatar answered Sep 23 '22 08:09

martjno