Tutorial for loading a video sequence into matlab. Author: N Dowson Revised: 31 Oct 05 Introduction Matlab does not support many formats when loading image sequences. In particular on the *nix environment only avi's with zero compression are supported (as far as I know). Also, matlab doesn't appear to recognise .mpeg files. Apart from this, loading sequences is slow. For this reason I looked around for another way to load sequences into matlab that was relatively simple and at least partially automated. This took me a little while to figure out, so I wrote this little tutorial. How to do it 1. Make sure mplayer is on your system and supports the video format you want to read. In most cases, a standard compile of mplayer and installation some native windows codecs will do. See www.mplayerhq.hu/homepage/ for more information. 2. At the commandline run "mplayer -nosound -vo png -ss hh:mm:ss ". -vo specifies that the output is actually to a sequence of PNG image files. -ss specifies the start position in hours minutes and seconds. This is optional. Make sure you have a lot of space free, because this will spew out a one uncompressed .png file per frame. At 512x384, thats 590k per frame. Uncompressed PNG is my favoured format because it's open, widely supported, and does not introduce more compression artifacts into the sequence. 3. In MATLAB run "V = loadclip('/PNGdir/0000','png',startFrame,endFrame);". /PNGdir/ is the directory where the PNG files are. The first four zeroes are specified because the loadclip routine only counts up to 10000. This little routine that loads each video clip, finds the mean gray value and adds it to a 3D uint array. This routine is reasonably thrifty with memory, so it shouldn't run out of RAM unless the actual 3D cube is too large to handle. The routine handles up to 10000 frames. You'll need to edit it if you need more (which is easy enough). 4. Viola you now have a sequence stored as a 3D cube. Save the 3D array, since reading a 3D array is much quicker than reading each .png again. 5. Enjoy. 6. Note that the avi's matlab outputs are not standard (i.e. don't work in a lot of programs) and only uncompressed avi's are supported in *nix, so I advise re-encoding them using mencoder with the XviD codec which is open source. Alternatively They can be played by mplayer if you use the -noidx or -forceidx options. 7. I've extracted a number of sequences this way, which I've stored in /vol/vssp/arph/dev/zavi 8. Contact me if you have problems.