26 m_sFile = _T(fileName);
27 if (_tcsstr((
char *)m_sFile, _T(
"avi")) == NULL)
28 m_sFile += _T(
".avi" );
33 m_width = m_renderer->GetRenderWindow()->GetSize()[0];
34 m_height = m_renderer->GetRenderWindow()->GetSize()[1];
39 m_width -= m_width % 4;
40 m_height -= m_height % 4;
43 bih.biSize =
sizeof(BITMAPINFOHEADER);
44 bih.biWidth = m_width;
45 bih.biHeight = m_height;
47 int imgSize = 3 * bih.biWidth * bih.biHeight;
49 bih.biCompression = BI_RGB;
50 bih.biSizeImage = imgSize;
52 bih.biClrImportant = 0;
58 memcpy(&m_bih, &bih,
sizeof(BITMAPINFOHEADER));
66 AVICOMPRESSOPTIONS opts;
67 AVICOMPRESSOPTIONS FAR *aopts[1] = {&opts};
75 DWORD wVer = HIWORD(VideoForWindowsVersion());
79 m_sError = _T(
"Version of Video for Windows too old. Come on, join the 21th century!");
87 hr = AVIFileOpen(&m_pAVIFile,
95 _tprintf(szBuffer, _T(
"AVI Engine failed to initialize. Check filename %s."), m_sFile);
100 case AVIERR_BADFORMAT:
101 m_sError += _T(
"The file couldn't be read, indicating a corrupt file or an unrecognized format.");
104 m_sError += _T(
"The file could not be opened because of insufficient memory.");
106 case AVIERR_FILEREAD:
107 m_sError += _T(
"A disk error occurred while reading the file.");
109 case AVIERR_FILEOPEN:
110 m_sError += _T(
"A disk error occurred while opening the file.");
112 case REGDB_E_CLASSNOTREG:
113 m_sError += _T(
"According to the registry, the type of file specified in AVIFileOpen does not have a handler ")
122 memset(&strHdr, 0,
sizeof(strHdr));
123 strHdr.fccType = streamtypeVIDEO;
124 strHdr.fccHandler = 0;
126 strHdr.dwRate =
static_cast<DWORD
>(m_FrameRate);
127 strHdr.dwSuggestedBufferSize = m_bih.biSizeImage;
128 SetRect(&strHdr.rcFrame,
132 (
int)m_bih.biHeight);
135 hr = AVIFileCreateStream(m_pAVIFile,
142 m_sError = _T(
"AVI Stream creation failed. Check Bitmap info.");
143 if (hr == AVIERR_READONLY)
145 m_sError += _T(
" Read only file.");
151 memset(&opts, 0,
sizeof(opts));
154 opts.fccType = streamtypeVIDEO;
157 opts.fccHandler = mmioFOURCC(
'M',
'S',
'V',
'C');
158 opts.dwQuality = 90000;
163 #if !(_MSC_VER >= 1400)
165 if (!AVISaveOptions(NULL, 0, 1, &m_pStream, (LPAVICOMPRESSOPTIONS FAR *)&aopts))
167 AVISaveOptionsFree(1, (LPAVICOMPRESSOPTIONS FAR *)&aopts);
174 hr = AVIMakeCompressedStream(&m_pStreamCompressed, m_pStream, &opts, NULL);
178 m_sError = _T(
"AVI Compressed Stream creation failed.");
182 case AVIERR_NOCOMPRESSOR:
183 m_sError += _T(
" A suitable compressor cannot be found.");
186 m_sError += _T(
" There is not enough memory to complete the operation.");
188 case AVIERR_UNSUPPORTED:
189 m_sError += _T(
"Compression is not supported for this type of data. This error might be returned if you try ")
190 _T(
"to compress data that is not audio or video.");
198 hr = AVISaveOptionsFree(1, (LPAVICOMPRESSOPTIONS FAR *)&aopts);
201 m_sError = _T(
"Error releasing memory");
206 hr = AVIStreamSetFormat(m_pStreamCompressed,
210 m_bih.biClrUsed *
sizeof(RGBQUAD));
214 m_sError = _T(
"AVI Compressed Stream format setting failed.");
226 HRESULT hr = AVIStreamWrite(m_pStreamCompressed,
247 AVIStreamRelease(m_pStream);
250 if (m_pStreamCompressed)
252 AVIStreamRelease(m_pStreamCompressed);
253 m_pStreamCompressed = NULL;
257 AVIFileRelease(m_pAVIFile);
virtual void SetFileName(const char *fileName)
filename under which movie is saved
virtual bool TerminateGenerator()
called after the last frame is added
void InitBitmapHeader()
reads out size of current OpenGL context and stores it
virtual bool AddFrame(void *data)
used to add a frame
virtual bool InitGenerator()
called directly before the first frame is added