简体   繁体   English

Gstreamer1.0:将decodebin链接到视频会话

[英]Gstreamer1.0 : link a decodebin to videoconvert

I have the following pipeline which works fine: 我有以下管道工作正常:

gst-launch-1.0 -v filesrc location=/home/Videos/sample_h264.mov ! gst-launch-1.0 -v filesrc location = / home / Videos / sample_h264.mov! decodebin ! decodebin! videoconvert ! 视频转换! autovideosink autovideosink

I want to write a C program to do the same thing. 我想写一个C程序来做同样的事情。 So I translated the previous pipeline to the following code: 所以我将以前的管道转换为以下代码:

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

But I get error when I try to connect the decoder to the converter. 但是当我尝试将解码器连接到转换器时,我收到错误。 Why it works fine with the command line but not with C code? 为什么它在命令行中工作正常但不能用C代码工作?

Decodebin uses something called a "sometimes-pad", which is basically a pad that will show up when a certain condition is met, in decodebins case that is media being decoded. 解码器使用称为“有时垫”的东西,其基本上是在满足特定条件时将出现的填充,在解码媒体的解码箱中。 gst-launch will do this sort of thing automagically, but in code you need to register a callback, and then link the pad in that callback. gst-launch将自动执行此类操作,但在代码中,您需要注册一个回调,然后在该回调中链接pad。 See also: GStreamer: how to connect dynamic pads 另请参阅: GStreamer:如何连接动态焊盘

As @HarvardGraff said, decodebin has no static src pads (see gst-inspect decodebin ). 正如@HarvardGraff所说, decodebin没有静态src pad(参见gst-inspect decodebin )。

But you can use launch-strings in your app as well. 但您也可以在应用中使用启动字符串。 That way GStreamer should handle all the linking): 这样GStreamer应该处理所有链接):

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

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

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