Приветствую уважаемых форумчан, пишу класс для работы с AVI. Собственно возникла проблема с созданием AVI файла. Переменные класса: Код | private AVI_DPI : integer; FFrame: TBitmap; FFrameCount: integer; FFramesBuff: TBitmapList; FFrameBuffSize: integer; FFrameInfo: PBitmapInfoHeader; FFrameBits: Pointer; FFrameSize: LongInt; asi: TAVIStreamInfoA; fFlyComp: boolean; FFPS: integer; FWidth : integer; FHeight : integer; pfile : IAVIFile; Stream, Stream_c : IAVIStream; // AVI stream and stream to be compressed FTempName: string; FFileName: string; fFrameTime: integer; fFourCC: TFourCC; fPixelFormat: TPixelFormat; fCompressionQuality: integer; AviCompressOptions: TAviCompressOptions;
|
Инициализация: Код | constructor TAVIWritter.Create(Height, Width: integer; FPS: integer; BufferSize: integer; FilePath: string); var TempDir: string; i: integer; begin SetLength(TempDir, MAX_PATH + 1); i := GetTempPath(MAX_PATH, PChar(TempDir)); SetLength(TempDir, i); if copy(TempDir, Length(TempDir), 1) <> '\' then TempDir := TempDir + '\'; FTempName := TempDir + 'simba.avi'; begin FFramesBuff:=TBitmapList.Create; SetHeight(Height); SetWidth(Width); SetFPS(FPS); SetBufferSize(BufferSize); SetFIlePath(FilePath); fFrameTime := 1000; fFourCC := ''; if CreateAviFile(0) then inherited Create else raise Exception.Create('Cannot initialize writter!'); end; end;
|
А создаю avi следующим образом(механизм подглядел в GLScene): Код | var bitmapInfoSize: Integer; AVIResult: Cardinal; ResultString: String; s: string; LocOptions: TAviCompressOptions; begin Result:=(FTempName<>''); if Result then begin if FileExists(FTempName) then begin DeleteFile(PChar(FTempName)); end; end; if not Result then Exit; AVIFileInit; // initialize the AVI lib. FFrame:=Graphics.TBitmap.Create; // AVIFrameIndex:=0; try FFrame.PixelFormat := fPixelFormat; FFrame.Width := FWidth; FFrame.Height := FHeight; // note: a filename with extension other then AVI give generate an error. if AVIFileOpen(pfile, PAnsiChar(AnsiString(FTempName)), OF_WRITE or OF_CREATE, nil)<>AVIERR_OK then raise Exception.Create('Cannot create AVI file. Disk full or file in use?'); with FFrame do begin InternalGetDIBSizes(Handle, bitmapInfoSize, FFrameSize,pf24bit); FFrameInfo:=AllocMem(bitmapInfoSize); FFrameBits:=AllocMem(FFrameSize); InternalGetDIB(Handle, 0,FFrameInfo^, FFrameBits^,pf24bit); end; FillChar(asi,sizeof(asi),0); with asi do begin fccType :=streamtypeVIDEO; // Now prepare the stream fccHandler:=0; dwScale :=1; // dwRate / dwScale = frames/second dwRate :=FFPS; dwSuggestedBufferSize:=FFrameInfo^.biSizeImage; rcFrame.Right :=FFrameInfo^.biWidth; rcFrame.Bottom:=FFrameInfo^.biHeight; end;
if AVIFileCreateStream(pfile, Stream, asi)<>AVIERR_OK then raise Exception.Create('Cannot create AVI stream.'); with FFrame do InternalGetDIB(Handle,0, FFrameInfo^, FFrameBits^,pf24bit); AVICompressOptions.fccType:=streamtypeVIDEO; FillChar(AviCompressoptions, SizeOf(AviCompressoptions), 0); if fFourCC <> '' then begin with AviCompressOptions do begin fccHandler := asi.fccHandler; fccType := asi.fccType; S := fFourCC; if S = '' then fccHandler := 0 else dwKeyFrameEvery := round(1000 / fFrameTime); dwQuality := fCompressionQuality; dwBytesPerSecond:=FFPS; dwFlags := AVICOMPRESSF_DATARATE or AVICOMPRESSF_KEYFRAMES; lpFormat := @FFrameInfo; cbFormat := SizeOf(fFrameSize); end; LocOptions:=AVICompressOptions; AVIResult:=AVIMakeCompressedStream(Stream_c, Stream, @LocOptions, nil); end; if AVIResult<>AVIERR_OK then begin if AVIResult=AVIERR_NOCOMPRESSOR then ResultString:='No such compressor found' else ResultString:=''; raise Exception.Create('Cannot make compressed stream. '+ResultString); end; if AVIStreamSetFormat(Stream_c, 0, @FFrameInfo, bitmapInfoSize)<>AVIERR_OK then raise Exception.Create('AVIStreamSetFormat Error'); // no error description found in MSDN. AVI_DPI:=DPI; with FFrame do InternalGetDIB(Handle,0, FFrameInfo^, FFrameBits^,pf24bit); AVICompressOptions.fccType:=streamtypeVIDEO; FillChar(AviCompressoptions, SizeOf(AviCompressoptions), 0);
except CloseAVIFile(); //raise; end; end;
|
Так вот все время, как бы я не изворачивался - на строке Код | AVIResult:=AVIMakeCompressedStream(Stream_c, Stream, @LocOptions, nil);
|
- вываливается с ошибкой, причем в AVIResult все время число 4215757. Нигде в доках описания этого не нашел. В чем может быть проблема?
|