VC6.0 如何用VFW录制avi

在.h头文件

#include "vfw.h"
#include "mmsystem.h"
#pragma comment (lib,"vfw32.lib")
#pragma comment (lib,"winmm.lib")

全局变量

int		nFrames = 0;
PAVIFILE pfile;
AVISTREAMINFO strhdr;
PAVISTREAM ps;
HRESULT hr; 
AVICOMPRESSOPTIONS pCompressOption;   
AVICOMPRESSOPTIONS FAR * opts[1] = {&pCompressOption};
PAVISTREAM pComStream;



 这里就不说如何用dib截屏了

 BITMAPINFOHEADER *pBInfo = new BITMAPINFOHEADER;
 pBInfo->biBitCount       = 24;
 pBInfo->biClrImportant   = 0;
 pBInfo->biCompression    = 0;
 pBInfo->biHeight         = DIBitmap.bmHeight;
 pBInfo->biPlanes         = DIBitmap.bmPlanes;
 pBInfo->biSize           = sizeof(BITMAPINFOHEADER);
 pBInfo->biSizeImage      = DIBitmap.bmWidthBytes * DIBitmap.bmHeight;
 pBInfo->biWidth          = DIBitmap.bmWidth;
 pBInfo->biXPelsPerMeter  = 0;
 pBInfo->biYPelsPerMeter  = 0;
if(nFrames == 0)
	{
		AVIFileInit();

		AVIFileOpen(&pfile,"录像.avi",OF_WRITE | OF_CREATE,NULL);
		memset(&strhdr, 0, sizeof(strhdr));
		strhdr.fccType    = streamtypeVIDEO;
		strhdr.fccHandler = 0;
		strhdr.dwScale    = 1;
		strhdr.dwRate     = 5;
		strhdr.dwSuggestedBufferSize = pBInfo->biSizeImage;
		SetRect(&strhdr.rcFrame,0,0,pBInfo->biWidth,pBInfo->biHeight);
		hr = AVIFileCreateStream(pfile,&ps,&strhdr); 
		
		opts[0]->fccType = streamtypeVIDEO;
		opts[0]->fccHandler = mmioStringToFOURCC("MSVC", 0);
		opts[0]->dwQuality = 7500;
		opts[0]->dwBytesPerSecond = 0;
		opts[0]->dwFlags = AVICOMPRESSF_VALID || AVICOMPRESSF_KEYFRAMES;
		opts[0]->lpFormat = 0;
		opts[0]->cbFormat = 0;
		opts[0]->dwInterleaveEvery = 0;
		
		AVIMakeCompressedStream(&pComStream,ps,&pCompressOption,NULL); 
		AVIStreamSetFormat(pComStream,0,pBInfo,sizeof(BITMAPINFOHEADER));
	}
	
	hr = AVIStreamWrite(pComStream,nFrames ,1,(LPBYTE)p+54,
		pBInfo->biSizeImage,AVIIF_KEYFRAME,NULL,NULL);
	nFrames++;
	
	delete pBInfo ;

 

结束的函数中加入

	if (pComStream != 0)
		AVIStreamClose(pComStream);
	if (ps != 0)
		AVIStreamClose(ps);
	if(pfile != NULL)
		AVIFileRelease(pfile);
	AVIFileExit();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值