我有一个简单的 C++ 代码,使用 gstreamer 读取 rtsp 视频。 我是 gstreamer 新手,无法将 gst_parse_launch() 与我的 rtsp 链接的 URL_RTSP 变量连接起来。
这里没有有效的变量 URL_RTSP:
/* Build the pipeline */
pipeline = gst_parse_launch("rtspsrc protocols=tcp location=rtsp://user:pass@protocol:port/cam/realmonitor?channel=1&subtype=0 latency=300 ! decodebin3 ! autovideosink", NULL);
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
使用变量 URL_RTSP,不起作用:
/*Url Cams*/
std::string URL_RTSP = "rtsp://user:pass@protocol:port/cam/realmonitor?channel=1&subtype=0";
/* Build the pipeline */
pipeline =
gst_parse_launch("rtspsrc protocols=tcp location="+ URL_RTSP + " latency=300 ! decodebin3 ! autovideosink", NULL);
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
当我尝试使用变量时出错,gst_parse_launch() 收到错误:
there is no proper conversion function from "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>" to "const gchar *"
最佳答案
gst_parse_launch
采用 const gchar*
作为第一个参数:
GstElement* gst_parse_launch (const gchar* pipeline_description, GError** error)
但是,你提供的,
"rtspsrc protocols=tcp location="+ URL_RTSP +
" latency=300 ! decodebin3 ! autovideosink"
产生std::string
。我建议首先创建 std::string
,然后使用 c_str()
成员函数向其传递 const char*
。
std::string tmp =
"rtspsrc protocols=tcp location=" + URL_RTSP +
" latency=300 ! decodebin3 ! autovideosink";
pipeline = gst_parse_launch(tmp.c_str(), nullptr);
关于c++ - gst_parse_launch 没有从字符串到 gchar 的正确转换函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73708226/