前言
gstreamer中视频叠加OSD有很多种方式,比如textoverlay添加文字,gdkpixbufoverlay添加图片,clockoverlay或timeoverlay插件显示时间,pango插件进行复杂文本渲染,使用cairo插件绘制图形或者文字。
今天使用最后一种:cairo
项目源码:
如果是QT,pro文件需要导入:
pro:
PKGCONFIG += cairo
INCLUDEPATH += /usr/include/cairo/
显示动态心♥
main.cpp
#include <gst/gst.h>
#include <gst/video/video.h>
#include <cairo/cairo.h>
#include <cairo/cairo-gobject.h>
#include <glib.h>
static gboolean
on_message (GstBus * bus, GstMessage * message, gpointer user_data)
{
GMainLoop *loop = (GMainLoop *) user_data;
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_ERROR:{
GError *err = NULL;
gchar *debug;
gst_message_parse_error (message, &err, &debug);
g_critical ("Got ERROR: %s (%s)", err->message, GST_STR_NULL (debug));
g_main_loop_quit (loop);
break;
}
case GST_MESSAGE_WARNING:{
GError *err = NULL;
gchar *debug;
gst_message_parse_warning (message, &err, &debug);
g_warning ("Got WARNING: %s (%s)", err->message, GST_STR_NULL (debug));
g_main_loop_quit (loop);
break;
}
case GST_MESSAGE_EOS:
g_main_loop_quit (loop);
break;
default:
break;
}
return TRUE;
}
/* Datastructure to share the state we are interested in between
* prepare and render function. */
typedef struct
{
gboolean valid;
GstVideoInfo vinfo;
} CairoOverlayState;
/* Store the information from the caps that we are interested in. */
static void
prepare_overlay (GstElement * overlay, GstCaps * caps, gpointer user_data)
{
CairoOverlayState *state = (CairoOverlayState *) user_data;
state->valid = gst_video_info_from_caps (&state->vinfo, caps);
}
/* Draw the overlay.
* This function draws a cute "beating" heart. */
static void
draw_