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

Prev

Next

 






































































































How to create a video clip directly from bitmap handles.

Description

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),

1. 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

2. 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.

- set VideoSource = vs_JPEGsOrBitmaps,
- set FrameRate with the desired frame rate
- create the OnVideoFromBitmapsNextFrameNeeded event, and put the code required to pass the bitmap handles, or the the image files,
- from the OnVideoFromBitmapsNextFrameNeeded event, invoke SendImageToVideoFromBitmaps or SendImageToVideoFromBitmaps2 and pass as parameter either the file name, either the bitmap handle
- invoke StartPreview() or StartRecording()

You can find sample code in the MainDemo project included in the package.

Remarks about SendImageToVideoFromBitmaps:

a) BitmapHandle and ImageFilePath are mutually exclusive:

- if you pass a file path to ImageFilePath, pass 0 to the BitmapHandle paramter
- if you pass a bitmap handle to the BitmapHandle parameter, pass an empty string to do not pass a file path to the ImageFilePath parameter

b) if the you pass a BitmapHandle, enable CanFreeBitmapHandle if TVideoGrabber must free the bitmap when it is no longer needed, or disable CanFreeBitmapHandle if you need 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.

* you can 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. You can test it e.g. to restart from your first bitmap.
* set EndOfData to true to notify the end of stream. This is equivalent to invoking StopRecording or StopPreview.


c. if you pass 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;



See Also
TOnVideoFromBitmapsNextFrameNeeded