Original Post
Jeff,
Would it be possible to do a tutorial on how to save your OpenGL animations as avi/mpeg files.
Regards
Louis_Wu
void save_to_avi(struct S_BMP *frame, char *filename)
{
int i;
AVISTREAMINFO strhdr;
PAVIFILE pfile = NULL;
PAVISTREAM ps = NULL, psCompressed = NULL, psText = NULL;
AVICOMPRESSOPTIONS opts;
AVICOMPRESSOPTIONS FAR * aopts[1] = {&opts};
HRESULT hr;
WORD wVer;
BITMAPINFOHEADER binfo;
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)
return;
AVIFileInit();
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)
break;
pov.hrot -= 0.04f;
pov.origin[1] += 1.5f;
}
error:
//
// Now close the file
//
if (ps)
AVIStreamClose(ps);
if (psCompressed)
AVIStreamClose(psCompressed);
if (pfile)
AVIFileClose(pfile);
AVIFileExit();
}
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more