//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
#include "vfw.h" // for video // 由 AVI 檔中取出影像串流 //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool GetVideoStream(char *szFile,PAVISTREAM *gapavi,AVISTREAMINFO *avis)
{
//1 Initial the AVI library
AVIFileInit(); //2 Open an AVI-file HRESULT hr;
PAVIFILE pfile; // 讀取avi檔案
hr = AVIFileOpen(&pfile,szFile , 0, 0L); if (hr != 0)
{
return false;
} //3 Getting an AVI stream
//PAVISTREAM gapavi; // for storage the frames of AVI
int gcpavi; AVIFileGetStream(pfile, gapavi, 0L, 0); // 把得到的 Stream interface放在gapavi中 //4. Get the stream information
//AVISTREAMINFO avis;
AVICOMPRESSOPTIONS gaAVIOptions;
LPAVICOMPRESSOPTIONS galpAVIOptions; // Stream header的資訊放在 avis中
AVIStreamInfo(*gapavi, avis, sizeof(*avis));
galpAVIOptions = &gaAVIOptions;
// 把 gaAVIOptions的內容清為0
_fmemset(galpAVIOptions, 0, sizeof(AVICOMPRESSOPTIONS));
// 取出該 stream 的多媒體型態放在相對應的gaAVIOptions陣列中
galpAVIOptions->fccType = avis->fccType; switch(avis->fccType) {
case streamtypeVIDEO:
galpAVIOptions->dwFlags = AVICOMPRESSF_VALID | AVICOMPRESSF_KEYFRAMES | AVICOMPRESSF_DATARATE;
galpAVIOptions->fccHandler = 0;
galpAVIOptions->dwQuality = (DWORD)ICQUALITY_DEFAULT;
galpAVIOptions->dwKeyFrameEvery = (DWORD)-1; // Default
galpAVIOptions->dwBytesPerSecond = 0;
galpAVIOptions->dwInterleaveEvery = 1; break;
default:
break;
}
return true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------- bool Frame2File (PAVISTREAM *gapavi,AVISTREAMINFO *avis, AnsiString fPath)
{
PGETFRAME gapgf; // GetFrame物件 //5. 對指定的 gapavi video stream 進行解壓縮,傳回 GetFrame物件放在gapgf中
if (avis->fccType == streamtypeVIDEO) {
gapgf = AVIStreamGetFrameOpen(*gapavi, NULL);
if (gapgf == NULL)
return false;
}
//6. 對指定的時間(2th) 計算相對應的frame
LONG lFrameStart=AVIStreamStart(*gapavi);
LONG lFrameLength=AVIStreamLength(*gapavi);
Form1->Caption = String(lFrameLength); for(int i=lFrameStart ;iHandle=hBitmap;
Bitmap1->SaveToFile(fPath i ".bmp");
Form1->Image1->Picture->LoadFromFile(fPath i ".bmp");
Application->ProcessMessages();
delete Bitmap1; }
return true;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
PAVISTREAM gapavi;
AVISTREAMINFO avis;
AnsiString sPath,sName;
if(OpenDialog1->Execute())
{
// 取出 Video Stream
GetVideoStream(OpenDialog1->FileName.c_str(),&gapavi,&avis);
LONG lFrameLength=AVIStreamLength(gapavi);
sName = ExtractFileName(OpenDialog1->FileName);
sName = ChangeFileExt(sName,"");
sPath = String("C:\\Image\\") sName "(" String(lFrameLength) ")";
if (!DirectoryExists(sPath))
CreateDir(sPath);
sPath=sPath String("\\");
// 把每張圖存到資料夾裡
Frame2File(&gapavi,&avis,sPath);
}
}
//--------------------------------------------------------------------------- 這是把讀取avi的frame 存檔起來
可是avi讀取出的圖檔都是720*480
要怎要再存檔之前改成680*480 再來存檔呢? 我是新手 多多指教 ^^