Taking a video file and splitting it into a load of numbered jpeg files is a useful thing to be able to do (particularly if you can’t get video input to work with OpenCV). This can be done really easily with mplayer:
mplayer input.avi -vo jpeg:outdir=output_directory
Replace “output_directory” with the directory you want the files to end up in and there you go. You will of course end up with lots of files if your video is of any length, so mplayer has options to make numbered subdirectories and store N frames of video in each. To do this, add subdirs=prefix and maxfiles=N to the command. The “prefix” says what each subdirectory will start with, and the maxfiles determines how many files are put in each subdirectory before moving on to the next one. So this line…
mplayer input.avi -vo jpeg:outdir=output_directory:subdirs=aa:maxfiles=100
…will put 100 files in each subdirectory, and each sub directory will start with the characters “aa”. This is most useful if you’ve got a massive video and there’s a limit on the number of files you can keep in a directory. For example, on a FAT32 system you can “only” have 65,534 files per directory. However, if you’re using Windows you’ll find that performance drops considerably before then, so splitting a huge number of image files between subdirectories is probably a good idea.
Going the other way – from images to video – can also be done really easily. This is useful for creating stop motion animations, or for taking a video that you’ve processed frame by frame and putting it back together into a video file. This command takes a load of jpg files (numbered, in the current directory), and encodes them as a video also in the current directory:
mencoder "mf://*.jpg" -mf fps=25 -o output.avi -ovc lavc -lavcopts vcodec =mpeg4
To change the frame rate, alter the fps option; to change the output format, change the vcodec option and optionally output filename. If you just want to watch a stack of (numbered) jpgs as a movie, you can use mplayer as follows without saving any output video: