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 memory bitmap handles or the file names 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 of the BMP or JPEG files (ImageFilePath parameter).
-
or 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 to the actual frame rate
-
invoke SendImageToVideoFromBitmaps once beforehand so the component can learn the video format (if this step is omitted the next step will fail)**
-
invoke StartPreview () or StartRecording ()
-
then periodically invoke SendImageToVideoFromBitmaps or SendImageToVideoFromBitmaps2 as soon as new frames are available to pass to the component.
-
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 event occurs periodically (depending on the FrameRate property), requesting the next image that will be used as a video frame to build 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 to the desired frame rate
-
create the OnVideoFromBitmapsNextFrameNeeded event, and put the code required to pass the bitmap handles, or the image files,
-
from the OnVideoFromBitmapsNextFrameNeeded event, invoke SendImageToVideoFromBitmaps or SendImageToVideoFromBitmaps2 and pass as parameter either the file name or the bitmap handle
-
invoke StartPreview () or StartRecording ()
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 parameter
-
when passing a bitmap handle to the BitmapHandle parameter, pass an empty string 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 high frame rate (e.g. FrameRate = 200) and then set the final frame rate when the recording ends from the OnAVIDurationUpdated 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, do 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;