Skip to content

Video clips built on the fly by passing bitmap handles, BMP or JPEG files

A video clip can be created on the fly by directly passing either directly memory bitmap handles, either the file name of BMP or JPEG files.

This feature is activated when VideoSource is set to vs_JPEGsOrBitmaps.

The frames are passed by invoking SendImageToVideoFromBitmaps and passing as parameter:

  • either the path to one or the BMP or JPEG files (ImageFilePath parameter).

  • either a bitmap handle (BitmapHandle parameter, see remark (b) below),

  • BUILDING A VIDEO CLIP BY PASSING IMAGES WHEN THEY ARE RECEIVED, IN REAL TIME (e.g. the images are currently received from another live source at 15 fps)

  • set VideoSource = vs_JPEGsOrBitmaps

  • set FrameRate with the real frame rate

  • invoke SendImageToVideoFromBitmaps a first time so the component can learn the video format (if this step is omitted the next step will fail)**

  • invoke StartPreview () or StartRecording ()

  • then invoke periodically SendImageToVideoFromBitmaps or SendImageToVideoFromBitmaps2 as soon as new frames are available to pass to the component.

I

  1. BUILDING A VIDEO CLIP FROM AN EXISTING SET OF IMAGES (e.g. a set of Jpeg files located in a folder)

When StartPreview or StartRecording is invoked, the OnVideoFromBitmapsNextFrameNeeded occurs periodically (depending of the FrameRate property), requesting for the next image that will be used as a video frame to built the video stream.

From this event, invoke SendImageToVideoFromBitmaps and pass the bitmap handle or the file name of the next frame.

Sample code is available in the MainDemo project included in the package.

Remarks about SendImageToVideoFromBitmaps:

a) BitmapHandle and ImageFilePath are mutually exclusive:

  • when passing a file path to ImageFilePath, pass 0 to the BitmapHandle paramter

  • when passing a bitmap handle to the BitmapHandle parameter, pass an empty string to do not pass a file path to the ImageFilePath parameter

b) when passing a BitmapHandle, enable CanFreeBitmapHandle if TVideoGrabber must free the bitmap when it is no longer needed, or disable CanFreeBitmapHandle to reuse the bitmap later.

c) all the images passed to this event must have the same format.

Remark about the frame rate When recording without audio to an AVI file, it is possible to record as fast as possible by setting a very hight frame rate, e.g. FrameRate = 200) and then set the final frame rate when the recording ends from the OnEndOfAVIRecording event.

  • **it is possible to apply the on the fly compression before invoking StartRecording, if needed.

  • the FirstSample parameter is true for the first frame, and false for the others. It is possible to test it e.g. to restart from the first bitmap.

  • set EndOfData to true to notify the end of stream. This is equivalent to invoking StopRecording or StopPreview.

c. when passing a bitmap handle, no not release it. If the bitmap handle is picked up from a TBitmap object (by passing TBitmap.Handle), be sure to release the handle before freeing the TBitmap.

E.g.:

procedure TForm1.VideoGrabberVideoFromBitmapsNextFrameNeeded(Sender: TObject; FirstSample: Boolean);

var

Bitmap: TBitmap;

begin

Bitmap:= TBitmap.Create;

Bitmap.Assign (Image1.Picture);

BitmapHandle:= Bitmap.Handle;

VideoGrabber. SendImageToVideoFromBitmaps ("", LongInt (BitmapHandle), true, false); Bitmap.ReleaseHandle;

Bitmap.Free;

end;