Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

VfW: avi compression problem

Hi, I created a tool for making an AVI out of seperated bitmaps with Video for Windows (vfw.pas).
AVISaveOptions should call the default VfW-dialog where the user can choose the compression. The Delphi 6 compiler shows no errors, but the program rises an exception at this line. I am not shure if there is something wrong with the opts parameter, but if I replace opts with a pointer, I get a compiler error. The following code shows the basic structure of my little program:



procedure TFormGui.Button1Click(Sender: TObject);
var
fileName: string;
fps: integer;
pFile: IAVIFile;
bitmap: TBitmap;
strhdr: TAVIStreamInfoA;
ps: IAVIStream;
psCompressed: IAVIStream;
opts: PAVICompressOptions;
bitmapInfo: PBitmapInfoHeader;
bitmapInfoSize: integer;
bitmapSize: cardinal;
bitmapBits: Pointer;
i, colors: integer;
begin
fps := 30;
SaveDialog.Execute;
fileName := SaveDialog.FileName;

// Open the file for writing
AVIFileOpen(pfile, PChar(fileName), OF_WRITE or OF_CREATE, nil);

// Get the first bmp in the list for setting format
bitmap := TBitmap.Create;
bitmap.LoadFromFile(SelectedFiles.Items[0]);

InternalGetDIBSizes(bitmap.Handle, bitmapInfoSize, bitmapSize, colors);
bitmapInfo := AllocMem(bitmapInfoSize);
bitmapBits := AllocMem(bitmapSize);
InternalGetDIB(bitmap.Handle, 0, bitmapInfo^, bitmapBits^, colors);

// Fill in the header for the video stream
FillChar(strhdr, SizeOf(strhdr), 0);
strhdr.fccType := streamtypeVIDEO;
strhdr.fccHandler := 0;
strhdr.dwScale := 1;
strhdr.dwRate := fps;
strhdr.dwSuggestedBufferSize := bitmapInfo^.biSizeImage;
strhdr.rcFrame.Right := bitmapInfo^.biWidth;
strhdr.rcFrame.Bottom := bitmapInfo^.biHeight;

// create the stream
AVIFileCreateStream(pfile, ps, strhdr);

FillChar(opts, SizeOf(opts), 0);
// get the compression options from the user

// ***** THIS IS WHERE THE ERROR OCCURS *****
AVISaveOptions(FormGui.Handle, ICMF_CHOOSE_KEYFRAME or
ICMF_CHOOSE_DATARATE, 1, ps, opts);

// make compressed stream
AVIMakeCompressedStream(psCompressed, ps, opts, nil);

InternalGetDIB(bitmap.Handle, 0, bitmapInfo^, bitmapBits^, 256);

// set the format of the compressed stream
AVIStreamSetFormat(psCompressed, 0, bitmapInfo, bitmapInfoSize);

// write out each video frame
for i := 0 to SelectedFiles.Count - 1 do
begin
Application.ProcessMessages;
bitmap.LoadFromFile(SelectedFiles.Items[i]);
InternalGetDIB(bitmap.Handle, 0, bitmapInfo^, bitmapBits^, 256);
AVIStreamWrite(psCompressed, i, 1, bitmapBits, bitmapSize,
AVIIF_KEYFRAME, nil, nil);
end;
end;


Does anybody know why the error occurs, or if there is an other
possibility to give the user the opportunity to choose the compression?

Thanks

genius8472

Comments

  • Justin BibJustin Bib USAMember Posts: 0

    / http://forcoder.org / free video tutorials and ebooks about [ JavaScript, Swift, C, C#, Go, C++, PHP, PL/SQL, Delphi, Objective-C, Visual Basic .NET, R, Assembly, Ruby, Python, Scratch, Perl, Visual Basic, Java, MATLAB Rust, SAS, ABAP, F#, Fortran, Scheme, Hack, Logo, FoxPro, Erlang, Alice, Scala, Transact-SQL, Awk, Dart, Lua, Apex, Lisp, D, Prolog, Crystal, Clojure, ML, Julia, VBScript, Bash, LabVIEW, Ada, COBOL, Kotlin ] _____

Sign In or Register to comment.