- bmih.bmiColors[i].rgbBlue = (BYTE)i;
- bmih.bmiColors[i].rgbGreen = (BYTE)i;
- bmih.bmiColors[i].rgbRed = (BYTE)i;
- bmih.bmiColors[i].rgbReserved = 0;
- }
-
- memset( &aviinfo, 0, sizeof(aviinfo));
- aviinfo.fccType = streamtypeVIDEO;
- aviinfo.fccHandler = 0;
- // use highest possible accuracy for dwRate/dwScale
- aviinfo.dwScale = (DWORD)((double)0x7FFFFFFF / fps);
- aviinfo.dwRate = cvRound(fps * aviinfo.dwScale);
- aviinfo.rcFrame.top = aviinfo.rcFrame.left = 0;
- aviinfo.rcFrame.right = frameSize.width;
- aviinfo.rcFrame.bottom = frameSize.height;
-
- if( AVIFileCreateStream( writer->avifile,
- &writer->uncompressed, &aviinfo ) == AVIERR_OK )
- {
- copts.fccType = streamtypeVIDEO;
- copts.fccHandler = fourcc != -1 ? fourcc : 0;
- copts.dwKeyFrameEvery = 1;
- copts.dwQuality = (DWORD)-1;
- copts.dwBytesPerSecond = 0;
- copts.dwFlags = AVICOMPRESSF_VALID;
- copts.lpFormat = &bmih;
- copts.cbFormat = (is_color ? sizeof(BITMAPINFOHEADER) : sizeof(bmih));
- copts.lpParms = 0;
- copts.cbParms = 0;
- copts.dwInterleaveEvery = 0;
-
- if( fourcc != -1 ||
- AVISaveOptions( 0, 0, 1, &writer->uncompressed, &pcopts ) == TRUE )
- {
- if( AVIMakeCompressedStream( &writer->compressed,
- writer->uncompressed, pcopts, 0 ) == AVIERR_OK &&
- // check that the resolution was not changed
- bmih.bmiHeader.biWidth == frameSize.width &&
- bmih.bmiHeader.biHeight == frameSize.height &&
- AVIStreamSetFormat( writer->compressed, 0, &bmih, sizeof(bmih)) == AVIERR_OK )
- {
- writer->fps = fps;
- writer->fourcc = (int)copts.fccHandler;
- writer->frameSize = frameSize;
- writer->tempFrame = cvCreateImage( frameSize, 8, (is_color ? 3 : 1) );
- return 1;
- }
- }