Solved Set gstreamer rtsp latency=0
-
I want to play H.264 videos(rtsp protocol) with QMediaPlayer(Qt5.6.2 and Gstreamer1.8.1). It works but there is some latency about 2s.
When I play the rtsp video with gst-launch, I use the command that like```
//gst-launch-1.0 -v rtspsrc latency=0 location="rtsp://xx:554"So. How could I add such parameter to QMediaPlayer? Maybe should I add something to the component QtMultiMedia?
-
@SGaist Thanks. When I use gst-launch-1.0 to play the video, I add the parameter "latency=0". and it plays almost real-time. So I want add such parameter to QMediaPlayer. I search the code of QtMultiMedia, and find that the file qgstreamerplayersession.cpp is about player. There is some code about "rtsp". I think the following code is important:
} else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstRTSPSrc") == 0) { // line 1578 //rtspsrc acts like a live source and will therefore only generate data in the PLAYING state. self->m_sourceType = RTSPSrc; self->m_isLiveSource = true; g_object_set(G_OBJECT(source), "buffer-mode", 1, NULL); // line 1583 g_object_set(G_OBJECT(source), "latency", 0, NULL); // I add this line.Sorry to make a mistake above that I wrote wrong line number. It is not line 1586 g_object_set(G_OBJECT(source), "threads", 4, NULL); // I add this line. I want to make QMediaPlayer work multi-thread.
I am sure that the code will execute because when I add "g_object_set(G_OBJECT(source), "threads", 4, NULL); " , there will be warning in the console that rtspsrc does not have property "threads".
-
Hi and welcome to devnet,
AFAIK, you need to modify the QtMultimedia GStreamer backend for that to happen.
-
internet/IP/RTSP/UDP multimedia is not designed for zero latency. You are going to be dissappointed. There is ALWAYS inherent latency when streaming video over IP networks. In tightly controlled point-to-point configuration you might get it down to 100-150ms average latency but that's about as good as it gets.
-
@SGaist Thanks. I add "g_object_set(G_OBJECT(source), "latency", 0, NULL);" on line 1586 to the file qgstreamerplayersession.cpp, but it does not work.
-
@dahan said in Set gstreamer rtsp latency=0:
but it does not work.
You know that with that high level of details it's mostly Crystal Ball debugging ?
-
@SGaist emm, I am so new with QtMultiMedia and Gstreamer that I just try.
-
That has nothing to do with Qt or GStreamer. When asking a question, you should always give as much details as you can about what you tried, what you excepted, what you actually get, etc.
For example here: did you check if the methods you call have return values ? If so, did you check what they mean ?
-
@SGaist Thanks. When I use gst-launch-1.0 to play the video, I add the parameter "latency=0". and it plays almost real-time. So I want add such parameter to QMediaPlayer. I search the code of QtMultiMedia, and find that the file qgstreamerplayersession.cpp is about player. There is some code about "rtsp". I think the following code is important:
} else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstRTSPSrc") == 0) { // line 1578 //rtspsrc acts like a live source and will therefore only generate data in the PLAYING state. self->m_sourceType = RTSPSrc; self->m_isLiveSource = true; g_object_set(G_OBJECT(source), "buffer-mode", 1, NULL); // line 1583 g_object_set(G_OBJECT(source), "latency", 0, NULL); // I add this line.Sorry to make a mistake above that I wrote wrong line number. It is not line 1586 g_object_set(G_OBJECT(source), "threads", 4, NULL); // I add this line. I want to make QMediaPlayer work multi-thread.
I am sure that the code will execute because when I add "g_object_set(G_OBJECT(source), "threads", 4, NULL); " , there will be warning in the console that rtspsrc does not have property "threads".
-
@dahan said in Set gstreamer rtsp latency=0:
g_object_get
I would check with a
g_object_get
call to see if the value was indeed set. -
@SGaist Thanks a lot. I do check with g_object_get, and the property latency is setted successfully.
I find that QtMultiMedia use gstreamer plugin playbin. I play the video with command gst-launch-1.0 playbin latency=10 uri=rtsp://xx:554 . On my machine it does not play as good as gst-launch-1.0 rtspsrc latency=10 location=rtsp://xx:554. So I think it's problem of the gstreamer plugin "playbin". I will try replace playbin with rtspsrc in QtMultiMedia.