Fast GStreamer overlay element

From RidgeRun Developer Wiki
Revision as of 14:50, 3 August 2012 by Tfischer (talk | contribs)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Description

emb-overlay is a gstreamer element that can be used to overlay: images, text and/or time and date over video streams or photos without using lots of floating point arithmetic. This is necessary to get good performance when the processor doesn't contain an FPU.

GStreamer embedded overlay element

After building the SDK and installing the images onto your target hardware, verify the embedded overlay element is available:

gst-inspect | grep emboverlay

With the expected output being:

emboverlayplugin:  emboverlay: overlay for embedded systems

To see the properties that are supported, run:

gst-inspect emboverlay

which will display an output similar to:

Element Properties:
  name                : The name of the object
                        flags: readable, writable
                        String. Default: null Current: "emboverlay0"
  logo                : Overlayed image path, must be a png file
                        flags: readable, writable
                        String. Default: null Current: null
  text                : Overlayed text to display
                        flags: readable, writable
                        String. Default: null Current: null
  logo-offseth        : Overlayed image horizontal offset
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  logo-offsetv        : Overlayed image vertical offset
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  logo-transp         : Overlayed image transparency. Enable = 1 Disable = 0
                        flags: readable, writable
                        Integer. Range: 0 - 1 Default: 0 Current: 0
  text-offseth        : Overlayed text horizontal offset
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  text-offsetv        : Overlayed text vertical offset
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  text-font-height    : Overlayed text font height
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  text-color          : Overlayed text color. Black = 0 Red = 1 Green = 2 Blue = 3 White = 4
                        flags: readable, writable
                        Integer. Range: 0 - 4 Default: 0 Current: 0
  time-offseth        : Overlayed time horizontal offset
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  time-offsetv        : Overlayed time vertical offset
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  time-font-height    : Overlayed time font size
                        flags: readable, writable
                        Integer. Range: -2147483648 - 2147483647 Default: 0 Current: 0
  time-color          : Overlayed time font color. Black = 0 Red = 1 Green = 2 Blue = 3 White = 4
                        flags: readable, writable
                        Integer. Range: 0 - 4 Default: 0 Current: 0
  time-param          : Overlayed time parameters %b %Y; %H:%M:%S will render: month year; hour:minutes:seconds
                        flags: readable, writable
                        String. Default: null Current: null

The (x,y) origin is the upper left corner.

GStreamer Pipelines

Next you will find various pipelines showing the emboverlay element capabilities, in this case the element was tested using a Leopardboard DM365 with a 5Mp sensor camera.

You can use emboverlay for text and/or date and/or logo overlay on each video frame.

Video overlay examples

Overlay text

Colored text can be entered using hexadecimal values in the following format:

0xRRGGBB

R stands for Red, G for Green, and B for Blue, with the possible values for each color being: 0-FF

Examples:

0xFFFFFF = White
0x000000 = Black
0xFF0000 = Red
0x00FF00 = Green
0x0000FF = Blue 
0xFF8000 = Orange

Any other combination are possible, the same principle applies to the color of the border of the text, letter color and border are chosen with the caps: "text-color", "text-border".

Example pipeline:

gst-launch v4l2src ! video/x-raw-yuv, format=\(fourcc\)NV12, width=640, height=480  ! emboverlay text-offsetv=40 text-offseth=40 text-font-height=50 text-color=0xFFFFFF \
text-border=0x000000 text="Hello overlay" ! TIDmaiVideoSink

Overlay date

emboverlay date has the same capabilities as the Unix date command, letter and border color can be chosen with the caps "time-color" and "time-border", using hexadecimal numbers with the format 0xRRGGBB, for example:

gst-launch v4l2src ! video/x-raw-yuv, format=\(fourcc\)NV12, width=640, height=480 ! emboverlay time-offsetv=40 time-offseth=40 time-font-height=50 time-color=0xFFFFFF time-param="%b %Y %H:%M:%S" time-border=0x000000 ! TIDmaiVideoSink

The only supported image file format is PNG. The image size in the file must be have even dimensions.

gst-launch v4l2src ! dmaiaccel ! video/x-raw-yuv, format=\(fourcc\)NV12, width=640, height=480 ! emboverlay logo="t2.png" logo-offsetv=250 logo-offseth=300 logo-transp=0 ! TIDmaiVideoSink

Mixing emboverlay text/logo/date

Emboverlay can overlay text and/or date and/or logo, the following is an example of a pipe with date and logo:

gst-launch v4l2src -e num-buffers=300 ! video/x-raw-yuv, format=\(fourcc\)NV12, width=640, height=480 ! emboverlay text-offsetv=40 text-offseth=40 text-font-height=80 text-color=0xFFFFFF text-border=0x000000 text="Hello overlay" time-offsetv=200 time-offseth=500 time-font-height=50 time-color=0x000000 time-param="%M:%S" time-border=0xFFFFFF ! dmaiperf ! TIDmaiVideoSink sync=false enable-last-buffer=false

Picture overlay examples

The following logo is used for the picture examples. The logo is 312 x 28 pixels in size and uses white (0xFFFFFF) as the transparency color.