Graphic overlays
Frame overlay
When the frame grabber is enabled, graphics or text can be overlaid over the uncompressed RGB video frames during preview, recording or playback.
For the graphics and text overlays to be applied over the recorded video frames during recording, the RecordingInNativeFormat property must be disabled.
Getting direct access to the current video frame bitmap
The OnFrameBitmap event, which occurs for each video frame, gives direct access to each video frame (see this event for more information).
The sample code is available in the "MainForm" of the MainDemo project included in the package: search for "FrameBitmap".
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.
From this event, do not perform any action with the potential to block:
- do not hold a critical section or wait on another thread,
- do not call any GDI or USER32.DLL API that might cause a window to move,
- do not invoke component properties that send messages, e.g. do not read the ItemIndex property of a ListBox component.
To read such a property, set an intermediary variable when the property changes, then read the intermediary variable from the OnFrameBitmap event.
Restrictions
- When the video is recorded in "native" format (RecordingInNativeFormat = true), the drawing over the video frames is visible on the preview stream but not on the recorded stream (native means "unmodified").
- During the preview or recording of video capture boards having a video port (e.g. ATI Radeon), the drawing over the video frames is not visible on the preview stream when the video port is enabled.
Therefore:
- For the overlays to be visible on the preview window, disable the video port (but, depending on the video capture device, the preview could be jerky when previewing large video sizes or in full screen mode).
- To include the frame overlay in the recorded stream, disable RecordingInNativeFormat (however, this requires a higher CPU consumption during recording, because the video stream may have to be decompressed before applying the overlays).
Drawing bitmaps over video frames
The DrawBitmapOverFrame function draws bitmaps "as is" or stretched over the video frames. This function includes the transparency and alpha blending features.
It must be called only from the OnFrameBitmap event, which occurs for each video frame.
With the 4K / 8K video clips, OnFrameBitmap is not raised by default (see above): use an image overlay, or set FrameGrabberRGBFormat = fgf_RGB32 before opening the clip.
Drawing a shape over the video frames
This feature is not available in the OCX versions.
To draw a shape over the video frames:
- Put a TShape component on the form.
- Assign the TShape component to the ShapeOverlay property.
- Disable the Visible property of the TShape, so that the shape itself is not visible at runtime.
- Enable ShapeOverlayEnabled to activate the drawing of shapes over the video frames.
- At runtime, define the Left, Top, Width and Height properties of the TShape: TVideoGrabber uses them to position and resize the shape over the video frames.
Drawing several shapes over video frames
This feature is not available in the OCX versions.
To draw several shapes over the video frames:
- Put TShape components on the form (e.g. Shape1 and Shape2).
- Call VideoGrabber1.ShapeOverlayList (Shape1, true) to add the 1st shape to the shape list of TVideoGrabber.
- Call VideoGrabber1.ShapeOverlayList (Shape2, true) to add the 2nd shape to the shape list of TVideoGrabber.
- Disable the Visible properties of Shape1 and Shape2, so that the shapes themselves are not visible at runtime.
- Enable ShapeOverlayEnabled to activate the drawing of shapes over the video frames.
- At runtime, define the Left, Top, Width and Height properties of Shape1 and Shape2: TVideoGrabber uses them to position and resize the shapes over the video frames.
Note
Shapes are not drawn if their Enabled property is disabled.