首页 > 解决方案 > Gstreamer 管道不以:Streamer-CRITICAL **: 20:17:03.138: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed

问题描述

我正在尝试使用以下代码启动 gstreamer 管道:

#include <cstdlib>
#include <gst/gst.h>
#include <gst/gstinfo.h>
#include <gst/app/gstappsrc.h>
#include <glib-unix.h>
#include <dlfcn.h>

#include <cstring>
#include <iostream>
#include <sstream>
#include <thread>
using namespace std;
#define USE(x) ((void)(x))
static GstPipeline *gst_pipeline = nullptr;
static void *ptr = nullptr;
int main(int argc, char** argv) {
    USE(argc);
    USE(argv);
    gst_init (&argc, &argv);
    GMainLoop *main_loop;
    main_loop = g_main_loop_new (NULL, FALSE);
    ostringstream launch_stream;
    string lstr = "videotestsrc ! tee ! video/x-raw,format=BGR,width=1280,height=720 ! videoconvert "
           "! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM)' ! nvv4l2h264enc "
           "! h264parse ! matroskamux !  tcpserversink port=8888 host=0.0.0.0 ";
    g_print("Using launch string: %s\n", lstr.c_str());
    GError *error = nullptr;
    gst_pipeline  = (GstPipeline*) gst_parse_launch(lstr.c_str(), &error);
    if (gst_pipeline == nullptr) {
        g_print( "Failed to parse launch: %s\n", error->message);
        return -1;
    }
    if(error) g_error_free(error);
    gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_PLAYING);
    gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_NULL);
    gst_object_unref(GST_OBJECT(gst_pipeline));
    g_main_loop_unref(main_loop);
    free(ptr);
    g_print("going to exit \n");
    return 0;
}

它失败并出现以下错误:

(gstreamer-opencv:2668): GStreamer-CRITICAL **: 20:17:03.138: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed 
(gstreamer-opencv:26678): GStreamer-CRITICAL **: 20:17:03.165: gst_element_link_pads_filtered: assertion 'GST_IS_BIN (parent)' failed 
(gstreamer-opencv:26678): GStreamer-CRITICAL **: 20:17:03.170: gst_element_link_pads_filtered: assertion 'GST_IS_BIN (parent)' failed 
Opening in BLOCKING MODE  going to exit

(当我将此链放入 cv::VideoWriter 时发生同样的错误)

如果我从命令行启动它,它可以正常工作:

gst-launch-1.0 videotestsrc ! tee ! video/x-raw,format=BGR,width=1280,height=720 ! videoconvert ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM)' ! nvv4l2h264enc ! h264parse ! matroskamux !  tcpserversink port=8888 host=0.0.0.0

我的 c 代码中缺少什么?

标签: c++opencvgstreamernvidia-jetson

解决方案


推荐阅读