Making movies using ppmtompg or whatever it is called.

Science and movies. A classic combination. I’m not talking science fiction, but actual science. As datasets get bigger and more and more imaging and modelling is done in three dimensions, being able to represent data graphically is more and more important. This is a problem for me because I am not really into computer graphics and the like — my scientific programming is all done in a text-based interface, with text files as inputs and outputs, and I do not have the time to spend learning GUI programming.

But, I do have some old PostScript routines that I use for printing stuff out when I have a simulation that is highly geometric in nature, for example something that involves atomic coordinates.

These routines are just old Fortran 77 subroutines, and I have bunged them up on the web for reference and because they are still kind of useful. [[I have also created a small program that uses them as a bit of a demo, but that is a story for another post, and not yet on the web.]]

So I can draw simple diagrams easily enough. But what if I want to make a movie? Well, there are two tools that I use for this, gifsicle and ppmtompeg. Here, I will outline how I use them.

Systematic naming of the input files is very important. Let’s say all my files have names of the form pXXXXX.ps, where XXXXX goes from 00001 to 99999. Now, the subroutine outputs them as PostScript files, so first I do some conversions. I use two steps. I’m sure you can do better. Here is my script, movieB.sh:

for f in *.ps;
do
ls $f
ps2epsi $f
done
for f in *.epsi;
do
ls $f
convert -alpha opaque $f $f.gif
convert $f $f.pnm
done
gifsicle --delay=10 --loop *.gif > myanimatedgif.gif
ppmtompeg mpeg.inp

So what happens here is that I convert all the PostScript files to encapsulated PostScript, then I convert them to GIF and also to PNM. I use two loops and keep all the intermediate files, for no good reason. Then I run gifsicle and produce my animated GIF, and I run ppmtompeg, which takes its input from mpeg.inp. Let’s have a look at that magical incantation:

PATTERN IBBPBBPBBPBBPBB
OUTPUT mympeg.mpg
INPUT_DIR .
INPUT
p*.epsi.pnm  [00001-02000]
END_INPUT
BASE_FILE_FORMAT PNM
INPUT_CONVERT *
GOP_SIZE 15
SLICES_PER_FRAME  1
PIXEL HALF
RANGE 3
PSEARCH_ALG LOGARITHMIC
BSEARCH_ALG SIMPLE
IQSCALE 3
PQSCALE 3
BQSCALE 3
REFERENCE_FRAME ORIGINAL
ASPECT_RATIO 1

Okay, so this is reading in PNM files, and note the wildcard format for the filenames, which is why I chose such a simple input filename format, and with a fixed number of characters. It is usually a lot easier if files are named ‘p00001.ps‘ to ‘p99999.ps‘ than ‘p1.ps‘ to ‘p99999.ps‘.

Most of the fields I don’t change. They may not be optimal but they work. I am not embedding an example because the files are too big and I don’t want to waste your bandwidth and mine.

Good advises. Real movies.

Advertisements

Tags: , , , , ,

About Darren

I'm a scientist by training, based in Australia.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: