c++ - gst_parse_launch 没有从字符串到 gchar 的正确转换函数

标签 c++ gstreamer gstreamer-1.0 gst-launch gst-launch-1.0

我有一个简单的 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/

相关文章:

c++ - Boost phoenix 或 lambda 库问题:从 std::vector 中删除元素

c - Gstreamer-mp3 上的持续时间查询错误

audio - 使用gstreamer播放2个剪辑,但将每个音频定向到不同的音频 channel

GStreamer Pipeline,带有 udpsrc 显示并保存到文件

c++ - 3 * 1000000000 作为int溢出,但是变量是long long。为什么?

c++ - 是否可以在 C++ 中创建一个符合开放/封闭原则的工厂?

c++ - 如何实现 bool 表达式来查找链表中的重复项?

c++ - 在 Windows 上使用 cmake 编译 gstreamer 应用程序

python - 包括 CMU pocketsphinx gstreamer 的语法

gstreamer - h264解析: broken/invalid nal Type