为什么 gstreamer 会给出 rtsp Invalid URI 错误?
Why gstreamer gives rtsp Invalid URI error?
我一直在尝试用 gstreamer 编写一个 rtsp 播放器。我正在使用 Windows 10 个
我想要这个播放器支持反向播放。当我开始编写代码时,gstreamer 版本是 1.14.5。但是在这个版本中,我发现 rtspsrc 不支持反向播放,这个功能在 1.15.2 版本中出现。当我编写代码时,所有功能(开始、暂停、停止、快进)都在工作,除了反向播放。
但是,当我切换到版本 1.15.2 时,我开始收到“无效 URI”错误,甚至没有尝试发送请求(我用 wireshark 进行了检查)。我检查过的所有地方都说要关闭代理,但我从 Windows 设置中关闭了代理,但它仍然不起作用。
初始化 gstreamer。
IGSPlayer::GSPlayer_ERROR Player::initialize_player(int argc, char* argv[]) {
gst_init(&argc,&argv);
GstElement *rtspsrc_element, *rtph264depay_element, *h264parse_element, *avdec_h264_element, *videoconvert_element, *glimagesink_element;
rtspsrc_element = gst_element_factory_make("rtspsrc", "rtspsrc");
if (!rtspsrc_element) {
std::cout << "Unable to create rtspsrc!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_RTSPSRC;
}
rtph264depay_element = gst_element_factory_make("rtph264depay", "rtph264depay");
if (!rtph264depay_element) {
std::cout << "Unable to create rtph264depay_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_DEPAY;
}
h264parse_element = gst_element_factory_make("h264parse", "h264parse");
if (!h264parse_element) {
std::cout << "Unable to create h264parse_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_PARSE;
}
avdec_h264_element = gst_element_factory_make("avdec_h264", "avdec_h264");
if (!avdec_h264_element) {
std::cout << "Unable to create avdec_h264_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_AVDEC;
}
videoconvert_element = gst_element_factory_make("videoconvert", "videoconvert");
if (!videoconvert_element) {
std::cout << "Unable to create vidoeconvert_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_CONVERT;
}
glimagesink_element = gst_element_factory_make("glimagesink", "glimagesink");
if (!glimagesink_element) {
std::cout << "Unable to create glimagesink_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_SINK;
}
setLoop(g_main_loop_new(NULL, FALSE));
g_object_set(rtspsrc_element, "location", get_rtsp_uri().c_str(), NULL);
g_object_set(rtspsrc_element, "latency", 0, NULL);
setVideoSink(glimagesink_element);
setPipeline(gst_pipeline_new("rtsp-pipeline"));
if (!getPipeline()) {
std::cerr << "pipeline could not be created!" << std::endl;
return IGSPlayer::CREATE_PIPELINE_ERROR;
}
setBus(gst_pipeline_get_bus(GST_PIPELINE(getPipeline())));
gst_bus_add_watch(getBus(), bus_call, this);
gst_object_unref(getBus());
gst_bin_add_many(GST_BIN(getPipeline()), rtspsrc_element, rtph264depay_element, NULL);
g_signal_connect(rtspsrc_element, "pad-added", G_CALLBACK(new_rtspsrc_pad), rtph264depay_element);
gst_bin_add_many(GST_BIN(getPipeline()), h264parse_element, NULL);
if (!gst_element_link(rtph264depay_element, h264parse_element)) {
std::cout << "rtph264depay -> h264parse not be linked!" << std::endl;
gst_object_unref(getPipeline());
return IGSPlayer::LINKED_ERROR;
}
gst_bin_add_many(GST_BIN(getPipeline()), avdec_h264_element, videoconvert_element, glimagesink_element, NULL);
/* link the elements together */
if (!gst_element_link_many(h264parse_element, avdec_h264_element, videoconvert_element, glimagesink_element, NULL)) {
std::cerr << "Elements could not be linked!" << std::endl;
gst_object_unref(getPipeline());
return IGSPlayer::LINKED_ERROR;
}
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(glimagesink_element), (guintptr) get_window_id());
setEndOfStream(false);
return IGSPlayer::SUCCESS;}
然后玩。
IGSPlayer::GSPlayer_ERROR Player::play_stream() {
GstStateChangeReturn ret = gst_element_set_state(getPipeline(), GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
gst_element_set_state(getPipeline(), GST_STATE_NULL);
gst_object_unref(GST_OBJECT(getPipeline()));
return IGSPlayer::GSPlayer_ERROR::STATE_CHANGE_ERROR;
}
setPlaying(TRUE);
setRate(1.0);
g_main_loop_run(getLoop());
return IGSPlayer::SUCCESS;}
我还尝试使用 windows powershell 和 gst-launch-1.0,但它也不起作用。我很想听听为什么这不起作用的任何想法。
好的,我找到了解决方案。我在 windows 上使用 non-English 语言选项。当我将语言选项设置为英文时,问题就解决了。
我一直在尝试用 gstreamer 编写一个 rtsp 播放器。我正在使用 Windows 10 个
我想要这个播放器支持反向播放。当我开始编写代码时,gstreamer 版本是 1.14.5。但是在这个版本中,我发现 rtspsrc 不支持反向播放,这个功能在 1.15.2 版本中出现。当我编写代码时,所有功能(开始、暂停、停止、快进)都在工作,除了反向播放。
但是,当我切换到版本 1.15.2 时,我开始收到“无效 URI”错误,甚至没有尝试发送请求(我用 wireshark 进行了检查)。我检查过的所有地方都说要关闭代理,但我从 Windows 设置中关闭了代理,但它仍然不起作用。
初始化 gstreamer。
IGSPlayer::GSPlayer_ERROR Player::initialize_player(int argc, char* argv[]) {
gst_init(&argc,&argv);
GstElement *rtspsrc_element, *rtph264depay_element, *h264parse_element, *avdec_h264_element, *videoconvert_element, *glimagesink_element;
rtspsrc_element = gst_element_factory_make("rtspsrc", "rtspsrc");
if (!rtspsrc_element) {
std::cout << "Unable to create rtspsrc!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_RTSPSRC;
}
rtph264depay_element = gst_element_factory_make("rtph264depay", "rtph264depay");
if (!rtph264depay_element) {
std::cout << "Unable to create rtph264depay_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_DEPAY;
}
h264parse_element = gst_element_factory_make("h264parse", "h264parse");
if (!h264parse_element) {
std::cout << "Unable to create h264parse_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_PARSE;
}
avdec_h264_element = gst_element_factory_make("avdec_h264", "avdec_h264");
if (!avdec_h264_element) {
std::cout << "Unable to create avdec_h264_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_AVDEC;
}
videoconvert_element = gst_element_factory_make("videoconvert", "videoconvert");
if (!videoconvert_element) {
std::cout << "Unable to create vidoeconvert_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_CONVERT;
}
glimagesink_element = gst_element_factory_make("glimagesink", "glimagesink");
if (!glimagesink_element) {
std::cout << "Unable to create glimagesink_element!" << std::endl;
return IGSPlayer::CREATE_ELEMENT_ERROR_SINK;
}
setLoop(g_main_loop_new(NULL, FALSE));
g_object_set(rtspsrc_element, "location", get_rtsp_uri().c_str(), NULL);
g_object_set(rtspsrc_element, "latency", 0, NULL);
setVideoSink(glimagesink_element);
setPipeline(gst_pipeline_new("rtsp-pipeline"));
if (!getPipeline()) {
std::cerr << "pipeline could not be created!" << std::endl;
return IGSPlayer::CREATE_PIPELINE_ERROR;
}
setBus(gst_pipeline_get_bus(GST_PIPELINE(getPipeline())));
gst_bus_add_watch(getBus(), bus_call, this);
gst_object_unref(getBus());
gst_bin_add_many(GST_BIN(getPipeline()), rtspsrc_element, rtph264depay_element, NULL);
g_signal_connect(rtspsrc_element, "pad-added", G_CALLBACK(new_rtspsrc_pad), rtph264depay_element);
gst_bin_add_many(GST_BIN(getPipeline()), h264parse_element, NULL);
if (!gst_element_link(rtph264depay_element, h264parse_element)) {
std::cout << "rtph264depay -> h264parse not be linked!" << std::endl;
gst_object_unref(getPipeline());
return IGSPlayer::LINKED_ERROR;
}
gst_bin_add_many(GST_BIN(getPipeline()), avdec_h264_element, videoconvert_element, glimagesink_element, NULL);
/* link the elements together */
if (!gst_element_link_many(h264parse_element, avdec_h264_element, videoconvert_element, glimagesink_element, NULL)) {
std::cerr << "Elements could not be linked!" << std::endl;
gst_object_unref(getPipeline());
return IGSPlayer::LINKED_ERROR;
}
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(glimagesink_element), (guintptr) get_window_id());
setEndOfStream(false);
return IGSPlayer::SUCCESS;}
然后玩。
IGSPlayer::GSPlayer_ERROR Player::play_stream() {
GstStateChangeReturn ret = gst_element_set_state(getPipeline(), GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
gst_element_set_state(getPipeline(), GST_STATE_NULL);
gst_object_unref(GST_OBJECT(getPipeline()));
return IGSPlayer::GSPlayer_ERROR::STATE_CHANGE_ERROR;
}
setPlaying(TRUE);
setRate(1.0);
g_main_loop_run(getLoop());
return IGSPlayer::SUCCESS;}
我还尝试使用 windows powershell 和 gst-launch-1.0,但它也不起作用。我很想听听为什么这不起作用的任何想法。
好的,我找到了解决方案。我在 windows 上使用 non-English 语言选项。当我将语言选项设置为英文时,问题就解决了。