代码之家  ›  专栏  ›  技术社区  ›  RajviK

将Gstrplaybin链接到自定义视频接收器、videoconvert和接收器,不链接gstreamer

  •  1
  • RajviK  · 技术社区  · 7 年前

    正在尝试从管道生成gstreamer应用程序:gst-launch-1.0 playbin uri=rtsp://video-sink=“videoconvert!video/x-raw,width=720,height=480!ximagessink”

    获取链接元素的错误。发布我的代码:

    #include <gst/gst.h>
    
    int main(int argc, char *argv[]) {
        GstElement *source, *videosink, *pipeline, *videoconvert;
        GstCaps *capsFilter;
        GstBus *bus;
        GstMessage *msg;
        GstPad *pad;
        gboolean link_ok;
    
        /* Initialize GStreamer */
        gst_init (&argc, &argv);
    
    
        /* Create Elements */
        pipeline = gst_pipeline_new("my-pipeline");
        source = gst_element_factory_make ("playbin", "source");
        videoconvert = gst_element_factory_make("videoconvert", "convert");
        videosink = gst_element_factory_make("ximagesink", "autovideosink");
    
        /* set property value */
        g_object_set (source, "uri", "rtsp:<file location>", NULL);
    
        if (!pipeline || !source || !videoconvert || !videosink)
        {   
                g_printerr ("Not all elements could be created.\n");
                return;
        }   
    
    
        gst_bin_add_many (GST_BIN(pipeline), videoconvert, videosink, NULL);
        capsFilter = gst_caps_new_simple("video/x-raw",
                        "width", G_TYPE_INT, 176,
                        "height", G_TYPE_INT, 144, 
                        NULL);
        link_ok = gst_element_link_filtered(videoconvert,videosink, capsFilter);
        gst_caps_unref (capsFilter);
    
        if (!link_ok) {
                g_warning ("Failed to link element1 and element2!");
        }   
        if (gst_element_link_many( videoconvert, videosink, NULL) != TRUE) {
                g_print ("Failed to link some elements .....1 !\n");
                gst_object_unref (pipeline);
                return -1; 
        }   
    
    
          /* Start playing */
        gst_element_set_state (source, GST_STATE_PLAYING);
    
        /* Wait until error or EOS */
        bus = gst_element_get_bus (source);
        msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
    GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   jgorostegui    7 年前

    应该注意的是 playbin 元素提供了从src到sink的完整管道,因此没有sink元素的管道将完美发挥作用:

    gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8551/test
    

    下一步是要创建的正确管道:

    gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8551/test video-sink="videoconvert ! video/x-raw,width=320,height=240 ! ximagesink"
    

    为了将其嵌入到GStreamer应用程序中,不需要链接所有元素。相反,需要做的必要步骤是构建一个自定义视频输出箱并将其设置为playbin video-sink 所有物换句话说,方法是创建一个bin并链接必要的元素,然后通过它的 视频接收器 所有物还需要为仓创建一个重影垫,并将其指向仓内第一个元素的下沉垫。

    这是结果:

    #include <gst/gst.h>
    
    int main(int argc, char *argv[]) {
        GstElement *source, *videosink, *pipeline, *videoconvert, *customoutput;
        GstCaps *capsFilter;
        GstBus *bus;
        GstMessage *msg;
        GstPad *pad;
        gboolean add_ok;
        gboolean link_ok;
        GstStateChangeReturn ret;
        GMainLoop *loop;
    
        /* Initialize GStreamer */
        gst_init (&argc, &argv);
        loop = g_main_loop_new (NULL, FALSE);
    
    
        /* Create Elements */
        pipeline = gst_pipeline_new("my-pipeline");
        source = gst_element_factory_make ("playbin", "source");
        videoconvert = gst_element_factory_make("videoconvert", "videoconvert");
        capsFilter = gst_caps_new_simple("video/x-raw",
                        "width", G_TYPE_INT, 320,
                        "height", G_TYPE_INT, 240, 
                        NULL);
        videosink = gst_element_factory_make("ximagesink", "videosink");
        customoutput = gst_bin_new("customoutput");
    
        // It is possible to create the bin like this 
        // Ghost pads on the bin for unlinked source or sink pads within the bin can automatically be created
        // customoutput =  gst_parse_bin_from_description ("videoconvert ! video/x-raw,width=320 ! ximagesink", TRUE, NULL);
        gst_bin_add_many (GST_BIN (customoutput), videoconvert, videosink, NULL);
    
        link_ok = gst_element_link_filtered(videoconvert,videosink, capsFilter);
        gst_caps_unref (capsFilter);
        if (!link_ok) {
                g_warning ("Failed to link element1 and element2!");
        }
    
        GstPad *sinkpad,*ghost_sinkpad;
        sinkpad = gst_element_get_static_pad (videoconvert, "sink"); 
        ghost_sinkpad = gst_ghost_pad_new ("sink", sinkpad); 
        gst_pad_set_active (ghost_sinkpad, TRUE); 
        gst_element_add_pad (customoutput, ghost_sinkpad); 
    
        /* set property value */
        g_object_set (source, "video-sink", customoutput, NULL);
        g_object_set (source, "uri", "rtsp://127.0.0.1:8551/test", NULL);
    
        if (!pipeline || !source || !videoconvert || !capsFilter || !videosink || !customoutput)
        {   
                g_printerr ("Not all elements could be created.\n");
                return -1;
        }
    
        gst_bin_add_many (GST_BIN(pipeline), source,NULL);
    
        // Start playing */
        ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
        g_print ("Running...\n");
        g_main_loop_run (loop);
        if (ret == GST_STATE_CHANGE_FAILURE) {
            g_printerr ("Unable to set the pipeline to the playing state.\n");
            gst_object_unref (pipeline);
            return -1;
        }
        /* Wait until error or EOS */
        //bus = gst_element_get_bus (pipeline);
        //msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
    
          /* Free resources */
        gst_object_unref (bus);
        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (pipeline);
        g_main_loop_unref (loop);
    
        return 0;
    }