GSTREAMER - 将命令行转换为C代码

时间:2013-10-24 15:49:32

标签: stream video-streaming converter gstreamer pipeline

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

gst-launch-1.0 -v tcpclientsrc host=192.168.1.132 port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! autovideosink

我想编写一个C程序来做同样的事情。

我将之前的管道转换为以下代码,但视频无法启动(HELP ME)

#include <gst/gst.h>

int main(int argc, char *argv[]) {
    GstBus *bus;
    GstMessage *msg;
    GstStateChangeReturn ret;

    /* Initialize GStreamer */
    gst_init (&argc, &argv);

    GError *error = NULL;

    GstElement *pipeline = gst_parse_launch("tcpserversrc name=src ! gdpdepay ! rtph264depay ! avdec_h264 !videoconvert ! autovideosink", &error);

    if (!pipeline) {
         g_print ("Parse error: %s\n", error->message);
         exit (1);
    }

    GstElement *src = gst_bin_get_by_name(GST_BIN(pipeline), "src");
    g_object_set(src, "host", "192.168.1.132","port",5000, NULL);

//开始播放

    ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);

    if (ret == GST_STATE_CHANGE_FAILURE) {
         g_printerr ("Unable to set the pipeline to the playing state.\n");
         gst_object_unref (pipeline);
         return -1;
    }else {
         g_printerr("ERROR PLAY\n");
    }

//等到错误或EOS

    bus = gst_element_get_bus (pipeline);
    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

    // Parse message
    if (msg != NULL) {
        GError *err;
        gchar *debug_info;

        switch (GST_MESSAGE_TYPE (msg)) {
            case GST_MESSAGE_ERROR:
                gst_message_parse_error (msg, &err, &debug_info);
                g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
                g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
                g_clear_error (&err);
                g_free (debug_info);
                break;
            case GST_MESSAGE_EOS:
                g_print ("End-Of-Stream reached.\n");
                break;
            default:
                // We should not reach here because we only asked for ERRORs and EOS
                g_printerr ("Unexpected message received.\n");
                break;
            }
        gst_message_unref (msg);
    }

//免费资源

    gst_object_unref (bus);
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);
    return 0;
}

2 个答案:

答案 0 :(得分:0)

我无法发现任何明显的事情。您是否尝试使用GST_DEBUG =“*:2”。/ myapp运行以查看是否存在某些警告

答案 1 :(得分:0)

gdppay / gdpdepay目前未移植到ios 1.2库中。我读过它应该包含在1.3 - 1.4版本中。我猜这就是问题所在。