Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Tutorial Idea

This topic is 6245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Jeff, Would it be possible to do a tutorial on how to save your OpenGL animations as avi/mpeg files. Regards Louis_Wu

Share this post

Link to post
Share on other sites
I disagree I think it''s important that we *all* see what kind of tutorial requests are being made. It let''s us know that we''re not the only ones wondering about something, and we can add our "support" to the request. It also gives us the opportunity to say "Oh yah! I''ve been wanting to write a tutorial about that, now I have the motivation to do it!".

As it so happens, I recently wrote some code to save an OpenGL anim to an AVI file, if you''re interested here''s a snipit of the AVI specific stuff...

void save_to_avi(struct S_BMP *frame, char *filename)
int i;
PAVISTREAM ps = NULL, psCompressed = NULL, psText = NULL;
AVICOMPRESSOPTIONS FAR * aopts[1] = {&opts};
WORD wVer;

binfo.biSize = sizeof(binfo);
binfo.biWidth = frame->width;
binfo.biHeight = frame->height;
binfo.biPlanes = 1;
binfo.biBitCount = 24;
binfo.biCompression = BI_RGB;
binfo.biSizeImage = frame->width*frame->height*3;
binfo.biClrUsed = 0;
binfo.biClrImportant = 0;

/* first let''s make sure we are running on 1.1 */
wVer = HIWORD(VideoForWindowsVersion());
if(wVer < 0x010a)


hr = AVIFileOpen(&pfile, // returned file pointer
filename, // file name
OF_WRITE | OF_CREATE, // mode to open file with
NULL); // use handler determined
// from file extension....
if (hr != AVIERR_OK)
goto error;

// Fill in the header for the video stream....

// The video stream will run in 15ths of a second....

memset(&strhdr, 0, sizeof(strhdr));
strhdr.fccType = streamtypeVIDEO;// stream type
strhdr.fccHandler = 0;
strhdr.dwScale = 1;
strhdr.dwRate = 15; // 15 fps
strhdr.dwSuggestedBufferSize = binfo.biSizeImage;
SetRect(&strhdr.rcFrame, 0, 0, // rectangle for stream
(int) binfo.biWidth,
(int) binfo.biHeight);

// And create the stream;
hr = AVIFileCreateStream(pfile, // file pointer
&ps, // returned stream pointer
&strhdr); // stream header
if (hr != AVIERR_OK) {
goto error;

memset(&opts, 0, sizeof(opts));

if (!AVISaveOptions(NULL, 0, 1, &ps, (LPAVICOMPRESSOPTIONS FAR *) &aopts))
goto error;

hr = AVIMakeCompressedStream(&psCompressed, ps, &opts, NULL);
if (hr != AVIERR_OK) {
goto error;

hr = AVIStreamSetFormat(psCompressed, 0,
&binfo, // stream format
binfo.biSize + // format size
binfo.biClrUsed * sizeof(RGBQUAD));
if (hr != AVIERR_OK) {
goto error;

for (i = 0; i < 480; i++) {
hr = AVIStreamWrite(psCompressed, i, 1, frame->data, frame->width*frame->height*3, AVIIF_KEYFRAME, NULL, NULL);
// hr = AVIStreamWrite(psCompressed, // stream pointer
// i * 10, // time of this frame
// 1, // number to write
// (LPBYTE) &binfo + // pointer to data
// binfo.biSize +
// binfo.biClrUsed * sizeof(RGBQUAD),
// binfo.biSizeImage, // size of this frame
// AVIIF_KEYFRAME, // flags....
// NULL,
// NULL);
if (hr != AVIERR_OK)
pov.hrot -= 0.04f;
pov.origin[1] += 1.5f;

// Now close the file
if (ps)

if (psCompressed)

if (pfile)


I hacked this code up a little right here to remove some globals and what not, so it probably wouldn''t compile exactly like this, but it should give you the idea. This would save a 480 frame AVI consisting of just the one input image. My original code actually rendered different frames in the inner loop there.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!