У меня есть простой код с С++, использующий gstreamer для чтения видео rtsp. Я новичок в gstreamer, мне не удалось объединить gst_parse_launch() с переменной URL_RTSP для моих ссылок 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);