6

我有以下工作正常的管道:

gst-launch-1.0 -v filesrc location=/home/Videos/sample_h264.mov !解码器!视频转换!自动视频接收器

我想编写一个 C 程序来做同样的事情。所以我把之前的管道翻译成下面的代码:

pipeline = gst_pipeline_new ("video_pipeline"); 
if (!pipeline) {
g_print("Failed to create the pipeline\n");
return -1;
}

bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
watch_id = gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);

source  = gst_element_factory_make ("filesrc", "file-source");
decoder  = gst_element_factory_make ("decodebin", "standard-decoder");
converter  = gst_element_factory_make ("videoconvert", "converter");
sink     = gst_element_factory_make ("autovideosink", "video-sink");

if (!source  || !decoder || !converter || !sink) {
g_print("Failed to create one or more pipeline elements\n");
return -1;
}

g_object_set(G_OBJECT(source), "location", file_name, NULL);

gst_bin_add_many (GST_BIN (pipeline), source, decoder, converter, sink, NULL); 

if (!gst_element_link_many (source,  decoder, converter, sink, NULL)) {
g_print ("Failed to link some elements!\n");
return -1;
}
/* run */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
    GstMessage *msg;

g_print ("Failed to start up pipeline!\n");

/* check if there is an error message with details on the bus */
    msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
    if (msg)         {
  GError *err = NULL;

  gst_message_parse_error (msg, &err, NULL);
      g_print ("ERROR: %s\n", err->message);
      g_error_free (err);
      gst_message_unref (msg);
    }
    return -1;
}

但是当我尝试将解码器连接到转换器时出现错误。为什么它适用于命令行但不适用于 C 代码?

4

2 回答 2

6

As @HarvardGraff said, decodebin has no static src pads (see gst-inspect decodebin).

But you can use launch-strings in your app as well. That way GStreamer should handle all the linking):

GstError *error = NULL;
GstElement *pipeline = gst_parse_launch("filesrc name=src ! decodebin ! videoconvert ! autovideosink", &error);

if (!error) {
    GstElement filesrc = gst_bin_get_by_name(GST_BIN(pipeline), "src");
    g_object_set(filesrc, "location", "/home/Videos/sample_h264.mov", NULL);
}
于 2013-07-08T14:25:30.090 回答
6

decodebin 使用一种叫做“sometimes-pad”的东西,它基本上是一个在满足特定条件时会出现的 pad,在 decodebins 的情况下是被解码的媒体。gst-launch 将自动执行此类操作,但在代码中您需要注册一个回调,然后在该回调中链接 pad。另请参阅:GStreamer:如何连接动态打击垫

于 2013-07-06T14:37:23.353 回答