Monday, October 8, 2007

movies from sequences of files.

Based on some advice I found [here](http://electron.mit.edu/~gsteele/ffmpeg/), I discovered how to make high quality movies from series of png files using [ffmpeg](http://ffmpeg.mplayerhq.hu/). I use png files because they have a high color depth (unlike 256 for gif), and they are non-lossy (unlike jpg).

First you need to make a sequence of _ordered_ files that have filenames like frame\_001.png, frame\_002.png, etc. For example, in python's matplotlib, you would have a line like:

saveframe('frame_%03d.png' % framenumber)

Then, you need to run ffmpeg on all of these files. The command is quite simple:

ffmpeg -r 10 -sameq -i frame_%03d.png test.mp4

where the -r flag sets the frames per second. Otherwise, the only other key option is the -sameq flag, which keeps the same non-lossy quality of the png files. Pretty easy. Also, you don't need to install xvid or h264 libraries for this to work. The codecs that come with ffmpeg seem to work just fine.

Also, the size of the resulting movie file is quite reasonable. I tested 121 frames at 1000x600 (with considerable non-changing space in the field). The resulting movie was 2.8M big. This is about seven times smaller than simply concatenating all of the images together. Not too bad.

No comments:

Post a Comment