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.
Remove the "-ansi" flag in CFLAGS and add "-fPIC" for "gcc" &
"g++" sections.
MPlayer source setup:
Download
and untar MPlayer source; I have
only tried with MPlayer-1.0pre7try2,
will at some point upgrade to the latest :).
Add "void
set_codecs_to_null();" to codec-cfg.h and its following
definition to codec-cfg.c void set_codecs_to_null(){
video_codecs = NULL;
audio_codecs = NULL; }
Copy and paste this function
into libmpcodecs/vf_scale.c after definition of the "static int
put_image( .. )" funciton.
In the MPlayer directory, run ./configure --cc="gcc
-fPIC"
For faster compilation you can add " --disable-mencoder
--disable-langinfo --disable-vm --disable-xf86keysym --disable-tv
--disable-tv-v4l --disable-tv-v4l2 --disable-tv-bsdbt848
--disable-cdparanoia --disable-freetype --disable-fontconfig
--disable-unrarlib --disable-sortsub --disable-enca --disable-macosx
--disable-inet6 --disable-ftp --disable-vstream --disable-internal-faad
--disable-ladspa --disable-mad --disable-toolame
--disable-mp3lib --disable-liba52 --disable-amr_nb
--disable-amr_nb-fixed --disable-amr_wb --disable-alsa
--disable-ossaudio --disable-arts --disable-esd --disable-polyp
--disable-jack --disable-nas --disable-sgiaudio --disable-sunaudio
--disable-win32waveout "
"make" to compile
MPlayer. Test MPlayer on a video file to ensure its ok.
Compiling mplayerMex:
Untar mplayerMex.tar in the MPlayer source main directory.
Open matlab and cd to the MPlayer source directory.
Run mex_cmd.m from matlab. This should hopefully build the
package and
create three .mex* files on 32 bit platforms. But on amd64, I get
/usr/bin/ld: libvo/osd.o: relocation R_X86_64_32S against `a local
symbol' can not be used when making a shared object; recompile with
-fPIC;
One workaround is to run 32 bit matlab on amd64, the .mexglx
files should work.
Use testMplayer to test.
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