The correct sequence of use of VCM is: Enable the decoder and set a bitmapinfoheader input format. Then, a function obtains the bitmapinfoheader format of the output format, compressbegin, compress, and compressend compressclose.
// Codec.h: interface for the CCodec class.////////////////////////////////////////////////////////////////////////#if !defined(AFX_CODEC_H__9B60DF9B_B3AC_4C8D_9D1A_044D5F9BF268__INCLUDED_)#define AFX_CODEC_H__9B60DF9B_B3AC_4C8D_9D1A_044D5F9BF268__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000class CCodec {public://for single compressBOOLInitCompress(BITMAPINFOHEADER bi);LONGCompressData(LPBYTE lpInData,LPBYTE lpOutData,LPDWORD lpdwFlags);voidCloseCompress();//for decompressBOOLInitDecompress(BITMAPINFOHEADER biIn,BITMAPINFOHEADER biOut);voidCloseDecompress();BOOLDecompressData(LPBYTE pData,LPBYTE pOutData,DWORD dwKeyFrame);CCodec();virtual ~CCodec();BITMAPINFOHEADER bihIn,bihOut;private:HIChic;BITMAPINFOHEADER decbihIn,decbihOut;HICdehic;};#endif // !defined(AFX_CODEC_H__9B60DF9B_B3AC_4C8D_9D1A_044D5F9BF268__INCLUDED_)// Codec.cpp: implementation of the CCodec class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "AviGenius.h"#include "Codec.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CCodec::CCodec(){}CCodec::~CCodec(){}BOOL CCodec::InitCompress(BITMAPINFOHEADER bi){memcpy(&bihIn,&bi,40);memcpy(&bihOut,&bi,40);/*hic = ICLocate (ICTYPE_VIDEO, fccHandler, (LPBITMAPINFOHEADER) &biIn, &biOut, ICMODE_COMPRESS); // hic = ICLocate (ICTYPE_VIDEO, 0L, (LPBITMAPINFOHEADER) &biIn, NULL, ICMODE_COMPRESS); if(!hic){AfxMessageBox("ICLocate error!");returnFALSE;}*/COMPVARS pc;pc.cbSize=sizeof(COMPVARS);pc.fccType=ICTYPE_VIDEO;pc.lpbiIn=(LPBITMAPINFO)&bihIn;if(!(ICCompressorChoose(NULL,0|ICMF_CHOOSE_DATARATE|ICMF_CHOOSE_KEYFRAME|ICMF_CHOOSE_PREVIEW,//ICMF_CHOOSE_ALLCOMPRESSORS
& Bihin, null, & PC, "video compression algorithm selection") {afxmessagebox ("iccompressorchoose error! "); Return false;} Hic = pc. hic; bihout. bicompression = pc. fcchandler;/* HIC = icopen (mmiofourcc ('V', 'I', 'D', 'C'), fcchandler, icmode_compress); If (! Hic) {afxmessagebox ("icopen error! "); Return 0;} icconfigure (HIC, null); */If (iccompressbegin (HIC, (lpbitmapinfo) & bihin, (lpbitmapinfo) & bihout )! = Icerr_ OK) {returnfalse;} return true;} Long ccodec: compressdata (lpbyte lpindata, lpbyte lpoutdata, lpdword finished) {If (iccompress (HIC, 0, & bihout, lpoutdata, & bihin, lpindata, 0, lpdwflags, 0, 0, null, null )! = Icerr_ OK) {MessageBox (null, "compress error! "," Error ", mb_ OK); return0;} return bihout. bisizeimage;} void ccodec: closecompress () {iccompressend (HIC ); // terminate compression} // For decompress ///// /// // bool ccodec:: initdecompress (bitmapinfoheader biin, bitmapinfoheader biout) {memcpy (& decbihin, & biin, 40); memcpy (& decbihout, & biout, 40 ); dehic = icopen (mmiofourcc ('V', 'I', 'D', 'C'), biin. bicompression, icmode_decompres S); If (! Dehic) {afxmessagebox ("decompress icopen error! "); Return false;} If (icdecompressbegin (dehic, & decbihin, & decbihout )! = Icerr_ OK) {afxmessagebox ("icdecompressbegin error"); returnfalse;} return true;} bool ccodec: decompressdata (lpbyte pdata, lpbyte poutdata, DWORD dwkeyframe) {If (icdecompress (dehic, 0, & decbihin, pdata, & decbihout, poutdata )! = Icerr_ OK) return false; return true;} void ccodec: closedecompress () {icdecompressend (dehic );}