www.pudn.com > Gesture[20040824].rar > WriteAvi.cpp
// WriteAvi.cpp: implementation of the CWriteAvi class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "WriteAvi.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWriteAvi::CWriteAvi()
{
AVIFileInit();
Init();
}
CWriteAvi::~CWriteAvi()
{
AVIFileExit();
Release();
}
bool CWriteAvi::Open(LPCSTR lpszFileName)
{
HRESULT hr = AVIFileOpen(&m_pAviFile, lpszFileName, OF_WRITE | OF_CREATE, NULL);
return (hr == 0) ;
}
void CWriteAvi::Release()
{
if(psSmall) AVIStreamRelease(psSmall);
if(m_pAviFile)
AVIFileRelease(m_pAviFile);
Init();
return;
}
void CWriteAvi::Init()
{
m_pAviFile = NULL;
psSmall = NULL;
}
bool CWriteAvi::NewVideoStream(BITMAPINFOHEADER framebi,int framenum)
{ this->bi = framebi;
memset(&strhdr,0,sizeof(strhdr));
strhdr.fccType = 1935960438;
strhdr.fccHandler = 808810089;
strhdr.dwScale = 100;
strhdr.dwRate = 2500;
strhdr.dwStart = 0;
strhdr.dwLength = framenum; //set for number of frame
strhdr.dwInitialFrames = 0;
strhdr.dwSuggestedBufferSize = 26930;
strhdr.dwQuality = 8500;
strhdr.dwSampleSize = 0;
strhdr.dwEditCount = 0;
strhdr.dwFormatChangeCount = 0;
strcpy(strhdr.szName,"editliu");
SetRect(&strhdr.rcFrame, 0, 0, (int) bi.biWidth,
(int) bi.biHeight);
HRESULT hr = AVIFileCreateStream(m_pAviFile, &psSmall, &strhdr);
if (hr != 0) { //Stream created OK? If not, close file.
Release();
return false;
}
hr = AVIStreamSetFormat(psSmall, 0, &bi, sizeof(bi));
if (hr != 0) {
Release();
return false;
}
return true;
}
void CWriteAvi::SetVideoFrame(LPVOID lpbit,int lStreamSize)
{
AVIStreamWrite(psSmall, lStreamSize, 1, lpbit,
bi.biSizeImage, AVIIF_KEYFRAME, NULL, NULL);
}