首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gst_parse_launch没有正确的字符串到gchar的转换函数。

gst_parse_launch没有正确的字符串到gchar的转换函数。
EN

Stack Overflow用户
提问于 2022-09-13 19:14:53
回答 1查看 58关注 0票数 2

我有一个简单的代码与c++使用gstreamer读取rtsp视频。我是gstreamer的新手,我无法将gst_parse_launch()与rtsp链接的URL_RTSP变量连接起来。

这里没有变量URL_RTSP,它可以工作:

代码语言:javascript
复制
  /* 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,不起作用:

代码语言:javascript
复制
  /*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);

当我尝试使用with变量时,gst_parse_launch()获得错误:

代码语言:javascript
复制
there is no proper conversion function from "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>" to "const gchar *"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-13 19:35:58

gst_parse_launchconst gchar*作为第一个参数:

代码语言:javascript
复制
GstElement* gst_parse_launch (const gchar* pipeline_description, GError** error)

但是,你提供的,

代码语言:javascript
复制
"rtspsrc protocols=tcp location="+ URL_RTSP + 
" latency=300 ! decodebin3 ! autovideosink"

结果为std::string。我建议先创建std::string,然后使用c_str()成员函数传递const char*

代码语言:javascript
复制
std::string tmp =
    "rtspsrc protocols=tcp location=" + URL_RTSP +
    " latency=300 ! decodebin3 ! autovideosink";

pipeline = gst_parse_launch(tmp.c_str(), nullptr);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73708226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档