13#pragma comment(lib, "Vfw32.lib")
47 BITMAPINFOHEADER m_bmpinfo;
48 PAVISTREAM m_pSourceStream;
49 PAVISTREAM m_pCompressedStream;
56 CAviMaker(
void) : m_pSourceStream(NULL), m_pCompressedStream(NULL), m_pAviFile(NULL), m_index(0)
58 m_compvars.cbSize = 0;
73 if ( m_pCompressedStream != NULL )
75 ::AVIStreamRelease(m_pCompressedStream);
76 m_pCompressedStream = NULL;
78 if ( m_pSourceStream != NULL )
80 ::AVIStreamRelease(m_pSourceStream);
81 m_pSourceStream = NULL;
83 if (m_pAviFile!=NULL) {
84 ::AVIFileRelease(m_pAviFile);
87 if ( m_compvars.cbSize != 0 )
89 ::ICCompressorFree(&m_compvars);
90 m_compvars.cbSize = 0;
107 bool Open(
const SIZE& size, LPCTSTR fileName, DWORD scale, DWORD rate,
bool boIsComp =
false)
110 size_t imageBytes = (((size.cx * 24 + 31)& ~31) / 8) * size.cy;
111 BITMAPINFOHEADER bi =
113 sizeof(BITMAPINFOHEADER), size.cx, size.cy, 1, 24, BI_RGB,
ToDword(imageBytes), 0, 0, 0, 0
118 streamtypeVIDEO, comptypeDIB, 0, 0, 0, 0,
119 scale, rate, 0, 0, 0, 0, DWORD_MAX, 0, {0, 0, size.cx, size.cy}, 0, 0, _T(
"VIDEO")
122 if ( ::AVIFileOpen(&m_pAviFile, fileName, OF_CREATE | OF_WRITE | OF_SHARE_DENY_NONE, NULL) != 0 )
129 memset(&m_compvars, 0,
sizeof(COMPVARS));
130 m_compvars.cbSize =
sizeof(COMPVARS);
131 m_compvars.dwFlags = ICMF_COMPVARS_VALID;
132 m_compvars.fccHandler = comptypeDIB;
133 m_compvars.lQ = ICQUALITY_DEFAULT;
134 if ( ! ::ICCompressorChoose(NULL, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME, &bi, NULL, &m_compvars, NULL) )
139 si.fccHandler = m_compvars.fccHandler;
140 AVICOMPRESSOPTIONS opt;
141 opt.fccType = streamtypeVIDEO;
142 opt.fccHandler = m_compvars.fccHandler;
143 opt.dwKeyFrameEvery = m_compvars.lKey;
144 opt.dwQuality = m_compvars.lQ;
145 opt.dwBytesPerSecond = m_compvars.lDataRate;
146 opt.dwFlags = (m_compvars.lDataRate > 0 ? AVICOMPRESSF_DATARATE : 0) | (m_compvars.lKey > 0 ? AVICOMPRESSF_KEYFRAMES : 0);
149 opt.lpParms = m_compvars.lpState;
150 opt.cbParms = m_compvars.cbState;
151 opt.dwInterleaveEvery = 0;
152 if ( ::AVIFileCreateStream(m_pAviFile, &m_pSourceStream, &si) != 0)
157 if ( ::AVIMakeCompressedStream(&m_pCompressedStream, m_pSourceStream, &opt, NULL) != AVIERR_OK )
165 if ( ::AVIFileCreateStream(m_pAviFile, &m_pCompressedStream, &si) != 0 )
171 if ( ::AVIStreamSetFormat(m_pCompressedStream, 0, &bi,
sizeof(BITMAPINFOHEADER)) != 0 )
187 if ( m_pCompressedStream != NULL )
189 CWorkMem work(m_bmpinfo.biSizeImage);
190 HDC dc = ::GetDC(NULL);
191 int r = ::GetDIBits(dc, bmp, 0, m_bmpinfo.biHeight - 1,
192 work.
Ref(),
reinterpret_cast<BITMAPINFO*
>(&m_bmpinfo), DIB_RGB_COLORS);
193 ::ReleaseDC(NULL, dc);
194 if ( r == m_bmpinfo.biHeight - 1 )
196 if ( ::AVIStreamWrite(m_pCompressedStream, m_index++, 1, work.
Ref(), down_cast<LONG>(work.
GetSize()), AVIIF_KEYFRAME, NULL, NULL) == 0 )
bool Add(CBitmapHandle bmp)
[追加] フレーム追加.
virtual ~CAviMaker()
デストラクタ
void Close(void)
[停止] ストップ.
bool Open(const SIZE &size, LPCTSTR fileName, DWORD scale, DWORD rate, bool boIsComp=false)
[開始] オープン.
size_t GetSize(void) const
[取得] サイズ取得
const TYP * Ref(void) const
[取得] ポインタ取得
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).