25 void Print(
const char* fmt, ...);
30 : filename(fname), fps(0), play(true), pfile(0), ps(0), ps_comp(0),
31 nframe(0), nsamp(0), iserr(false), frame_size(0)
37 : filename(fname), rect(r), fps(frame_rate), play(false), pfile(0),
38 ps(0), ps_comp(0), nframe(0), nsamp(0), iserr(false)
40 Print(
"\n\nAviFile(%s, w=%d, h=%d, f=%d FPS)\n", fname, r.
w, r.
h, fps);
41 frame_size = r.
w * r.
h * 3;
44 HRESULT hr = AVIFileOpen(&pfile, fname, OF_WRITE|OF_CREATE, 0);
46 if (hr != AVIERR_OK) {
47 Print(
"AviFile - open failed. %08x\n", hr);
52 Print(
"AviFile - open successful\n");
55 ZeroMemory(&strhdr,
sizeof(strhdr));
57 strhdr.fccType = streamtypeVIDEO;
58 strhdr.fccHandler = 0;
59 strhdr.dwScale = 1000 / fps;
61 strhdr.dwSuggestedBufferSize = frame_size;
63 SetRect(&strhdr.rcFrame, 0, 0, r.
w, r.
h);
65 hr = AVIFileCreateStream(pfile, &ps, &strhdr);
67 if (hr != AVIERR_OK) {
68 Print(
"AviFile - create stream failed. %08x\n", hr);
73 Print(
"AviFile - create stream successful\n");
75 AVICOMPRESSOPTIONS opts;
76 ZeroMemory(&opts,
sizeof(opts));
77 opts.fccType = streamtypeVIDEO;
79 opts.fccHandler = mmioFOURCC(
'D',
'I',
'B',
' ');
82 hr = AVIMakeCompressedStream(&ps_comp, ps, &opts, 0);
83 if (hr != AVIERR_OK) {
84 Print(
"AviFile - compressed stream failed. %08x\n", hr);
89 Print(
"AviFile - make compressed stream successful\n");
91 BITMAPINFOHEADER bmih;
92 ZeroMemory(&bmih,
sizeof(BITMAPINFOHEADER));
94 bmih.biSize =
sizeof(BITMAPINFOHEADER);
96 bmih.biCompression = BI_RGB;
97 bmih.biWidth = rect.
w;
98 bmih.biHeight = rect.
h;
100 bmih.biSizeImage = frame_size;
102 hr = AVIStreamSetFormat(ps_comp, 0, &bmih,
sizeof(BITMAPINFOHEADER));
104 if (hr != AVIERR_OK) {
105 Print(
"AviFile - stream format failed. %08x\n", hr);
110 Print(
"AviFile - stream format successful\n");
116 Print(
"*** Closing AVI file '%s' with %d frames\n", (
const char*) filename, nframe);
119 if (ps_comp) AVIStreamRelease(ps_comp);
120 if (ps) AVIStreamRelease(ps);
121 if (pfile) AVIFileRelease(pfile);
140 BYTE* buffer =
new(__FILE__,__LINE__) BYTE[frame_size];
143 for (
int y = 0; y < bmp.
Height(); y++) {
146 for (
int x = 0; x < bmp.
Width(); x++) {
147 *dst++ = (BYTE) src->
Blue();
148 *dst++ = (BYTE) src->
Green();
149 *dst++ = (BYTE) src->
Red();
154 #pragma warning(suppress: 6001)
155 hr = AVIStreamWrite(ps_comp, nframe, 1, buffer, frame_size, AVIIF_KEYFRAME, 0, 0);
161 Print(
"AVIStreamWriteFile failed. %08x\n", hr);