码迷,mamicode.com
首页 > 其他好文 > 详细

把连续动态bmp转换为avi

时间:2014-11-07 17:12:14      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:blog   os   for   strong   文件   数据   on   2014   log   

把动态bmp24转换为avi

BYTE tmp_buf[1024*768*4];
//生成avi
void BMPtoAVI(CString szAVIName, CString strBmpDir)
{
	CFileFind finder;
	strBmpDir += _T("\\*.bmp"); 
	AVIFileInit(); 
	AVISTREAMINFO strhdr;
	PAVIFILE pfile;
	PAVISTREAM ps; 
	int nFrames =0; 
	HRESULT hr; 

	BOOL bFind = finder.FindFile(strBmpDir);
	while(bFind)
	{
		bFind = finder.FindNextFile();
		if(!finder.IsDots() && !finder.IsDirectory())
		{
			CString str = finder.GetFilePath();//检索文件
			FILE *fp = fopen(str,"rb");
			BITMAPFILEHEADER bmpFileHdr;
			BITMAPINFOHEADER bmpInfoHdr;
			fseek( fp,0,SEEK_SET);
			fread(&bmpFileHdr,sizeof(BITMAPFILEHEADER),1, fp);
			fread(&bmpInfoHdr,sizeof(BITMAPINFOHEADER),1, fp);//读取文件头
		
			if(nFrames ==0 )
			{
				AVIFileOpen(&pfile,szAVIName,OF_WRITE | OF_CREATE,NULL);
				memset(&strhdr, 0, sizeof(strhdr));
				strhdr.fccType = streamtypeVIDEO;// stream type
				strhdr.fccHandler = 0;
				strhdr.dwScale = 1;
				strhdr.dwRate = 25; // 15 fps
				strhdr.dwSuggestedBufferSize = bmpInfoHdr.biSizeImage ;
				SetRect(&strhdr.rcFrame, 0, 0, bmpInfoHdr.biWidth, bmpInfoHdr.biHeight);		
								// And create the stream;
				hr = AVIFileCreateStream(pfile,&ps,&strhdr); 
								// hr = AVIStreamSetFormat(ps,nFrames,&bmpInfoHdr,sizeof(bmpInfoHdr));
			}
		//	tmp_buf = new BYTE[bmpInfoHdr.biWidth * bmpInfoHdr.biHeight * 4];
			fread(tmp_buf, 1, bmpInfoHdr.biWidth * bmpInfoHdr.biHeight * 3, fp);//读取文件数据
			hr = AVIStreamSetFormat(ps,nFrames,&bmpInfoHdr,sizeof(bmpInfoHdr));
			hr = AVIStreamWrite(ps, // stream pointer
				nFrames , // time of this frame
				1, // number to write
				(LPBYTE) tmp_buf,
				bmpInfoHdr.biSizeImage , // size of this frame
				AVIIF_KEYFRAME, // flags....
			NULL,
			NULL);
			nFrames ++; 
			
			fclose(fp);

		}
	}
	AVIStreamClose(ps);
	if(pfile != NULL)
	AVIFileRelease(pfile);
	AVIFileExit();

}
void CTestaviDlg::OnButton2() 
{
	BMPtoAVI("f:\\ffoutput\\1.avi","f:\\ffoutput\\pic\\");
        MessageBox("over");
}


把连续动态bmp转换为avi

标签:blog   os   for   strong   文件   数据   on   2014   log   

原文地址:http://blog.csdn.net/mao0514/article/details/40892823

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!