Frame capture features
Video frames can be captured during preview, recording and playback when the frame grabber is enabled. The frame grabber can be inserted on the preview stream, the capture stream, or both: see the FrameGrabber property. In the evaluation version, the frame grabber is always inserted on both streams and the frames carry the evaluation watermark: see Evaluation version.
Frames can be captured, one by one or automatically in burst mode, to:
- memory bitmaps,
- BMP files,
- JPEG files,
- PNG files,
- TIFF files,
- the clipboard (CF_BITMAP).
Direct copy of the bitmap handle (or bitmap bits array) of the current frame from the OnFrameBitmap event
For each video frame traveling through the graph, the OnFrameBitmap event occurs and makes it possible to capture the bitmap bits directly.
This is the method that requires the least CPU. However, as the OnFrameBitmap event is called directly from a thread (1), the bitmap handle and the bitmap bits are valid only when the event occurs, so they must be copied to another buffer immediately.
(1) The event can be synchronized with the Windows main thread by enabling the OnFrameBitmapEventSynchrone property.
This method can slow down the graph and/or produce a jerky preview, because the processing time added in the event is included in the frame processing time: if the processing time of a frame becomes longer than the interval between 2 frames, frames are dropped.
So it is recommended mainly when the graph is previewing (started by invoking StartPreview): in this case dropped frames are less critical than during a recording (which could become jerky) or during playback (which may appear jerky).
Sample code can be found in the OnFrameBitmap event of the MainDemo project (search for "FrameBitmap" in the MainForm).
Note
By default, this event is not raised for the 4K / 8K video clips, whose frames are kept in NV12 (FrameGrabberRGBFormat = fgf_Default): to receive it, set FrameGrabberRGBFormat = fgf_RGB32 before opening the clip, see 4K and 8K playback. The methods described in the next 2 sections (direct frame capture, and frame capture with CaptureFrameTo or the burst mode) work with these clips.
Direct frame capture of the current frame (or previous frames)
Invoke GetLastFrameAsHBITMAP (all versions) or GetLastFrameAsTBitmap (Delphi/C++Builder versions only) to get a copy of the current (or previous) frame at the desired size, with or without overlays.
This method does not slow down the graph and does not generate dropped frames.
Sample code is shown in the MotionDetected event of the MainDemo project, which displays a copy of the last frame detected with motion in the "Overlay" tab.
Frame capture of the current frame (or next frames automatically in burst mode)
This method uses CaptureFrameTo (or the burst mode) and the OnFrameCaptureCompleted event.
It does not slow down the graph and does not generate dropped frames.
With or without overlays
If the application performs graphic or text overlays, the frames are captured with the overlays by default. To capture the frames without overlays, enable the FrameCaptureWithoutOverlay property.
Asynchronous vs. synchronous frame capture
Asynchronous frame capture
To capture frames one by one, invoke CaptureFrameTo. The function sends a "capture order" and exits immediately. The captured frame is then returned by the OnFrameCaptureCompleted event.
To capture frames automatically, use the burst mode. Frames can be captured to TBitmap, top-down TBitmap, BMP file, JPEG file, PNG file, TIFF file or the clipboard according to the BurstType property. Frames are captured indefinitely if BurstCount = 0; otherwise the frame capture stops when BurstCount frames have been captured. If BurstInterval > 0, BurstInterval frames are skipped between each captured frame.
The burst mode is activated by enabling BurstMode. It is deactivated:
- by disabling BurstMode,
- if BurstCount > 0, when BurstCount frames have been captured.
When capturing video frames to BMP, JPEG, PNG or TIFF files, the file name is generated automatically according to StoragePath, AutoFileName and AutoFilePrefix:
- if no file name is specified when invoking CaptureFrameTo or CaptureFrameSyncTo,
- always in burst mode.
Frame capture of unmodified frames when performing frame overlay
When drawing over the video frames with the Frame Overlay feature, the frame capture occurs by default AFTER the frames have been overlaid (the objects drawn over the video frames appear on the captured frames). Enable the FrameCaptureWithoutOverlay property to capture the unmodified frames before they are overlaid.
Example of asynchronous frame capture from a video clip
The method is the same as described above, except that UseClock must be set to false before opening the clip, to play it at maximum speed, e.g.:
VideoGrabber.BurstMode = true
VideoGrabber.BurstCount = 5
VideoGrabber.BurstInterval = 10
VideoGrabber.BurstType = TFrameCaptureDest.fc_BmpFile
VideoGrabber.PlayerFileName = "... the file name of my video clip..."
VideoGrabber.UseClock = false
VideoGrabber.OpenPlayer
Size of the captured frames
- Default size: by default, the size of the captured frames is the current size of the video frames (returned by the VideoWidth and VideoHeight properties).
- Zoomed size: the captured frames can be zoomed by specifying a FrameCaptureZoomSize percentage. The default value is 100 (100%).
- Custom size: the captured frames can be stretched to a specified width, height or both by assigning a value to FrameCaptureWidth and/or FrameCaptureHeight. The default value of both is -1 (disabled).
If a value other than 100 is assigned to FrameCaptureZoomSize, FrameCaptureWidth and FrameCaptureHeight are ignored.
Synchronous frame capture through the frame grabber
Invoke CaptureFrameSyncTo: the function waits for the frame capture to be completed before returning. The frame is returned through the OnFrameCaptureCompleted event, and then the function returns true upon success, exactly like the asynchronous CaptureFrameTo described above.
Synchronous frame capture with the frame grabber disabled
The frame being displayed in the video renderer can be captured by invoking CaptureFrameRenderedTo, which makes it possible to disable the frame grabber to save CPU load and memory.
How to capture a sub-rectangle of the video frame
To capture a sub-rectangle, invoke SetFrameCaptureBounds (Left, Top, Right, Bottom) before invoking CaptureFrameTo or CaptureFrameSyncTo. To retrieve the current size of the video frame, use VideoWidth and VideoHeight.
How to stretch the captured video frame
To resize the video frame as desired, specify a FrameCaptureWidth and/or FrameCaptureHeight value.
How to zoom the captured video frame
To resize the captured frame, assign a zoom percentage to FrameCaptureZoomSize.
Top-down and left-right frame capture
Invoke SetFrameCaptureBounds and specify the bottom instead of the top, and/or the left instead of the right. To retrieve the current size of the video frame, use VideoWidth and VideoHeight.