Linux Matlab Video Frame Grabber - mplayerMex

mplayerMex.tar.gz  (source and mexglx compiled with gcc3.3.4 on r2006b-32bit)
Matlab R14 or newer binaries  (mexglx compiled with gcc3.2.3 should work with Matlab7.0 and later)
Associated shared libraries  (not needed if your system already has these)

New: NetAvi: win32 video server based AVI read interface for most Matlab platforms

New: A whole bunch of nasty bugs have been fixed :) if you are checking in after a while, please do try out our recent version.

This package provides a simple matlab interface with MPlayer to read frames from a video file on Linux. It hence supports codecs handled by MPlayer. MPlayer is an opensource video player supported on many platforms. 

Supplied binaries (64bit not there yet):

If your Matlab is R14SP3 or later, use the .mexglx files in mplayerMex.tar;  for Matlab R14 or later, use the second link above. To test, run testMplayer from matlab. If you see errors about missing ".so" files, the ones I think needed are here, (you could also get the rpm by searching for the .so file on www.rpmfind.net), set the LD_LIBRARY_PATH environment variable to include path for the ".so" files before starting matlab.  On 64 bit linux, you would need to run the 32 bit matlab ( matlab -glnx86 ) to use the .mexglx files.  You can use "version( '-java' )" to check if the matlab you are running is 64-bit. If all this fails, you can try recompiling as described below or send me an email with your matlab version.

Usage:

[av_hdl, av_inf] = mplayerOpen(<video filename>); 
% avi_inf contains useful properties of the video.

pixmap = mplayerReadMex(av_hdl, <frame_num>);

img = reshape(pixmap,[av_inf.Height,av_inf.Width,3]);

%Cleanup
mplayerCloseMex(av_hdl);

Please read before using

Thanks to Eugene Lubenov for his help: the extracted frames may be off from the true frame since MPlayer seeks to the nearest keyframe.  It seems to work ok for DV-AVI. This also means that stepping by more than a frame may not work. If you need frame-to-frame correspondence with VirtualDub; some sort of frame number interpolation could be tried (hand-registering a pair of frames between mplayerMex and VirtualDub in the middle and end of the video can be a rough way to determine this).

Compiling mplayerMex from source:

DOES NOT YET WORK FOR 64BIT MATLAB.
Not all gcc versions are Matlab compatible, ensure that you have the correct version installed. If not, download & build the correct gcc source into your local directory. Set your path to this gcc bin directory, run "gcc -v" to confirm version. There is one thing to change in the section for your plaform (e.g glnx86)  in <HOME>/.matlab/<your matlab version>/mexopts.sh. If you dont see this file,  run "mex -setup" from matlab.
MPlayer source setup:
Compiling mplayerMex:

Miscellaneous:

Platform independent version netAvi.
For Windows: Check out dxAvi.  mplayerMex may also be able to compile on windows using mingw-gcc, I havent tried this though.

Your feedback keeps opensource ticking ;)
tvashwin | @ | cs | bu | edu
View My Stats