把动态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"); }
版权声明:本文为博主原创文章,未经博主允许不得转载。