On HP Lab Machines: ~tgd/cs450/bin
In order to do this, add the statement:
On HP Lab Machines: set path=($path ~tgd/cs450/bin)
to your .cshrc file. Then, you must source your .cshrc file (in order for the changes to take effect in your current login session) by executing the command:
source .cshrc
There are a number of files in the directory you have just added to your path that will help you MPEG encode your animation. They are described below. All of the commands mentioned below should work exactly as specified below after this step is performed. This step must only be performed the first time once.
In order to MPEG encode your animation, you need to store your frames in separate files. Each file needs to be in either YUV or PPM format.
int **red, **green, **blue;
void WritePPM(char *fileName, int width, int height, int maxVal)
{
register int x, y;
unsigned char r, g, b;
fprintf(stdout, "P6\n");
fprintf(stdout, "%d %d\n", width, height);
fprintf(stdout, "%d\n", maxVal);
for ( y = 0; y < height; y++ )
for ( x = 0; x < width; x++ )
{
r = red[x][y]; g = green[x][y]; b = blue[x][y];
fwrite(&r, 1, 1, stdout);
fwrite(&g, 1, 1, stdout);
fwrite(&b, 1, 1, stdout);
}
}
maxVal
is the maximum color value. It must be between 0 and 255 inclusive.
Generally speaking, it should be 255 always.
To give you an idea of what format the YUV file must be in, the following code will read in a YUV file:
unsigned char **y_data, **cr_data, **cb_data;
void ReadYUV(char *fileName, int width, int height)
{
FILE *fpointer;
register int y;
/* should allocate memory for y_data, cr_data, cb_data here */
fpointer = fopen(fileName, "r");
for (y = 0; y < height; y++) /* Y */
fread(y_data[y], 1, width, fpointer);
for (y = 0; y < height / 2; y++) /* U */
fread(cb_data[y], 1, width / 2, fpointer);
for (y = 0; y < height / 2; y++) /* V */
fread(cr_data[y], 1, width / 2, fpointer);
fclose(fpointer);
}
There are two reasons why you'd want to use YUV files rather than PPM files:
~tgd/cs450/bin
directory.
mpeg_encode
parameter-file-name
It will read your frames and write an output file according to the instructions in the parameter file.
You can view an MPEG animation by typing:
mpeg_play file.mpg
.
For example, you can view the ~tgd/cs450/sample.mpg animation on the HP system by typing:
mpeg_play ~tgd/cs450/sample.mpg
The argument -loop
will play the movie in a continuous
loop, e.g., mpeg_play -loop image.mpg
.
Please send any questions or comments to:
Tom Dietterich : tgd@cs.orst.edu