線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3078
推到 Plurk!
推到 Facebook!

aviFileOpen問題

缺席
frog1
一般會員


發表:25
回覆:40
積分:18
註冊:2007-01-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-10-12 12:03:08 IP:219.81.xxx.xxx 訂閱
Hi, 各位前輩
如下列程式碼,
在Delphi 7, 用AviFil32.dll寫了一個類別, 可用來將Bmp檔轉成AVI, 但該類別在Delphi2009, 卻無法執行(用2009編譯過)
在 intaviopen := AVIFileOpen(@pFile, PChar(FileName), OF_WRITE or OF_CREATE, 0);
intAviOpen的值為 2147746132, 查了這錯誤為 REGDB_E_CLASSNOTREG
有下載 aviFile.reg再做登入, 但就是無法正常執行
懇請前輩們指點


[code delphi]
unit U_ClassBmp2AVI;
interface
uses
Windows, SysUtils, Variants, Classes, Controls, ComCtrls, ExtCtrls, StdCtrls
, Graphics;

type TFourCC = string[4];
const // AVISaveOptions Dialog box flags
ICMF_CHOOSE_KEYFRAME = 1; // show KeyFrame Every box
ICMF_CHOOSE_DATARATE = 2; // show DataRate box
ICMF_CHOOSE_PREVIEW = 4; // allow expanded preview dialog
ICMF_CHOOSE_ALLCOMPRESSORS = 8; // don't only show those that
// can handle the input format
// or input data
AVIIF_KEYFRAME = 10;

type
AVI_COMPRESS_OPTIONS = packed record
fccType: DWORD; // stream type, for consistency
fccHandler: DWORD; // compressor
dwKeyFrameEvery: DWORD; // keyframe rate
dwQuality: DWORD; // compress quality 0-10,000
dwBytesPerSecond: DWORD; // bytes per second
dwFlags: DWORD; // flags... see below
lpFormat: DWORD; // save format
cbFormat: DWORD;
lpParms: DWORD; // compressor options
cbParms: DWORD;
dwInterleaveEvery: DWORD; // for non-video streams only
end;
AVI_STREAM_INFO = packed record
fccType: DWORD;
fccHandler: DWORD;
dwFlags: DWORD;
dwCaps: DWORD;
wPriority: word;
wLanguage: word;
dwScale: DWORD;
dwRate: DWORD;
dwStart: DWORD;
dwLength: DWORD;
dwInitialFrames: DWORD;
dwSuggestedBufferSize: DWORD;
dwQuality: DWORD;
dwSampleSize: DWORD;
rcFrame: TRect;
dwEditCount: DWORD;
dwFormatChangeCount: DWORD;
szName: array[0..63] of char;
end;
BITMAPINFOHEADER = packed record
biSize: DWORD;
biWidth: DWORD;
biHeight: DWORD;
biPlanes: word;
biBitCount: word;
biCompression: DWORD;
biSizeImage: DWORD;
biXPelsPerMeter: DWORD;
biYPelsPerMeter: DWORD;
biClrUsed: DWORD;
biClrImportant: DWORD;
end;
BITMAPFILEHEADER = packed record
bfType: word; //"magic cookie" - must be "BM"
bfSize: integer;
bfReserved1: word;
bfReserved2: word;
bfOffBits: integer;
end;

type
TBmp2AVI = class
private
Opts: AVI_COMPRESS_OPTIONS;
pOpts: Pointer;
pFile, ps, psCompressed: DWORD;
strhdr: AVI_STREAM_INFO;
i: integer;
// BFile: file;
m_Bih: BITMAPINFOHEADER;
m_Bfh: BITMAPFILEHEADER;
m_MemBits: packed array of byte;
m_MemBitMapInfo: packed array of byte;
FramesPerSec: integer;
isAviFormatOk : Boolean;
intFrameIndex : Integer;
public
ConStructor Create(owner : TComponent;const FileName: string; mstBmp : TMemoryStream);
destructor Destroy;OverRide;
Procedure BmpAdd(mstBmp : TMemoryStream);
end;
// DLL External declarations
function AVISaveOptions(Hwnd: DWORD; uiFlags: DWORD; nStreams: DWORD;
pPavi: Pointer; plpOptions: Pointer): boolean; stdcall; external 'avifil32.dll';
function AVIFileCreateStream(pFile: DWORD; pPavi: Pointer; pSi: Pointer): integer;
stdcall; external 'avifil32.dll';
function AVIFileOpen(pPfile: Pointer; szFile: PChar; uMode: DWORD;
clSid: DWORD): integer;stdcall; external 'avifil32.dll';
function AVIMakeCompressedStream(psCompressed: Pointer; psSource: DWORD;
lpOptions: Pointer; pclsidHandler: DWORD): integer;stdcall; external 'avifil32.dll';
function AVIStreamSetFormat(pAvi: DWORD; lPos: DWORD; lpGormat: Pointer;
cbFormat: DWORD): integer;stdcall; external 'avifil32.dll';
function AVIStreamWrite(pAvi: DWORD; lStart: DWORD; lSamples: DWORD;
lBuffer: Pointer; cBuffer: DWORD; dwFlags: DWORD;plSampWritten: DWORD; plBytesWritten: DWORD): integer;
stdcall; external 'avifil32.dll';
function AVISaveOptionsFree(nStreams: DWORD; ppOptions: Pointer): integer;
stdcall; external 'avifil32.dll';
function AVIFileRelease(pFile: DWORD): integer; stdcall; external 'avifil32.dll';
procedure AVIFileInit; stdcall; external 'avifil32.dll';
procedure AVIFileExit; stdcall; external 'avifil32.dll';
function AVIStreamRelease(pAvi: DWORD): integer; stdcall; external 'avifil32.dll';
function mmioStringToFOURCCA(sz: PChar; uFlags: DWORD): integer;stdcall; external 'winmm.dll';


implementation
{ TBmp2AVI }
//--- Create & Destory ----------------------------------------------------------------------
constructor TBmp2AVI.Create(owner : TComponent; const FileName: string; mstBmp: TMemoryStream);
var intaviopen : DWord;
begin
FramesPerSec := 15;
intFrameIndex := 0;
isAviFormatOk := False;
DeleteFile(FileName);
Fillchar(Opts, SizeOf(Opts), 0);
FillChar(strhdr, SizeOf(strhdr), 0);
// Opts.fccHandler := 541215044; // Full frames Uncompressed
Opts.fccHandler := mmioStringToFOURCCA('MPG4', 0);
AVIFileInit;
pfile := 0;
pOpts := @Opts;
intaviopen := AVIFileOpen(@pFile, PChar(FileName), OF_WRITE or OF_CREATE, 0);
If intaviopen = 0 Then
Begin
mstBmp.Position := 0;
mstBmp.Read(m_Bfh, SizeOf(m_Bfh));
mstBmp.Read(m_Bih, SizeOf(m_Bih));
SetLength(m_MemBitMapInfo, m_bfh.bfOffBits - 14);
// SetLength(m_MemBits, m_Bih.biSizeImage);
SetLength(m_MemBits, mstBmp.size);
mstBmp.Position := SizeOf(m_Bfh);
mstBmp.Read(m_MemBitMapInfo[0], length(m_MemBitMapInfo));
strhdr.fccType := mmioStringToFOURCCA('vids', 0); // stream type video
// strhdr.fccHandler := 0; // def AVI handler
strhdr.fccHandler := mmioStringToFOURCCA('PMG4', 0);
strhdr.dwScale := 1;
strhdr.dwRate := FramesPerSec; // fps 1 to 30
strhdr.dwSuggestedBufferSize := m_Bih.biSizeImage; // size of 1 frame
SetRect(strhdr.rcFrame, 0, 0, m_Bih.biWidth, m_Bih.biHeight);
If AVIFileCreateStream(pFile, @ps, @strhdr) = 0 Then
If AVIMakeCompressedStream(@psCompressed, ps, @opts, 0) = 0 Then
If AVIStreamSetFormat(psCompressed, 0, @m_memBitmapInfo[0],length(m_MemBitMapInfo)) = 0 Then
isAviFormatOk := True;
End;
end;
destructor TBmp2AVI.Destroy;
begin
AVIStreamRelease(ps);
AVIStreamRelease(psCompressed);
AVIFileRelease(pFile);
AVIFileExit;
m_MemBitMapInfo := nil;
m_memBits := nil;
inherited;
end;
procedure TBmp2AVI.BmpAdd(mstBmp: TMemoryStream);
begin
If isAviFormatOk Then
Begin
mstBmp.Position := 54; //SizeOf(m_bfh.bfOffBits);
// mstBmp.Read(m_MemBits[0], m_Bih.biSizeImage);
mstBmp.Read(m_MemBits[0], mstBmp.Size);
if AVIStreamWrite(psCompressed, intFrameIndex, 1, @m_MemBits[0], m_Bih.biSizeImage, AVIIF_KEYFRAME, 0, 0) <> 0 then
begin
// ShowMessage('Error during Write AVI File');
Exit;
end;
intFrameIndex := intFrameIndex 1;
End;
end;
End.

[/code]
frog1
一般會員


發表:25
回覆:40
積分:18
註冊:2007-01-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-10-12 15:01:44 IP:219.81.xxx.xxx 訂閱
Hi, 
感謝各位的精神支持, 問題已解
要在Delphi2009的Component -> Import Component 中將 WMPLib_TLB import進來
Delphi7也要, 只因太久了, 忘了有這項
系統時間:2024-04-25 4:29:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!