头文件 #include <Vfw.h>
成员变量:
// for avi;
PGETFRAME Frame;
BITMAPFILEHEADER BMPFileHeader;
PAVIFILE aviFile;
PAVISTREAM aviStream;
AVISTREAMINFO aviStreamInfo;
int m_nFrameNumber;
BITMAPINFO* m_pBitMapInfo;
BYTE* pData;
int cy;
int cx;
HANDLE handle;
//
读取代码:
AVIFileInit(); AVIFileOpen(&aviFile, "E:\\Alizee.avi", OF_READ, NULL); AVIFileGetStream(aviFile, &aviStream, streamtypeVIDEO, 0); AVIStreamInfo(aviStream, &aviStreamInfo, sizeof(aviStreamInfo)); AVIFILEINFO fileInfo; AVIFileInfo(aviFile, &fileInfo, sizeof(AVIFILEINFO)); cx = fileInfo.dwWidth; cy = fileInfo.dwHeight; AVIFileGetStream(aviFile, &aviStream, streamtypeVIDEO, 0); m_pBitMapInfo = new BITMAPINFO; m_pBitMapInfo->bmiHeader.biBitCount = 32; m_pBitMapInfo->bmiHeader.biClrImportant=0; m_pBitMapInfo->bmiHeader.biClrUsed=0; m_pBitMapInfo->bmiHeader.biCompression=0; m_pBitMapInfo->bmiHeader.biHeight=cy; m_pBitMapInfo->bmiHeader.biWidth=cx; m_pBitMapInfo->bmiHeader.biPlanes=1; m_pBitMapInfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); //m_pBitMapInfo->bmiHeader.biSizeImage = (cx * 24 + 31) / 32 * 4 * cy; //图像数据的大小; m_pBitMapInfo->bmiHeader.biSizeImage = 0; m_pBitMapInfo->bmiHeader.biXPelsPerMeter=0; m_pBitMapInfo->bmiHeader.biYPelsPerMeter=0; handle=GlobalAlloc(GHND,((long)((cx*24+31)/32*4)*cy)); pData=(BYTE*)GlobalLock(handle); BMPFileHeader.bfType = 0x4D42; BMPFileHeader.bfSize = (cx * 24 + 31) / 32 * 4 * cy + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); //图像的总大小; BMPFileHeader.bfReserved1=0; BMPFileHeader.bfReserved2=0; BMPFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); //24位真彩色位图恒为54; ////// static CEngine* pEngine = ((CHKEditorApp*)AfxGetApp())->m_pEngine; assert(pEngine != NULL); m_nFrameNumber = 0; SetTimer(ID_AVI_TIMER, 1, 0);
定时器里面:
case ID_AVI_TIMER: { if (m_nFrameNumber == aviStreamInfo.dwLength) { KillTimer(ID_AVI_TIMER); return; } PGETFRAME pg = AVIStreamGetFrameOpen(aviStream, &(m_pBitMapInfo-> bmiHeader)); pData = (BYTE*)AVIStreamGetFrame(pg, m_nFrameNumber++); // CClientDC dc(this); // CRect rect; // GetClientRect(&rect); // StretchDIBits(HDC(dc),0,0,rect.right,rect.bottom,0,0,cx,cy,pData,(BITMAPINFO*)m_pBitMapInfo,DIB_RGB_COLORS,SRCCOPY); Engine->m_pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); memcpy(Engine->m_pixelBuffer->getCurrentLock().data, &BMPFileHeader, sizeof(BITMAPFILEHEADER)); memcpy((BYTE*)Engine->m_pixelBuffer->getCurrentLock().data + sizeof(BITMAPFILEHEADER), m_pBitMapInfo,sizeof(BITMAPINFO)); memcpy((BYTE*)Engine->m_pixelBuffer->getCurrentLock().data + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO), pData, cx*cy*3); //memcpy((BYTE*)Engine->m_pixelBuffer->getCurrentLock().data, pData, cx * cy * 3/* + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO)*/); Engine->m_pixelBuffer->unlock(); if (m_nFrameNumber == 5) { CFile myfile; myfile.Open( "e:\\hkx.bmp",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary); myfile.Write(&BMPFileHeader, sizeof(BITMAPFILEHEADER)); myfile.Write(m_pBitMapInfo,sizeof(BITMAPINFO)); myfile.Write(pData, cx * cy * 3); myfile.Close(); } AVIStreamGetFrameClose(pg); Engine->m_Root->renderOneFrame(); } break;