简体   繁体   English

gstreamer管道显示图像

[英]gstreamer pipeline to show images

i use videomixer to display multiplr images in one windows i use the following code to do it 我使用videomixer在一个窗口中显示多个图像我使用以下代码来执行此操作

#include <gst/gst.h> 
#include <glib.h>




static gboolean bus_call (GstBus     *bus,
                          GstMessage *msg,
                          gpointer    data)
{
  GMainLoop *loop = (GMainLoop *) data;

  switch (GST_MESSAGE_TYPE (msg)) {

   case GST_MESSAGE_EOS:
      g_print ("End of stream\n");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_ERROR: {
      gchar  *debug;
      GError *error;

      gst_message_parse_error (msg, &error, &debug);
      g_free (debug);

      g_printerr ("Error: %s\n", error->message);
      g_error_free (error);

      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }
  return TRUE;
}

static void
on_pad_added (GstElement *element,
              GstPad     *pad,
              gpointer    data)
{
  GstPad *sinkpad;
  GstElement *decoder = (GstElement *) data;

  /* We can now link this pad with the vorbis-decoder sink pad */
  g_print ("Dynamic pad created, linking demuxer/decoder\n");

  sinkpad = gst_element_get_static_pad (decoder, "sink");

  gst_pad_link (pad, sinkpad);
  gst_object_unref (sinkpad);
}

int
main (int   argc,
      char *argv[]) {

GMainLoop *loop;

GstElement *pipeline,*freeze,*clrspace;
GstElement *source1;
GstElement *source2;
GstElement *videobox1,*videobox2;
GstElement *mixer,*sink,*queuevideo;
GstBus *bus;

loop = g_main_loop_new (NULL, FALSE);

/* Create gstreamer elements */
pipeline = gst_pipeline_new ("player");
source1  = gst_element_factory_make ("playbin2", "dec1");
source2  = gst_element_factory_make ("playbin2", "dec2");
freeze = gst_element_factory_make ("imagefreeze", "fr");
//videobox1 = gst_element_factory_make ("videobox",       "videobox1");
//videobox2 = gst_element_factory_make ("videobox",       "videobox2");
clrspace  = gst_element_factory_make ("ffmpegcolorspace",       "clrspace");
mixer = gst_element_factory_make ("videomixer",       "mixer");
queuevideo = gst_element_factory_make ("queue", "queue-video");
sink     = gst_element_factory_make ("xvimagesink", "sink");


if (!pipeline || !source1 || !source2 || !sink || !mixer ||!freeze || !clrspace || !queuevideo ) {
    g_printerr ("One element could not be created. Exiting.\n");
    exit(1);
}

g_object_set (source1, "uri", "http://www.logotheque.fr/6396-2/logo+RMC+INFO.jpg", NULL);
g_object_set (source2, "uri", "http://www.logotheque.fr/6396-2/logo+RMC+INFO.jpg", NULL);

// g_object_set(videobox1,"border-alpha",0,"top",0,"left",0,NULL);
// g_object_set(videobox2,"border-alpha",0,"top",0,"left",-200,NULL);

/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);

/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
                  source1,mixer, clrspace, freeze, sink, source2, NULL);

/* we link the elements together */
gst_element_link_many (source1, mixer, clrspace, freeze,sink,source2, NULL);
//gst_element_link_many (source[1], mixer, NULL);

 g_signal_connect (source1, "pad-added", G_CALLBACK (on_pad_added), queuevideo);
 g_signal_connect (source2, "pad-added", G_CALLBACK (on_pad_added), queuevideo);


/* Set the pipeline to "playing" state*/
gst_element_set_state (pipeline, GST_STATE_PLAYING);

/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);

/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);

g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
}

i don't have a errors compilation but when i run it i show nothing and i have a following warning 我没有编译错误,但是当我运行它时我什么也没有显示,我有一个警告

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

(process:5959): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed
One element could not be created. Exiting.

someone can help me please? 有人可以帮我吗?

I do not see your call to gst_init() in this code. 我在这段代码中看不到你对gst_init()的调用。

From the documentation : 从文档

The GStreamer library should be initialized with gst_init() before it can be used. 应该先使用gst_init()初始化GStreamer库,然后才能使用它。

Hint: your previous post of this question did call gst_init , and did not have this error. 提示:之前提到的这个问题 确实调用了gst_init ,并没有出现此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM