ImageEn, unit imageenio

TImageEnIO.CreateAVIFile

TImageEnIO.CreateAVIFile


Declaration

function CreateAVIFile(const FileName: WideString; Rate: Double = 15.0; const codec: AnsiString='DIB '; const WavFilename: WideString = ''): TIECreateAVIFileResult;


Description

Creates a new, empty AVI file.

FileName: Full destination path

Rate: Specifies the number of frames per second, e.g. 20 means 20 fps (each frame shows for 50ms)

Code: The compression codec to use (must be installed on system) as a four characters string.
For example:
'cvid' : cinepak by Radius
'msvc' : Microsoft Video 1
'mp42' : Microsoft MPEG4 V2

More codecs are listed at www.fourcc.org or by searching for registered fourcc codes and wave formats on MSDN
If a codec is not specified, a dialog box appears to allow the user to select a compression.

WavFilename: An optional audio file to include as an audio track. Must be WAV format. Output video will match length of the audio file if longer than the video content.

You can save each frame to the created AVI file using the SaveToAVI method.
Finally, call CloseAVIFile to close the file.


Demos

Demo  Demos\VideoCapture\DesktopToAvi\DesktopToAvi.dpr
Demo  Demos\VideoCapture\ImagesToAvi\ImagesToAvi.dpr


Example 1

// Create an AVI file from images
ImageEnView.IO.CreateAVIFile( 'D:\output.avi', 20, 'DIB ' );

// Save frame 0
ImageEnView.IO.LoadFromFile('C:\frame0.jpg');
ImageEnView.IO.Params.BitsPerSample   := 8;
ImageEnView.IO.Params.SamplesPerPixel := 1;
ImageEnView.IO.SaveToAVI();

// Save frame 1
ImageEnView.IO.LoadFromFile('C:\frame1.jpg');
ImageEnView.IO.Params.BitsPerSample   := 8;
ImageEnView.IO.Params.SamplesPerPixel := 1;
ImageEnView.IO.SaveToAVI();

etc...

// Close the file
ImageEnView.IO.CloseAVIFile();


Example 2

// Create an AVI transitioning one image to another
const
  Frames_Per_Second = 20;
  Display_Seconds   = 5;
var
  proc: TImageEnProc;
  io: TImageEnIO;
  startBitmap, endBitmap : TIEBitmap;
  i, frameCount: Integer;
  transLevel: Single;
begin
  startBitmap := TIEBitmap.Create;
  endBitmap   := TIEBitmap.Create;

  proc := TImageEnProc.Create( nil );
  io   := TImageEnIO.Create( nil );
  try
    if io.CreateAVIFile('D:\Transition.avi', Frames_Per_Second, 'cvid' ) = ieaviNOCOMPRESSOR then
      raise Exception.create( 'This compressor is unavailable!' );

    startBitmap.LoadFromFile( 'D:\image1.jpg' );
    endBitmap.LoadFromFile( 'D:\image2.jpg' );

    // Call PrepareTransitionBitmaps once
    proc.PrepareTransitionBitmaps(startBitmap, endBitmap, SelectedTransitionEffect);

    frameCount := Display_Seconds * Frames_Per_Second;

    for i := 0 to frameCount - 1 do
    begin
      // We want levels from 0% to 100% (show start and end)
      transLevel := 100 / ( frameCount - 1 ) * i;

      // Call CreateTransitionBitmap for each required frame
      proc.CreateTransitionBitmap( transLevel, io.IEBitmap );
      io.SaveToAVI();

      Caption := IntToStr( Round( i / frameCount * 100 )) + '%';
    end;

    io.CloseAVIFile();
    Caption := 'Done!';

  finally
    startBitmap.Free();
    endBitmap.Free();
    proc.Free();
    io.Free();
  end;
end;