#include "vfw.h"
#pragma comment(lib, "vfw32.lib")
#pragma comment(lib, "Winmm.lib")
AVIFileInit();
PAVIFILE pAviFile = nullptr;
// 打開AVI檔案
int nRet = AVIFileOpen(&pAviFile, "10.82.27.20_00_201908231542_part0.avi", OF_READ, NULL);
if (nRet == 0)
{
// 讀取AVI檔案的資訊
AVIFILEINFO aviFileInfo = { 0 };
AVIFileInfo(pAviFile, &aviFileInfo, sizeof(AVIFILEINFO));
// 提取出AVI檔案的某種流,此例為視訊流
PAVISTREAM pAviStrem = nullptr;
AVIFileGetStream(pAviFile, &pAviStrem, streamtypeVIDEO, 0);
// 讀取流資訊
AVISTREAMINFO aviStreamInfo = { 0 };
AVIStreamInfo(pAviStrem, &aviStreamInfo, sizeof(AVISTREAMINFO));
/*
// type 為流格式(音頻或視訊),handler為壓縮方法:如H264
char handler[4],type[4];
handler[0] = stinfo.fccHandler;
handler[1] = stinfo.fccHandler >> 8;
handler[2] = stinfo.fccHandler >> 16;
handler[3] = stinfo.fccHandler >> 24;
type[0] = stinfo.fccType;
type[1] = stinfo.fccType >> 8;
type[2] = stinfo.fccType >> 16;
type[3] = stinfo.fccType >> 24;
//如果是壓縮的視訊(一般都是壓縮的),打開讀取壓縮桢的函數
PGETFRAME pGetFrame = AVIStreamGetFrameOpen(pAviStrem, NULL);
//傳回解壓縮後,圖像的資訊
LPBITMAPINFOHEADER lpbm = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pGetFrame, 1);
//讀入并解壓縮視訊的每一幀
for (int i = 0; i < aviFileInfo.dwLength; i++)
{
memcpy(RGBbuf,(BYTE*)AVIStreamGetFrame(pgf,i)+40,pfi.dwWidth*pfi.dwHeight*3);
}
//關閉讀取壓縮桢的函數
AVIStreamGetFrameClose(pGetFrame);*/
char* szBuf = new char[500 * 1024];
memset(szBuf, 0, 500 * 1024);
const int headerSize = sizeof(CMD_HEADER) + sizeof(AV_VIDEO_INFO);
while (!m_bExit)
{
for (int i = 0; i < aviFileInfo.dwLength; i++)
{
// 擷取編碼前資料
AVIStreamRead(pAviStrem, i, 1, szBuf + headerSize, 500 * 1024 - headerSize, NULL, NULL);
}
}
//釋放AVI檔案指針
AVIFileRelease(pAviFile);
}
AVIFileExit();