File descriptor returned by
Applications can use the
VIDIOC_S_FBUF ioctl to get and set the
framebuffer parameters for a Video
Overlay or Video Output Overlay
(OSD). The type of overlay is implied by the device type (capture or
output device) and can be determined with the
One /dev/videoN device must not support both
kinds of overlay.
The V4L2 API distinguishes destructive and non-destructive overlays. A destructive overlay copies captured video images into the video memory of a graphics card. A non-destructive overlay blends video images into a VGA signal or graphics into a video signal. Video Output Overlays are always non-destructive.
To get the current parameters applications call the
VIDIOC_G_FBUF ioctl with a pointer to a
v4l2_framebuffer structure. The driver fills
all fields of the structure or returns an EINVAL error code when overlays are
To set the parameters for a Video Output
Overlay, applications must initialize the
flags field of a struct
v4l2_framebuffer. Since the framebuffer is
implemented on the TV card all other parameters are determined by the
driver. When an application calls
with a pointer to this structure, the driver prepares for the overlay
and returns the framebuffer parameters as
VIDIOC_G_FBUF does, or it returns an error
To set the parameters for a non-destructive
Video Overlay, applications must initialize the
flags field, the
fmt substructure, and call
VIDIOC_S_FBUF. Again the driver prepares for the
overlay and returns the framebuffer parameters as
VIDIOC_G_FBUF does, or it returns an error
For a destructive Video Overlay
applications must additionally provide a
base address. Setting up a DMA to a
random memory location can jeopardize the system security, its
stability or even damage the hardware, therefore only the superuser
can set the parameters for a destructive video overlay.
Table 1. struct
|__u32||Overlay capability flags set by the driver, see Table 2.|
|__u32||Overlay control flags set by application and driver, see Table 3|
Physical base address of the framebuffer, that is the address of the pixel in the top left corner of the framebuffer.a
This field is irrelevant to non-destructive Video Overlays. For destructive Video Overlays applications must provide a base address. The driver may accept only base addresses which are a multiple of two, four or eight bytes. For Video Output Overlays the driver must return a valid base address, so applications can find the corresponding Linux framebuffer device (see Section 4.4).
|struct v4l2_pix_format||Layout of the frame buffer. The
|__u32||Width of the frame buffer in pixels.|
|__u32||Height of the frame buffer in pixels.|
The pixel format of the framebuffer.
For non-destructive Video
Overlays this field only defines a format for the
For destructive Video Overlays applications must initialize this field. For Video Output Overlays the driver must return a valid format.
Usually this is an RGB format (for example
|enum v4l2_field||Drivers and applications shall ignore this field.
If applicable, the field order is selected with the |
|__u32||Distance in bytes between the leftmost pixels in two adjacent lines.|
This field is irrelevant to non-destructive Video Overlays.
For destructive Video
Overlays both applications and drivers can set this field
to request padding bytes at the end of each line. Drivers however may
ignore the requested value, returning
For Video Output Overlays the driver must return a valid value.
Video hardware may access padding bytes, therefore they must reside in accessible memory. Consider for example the case where padding bytes after the last line of an image cross a system page boundary. Capture devices may write padding bytes, the value is undefined. Output devices ignore the contents of padding bytes.
When the image format is planar the
This field is irrelevant to non-destructive Video Overlays. For destructive Video Overlays applications must initialize this field. For Video Output Overlays the driver must return a valid format.
|enum v4l2_colorspace||This information supplements the
|__u32||Reserved for additional information about custom (driver defined) formats. When not used drivers and applications must set this field to zero.|
a. A physical base address may not suit all platforms. GK notes in theory we should pass something like PCI device + memory region + offset instead. If you encounter problems please discuss on the Video4Linux mailing list: https://listman.redhat.com/mailman/listinfo/video4linux-list.
Table 2. Frame Buffer Capability Flags
|0x0001||The device is capable of non-destructive overlays. When the driver clears this flag, only destructive overlays are supported. There are no drivers yet which support both destructive and non-destructive overlays.|
|0x0002||The device supports clipping by chroma-keying the images. That is, image pixels replace pixels in the VGA or video signal only where the latter assume a certain color. Chroma-keying makes no sense for destructive overlays.|
|0x0004||The device supports clipping using a list of clip rectangles.|
|0x0008||The device supports clipping using a bit mask.|
|0x0010||The device supports clipping/blending using the alpha channel of the framebuffer or VGA signal. Alpha blending makes no sense for destructive overlays.|
|0x0020||The device supports alpha blending using a global alpha value. Alpha blending makes no sense for destructive overlays.|
|0x0040||The device supports clipping/blending using the inverted alpha channel of the framebuffer or VGA signal. Alpha blending makes no sense for destructive overlays.|
Table 3. Frame Buffer Flags
|0x0001||The framebuffer is the primary graphics surface. In other words, the overlay is destructive. [?]|
|0x0002||The frame buffer is an overlay surface the same size as the capture. [?]|
|The purpose of
|0x0004||Use chroma-keying. The chroma-key color is
determined by the |
|There are no flags to enable
clipping using a list of clip rectangles or a bitmap. These methods
are negotiated with the |
|0x0008||Use the alpha channel of the framebuffer to clip or blend framebuffer pixels with video images. The blend function is: output = framebuffer pixel * alpha + video pixel * (1 - alpha). The actual alpha depth depends on the framebuffer pixel format.|
|0x0010||Use a global alpha value to blend the framebuffer
with video images. The blend function is: output = (framebuffer pixel
* alpha + video pixel * (255 - alpha)) / 255. The alpha value is
determined by the |
On success 0 is returned, on error -1 and the
errno variable is set appropriately:
VIDIOC_S_FBUF can only be called
by a privileged user to negotiate the parameters for a destructive
The framebuffer parameters cannot be changed at this time because overlay is already enabled, or capturing is enabled and the hardware cannot capture and overlay simultaneously.
The ioctl is not supported or the
VIDIOC_S_FBUF parameters are unsuitable.