2

我使用videomixer在一个窗口中显示multiplr图像我使用以下代码来做到这一点

#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));
}

我没有错误编译但是当我运行它时我什么也没有显示并且我有以下警告

(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.

有人可以帮助我吗?

4

1 回答 1

5

我在这段代码中没有看到你对gst_init()的调用。

从文档中

GStreamer 库应该在使用之前使用 gst_init() 进行初始化。

提示:之前发布的这个问题 确实调用了gst_init,并且没有出现此错误。

于 2013-10-30T16:36:26.787 回答