gst-rtsp-server transmit rtsp stream

Hello everyone!
I want to transmit rtsp stream with gst-rtsp-server(gst-rtsp-server-1.8.1),for example an XXX.mp4 video file.

/**
*Author:	Yingpeng Chen
*Date:		2017/05/24
**/

//以下为rtsp的服务器A
#include <gst/gst.h>  
#include <gst/rtsp-server/rtsp-server.h>
#include <gst/rtsp-server/rtsp-session-pool.h> 

static gboolean timeout (GstRTSPServer * server)
{
	GstRTSPSessionPool *pool;
 
   	pool = gst_rtsp_server_get_session_pool (server);
    gst_rtsp_session_pool_cleanup (pool);
    g_object_unref (pool);
 
    return TRUE;
}
 
 
int main (int argc, char *argv[])
{
    GMainLoop *loop;
    GstRTSPServer *server;
    GstRTSPMountPoints *mounts;
    //GstRTSPMediaFactory *factory;
    GstRTSPMediaFactory *factory1;
    GstRTSPSessionPool *session;
     
    gst_init (&argc, &argv);

   	loop = g_main_loop_new (NULL, FALSE);
   
    session = gst_rtsp_session_pool_new();
    gst_rtsp_session_pool_set_max_sessions  (session, 255);
    /* 创建服务器实例 */
    server = gst_rtsp_server_new ();
 
    /* 获取服务器的rtsp流的管理器*/
    mounts = gst_rtsp_server_get_mount_points (server);
 
    /* 创建两个rtsp的流管理器,设置流的源*/
    //factory = gst_rtsp_media_factory_new ();
    factory1 = gst_rtsp_media_factory_new ();
    //gst_rtsp_media_factory_set_launch (factory,
    //   "( videotestsrc is-live=1 ! x264enc ! rtph264pay name=pay0 pt=96 )");
  
    gst_rtsp_media_factory_set_launch (factory1,
		"( "  
       	"filesrc location=/home/nvidia/Videos/iptest.mp4 ! qtdemux name=d "
       	"d. ! queue ! rtph264pay pt=96 name=pay0 "
       	"d. ! queue ! rtpmp4apay pt=97 name=pay1 " ")");
   
   	//gst_rtsp_media_factory_set_shared (factory, TRUE);
   	gst_rtsp_media_factory_set_shared (factory1, TRUE);

   	/*绑定流的地址,并加入流管理器中*/
   	//gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
    gst_rtsp_mount_points_add_factory (mounts, "/test1", factory1);
   
   	g_object_unref (mounts);
 
   	gst_rtsp_server_attach (server, NULL); 
     
   	g_timeout_add_seconds (2, (GSourceFunc) timeout, server);
 
   	//g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
   	g_print ("stream ready at rtsp://127.0.0.1:8554/test1\n");
   	g_main_loop_run (loop);
 
   	return 0;
}

receiver terminal on Ubuntu14.04

gst-launch-1.0 -v rtspsrc location=rtsp://192.168.0.106/test1 ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink

result

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.0.106/test1
ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(6183): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0:
Failed to connect. (Generic error)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

How to solve it? Thank you in advance!

hello Holy_chen,

had you already verified running the RTSP server and receive the streaming on ubuntu desktop works?
thanks

Hi,JerryChang,
No work!I try many times in different ways,but the result remains the same!Could you give me some suggestions?

hello Holy_chen,

could you enable gstreamer debug flag both at the server/client side to gather more messages.

--gst-debug=2

thanks

Hi,Jerry
sender teiminal on jetson-tx2

nvidia@tegra-ubuntu:~/Projects/gstRTSPServer/videoFileTransmit$ ./gstRTSPServer stream ready at rtsp://127.0.0.1:8554/test1

** (gstRTSPServer:7038): CRITICAL **: could not parse launch syntax (( filesrc location=/home/nvidia/Videos/iptest.mp4 ! omxh264enc ! rtph264pay name=pay0 pt=96)): could not set property "pt" in element "pay0" to "96)"

** (gstRTSPServer:7038): CRITICAL **: could not create element
receiver terminal on Ubuntu14.04
chen@chen-All-Series:~$ GST_DEBUG=2 gst-launch-1.0 rtspsrc location=rtsp://192.168.0.106:8554/test1
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.0.106:8554/test1
Progress: (open) Retrieving server options
Progress: (open) Retrieving media info
0:00:00.027851298  3922      0x109da80 WARN                 rtspsrc gstrtspsrc.c:5104:gst_rtspsrc_send:<rtspsrc0> error: Not Found
0:00:00.027922810  3922      0x109da80 WARN                 rtspsrc gstrtspsrc.c:6262:gst_rtspsrc_open:<rtspsrc0> can't get sdp
ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Resource not found.
0:00:00.027944348  3922      0x109da80 WARN                 rtspsrc gstrtspsrc.c:4560:gst_rtspsrc_loop:<rtspsrc0> we are not connected
Additional debug info:
gstrtspsrc.c(5104): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0:
Not Found
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

Thanks!

rtph264pay doesn’t document “pt” as a property:
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-rtph264pay.html

As pointed out by @snarky, you may change :

rtph264pay name=pay0 pt=96

to

rtph264pay name=pay0 payload=96

Hi,Honey,
I have changed my code as followed you said,but the result appears new error.

chen@chen-All-Series:~$ GST_DEBUG=2 gst-launch-1.0 -v rtspsrc location=rtsp://192.168.0.106/test1 ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.0.106/test1
0:00:00.040312855  3244      0x140ef20 ERROR                default gstrtspconnection.c:751:gst_rtsp_connection_connect: failed to connect: Could not connect to 192.168.0.106: Connection refused
0:00:00.040348630  3244      0x140ef20 ERROR                rtspsrc gstrtspsrc.c:3716:gst_rtsp_conninfo_connect:<rtspsrc0> Could not connect to server. (Generic error)
0:00:00.040362669  3244      0x140ef20 WARN                 rtspsrc gstrtspsrc.c:6183:gst_rtspsrc_retrieve_sdp:<rtspsrc0> error: Failed to connect. (Generic error)
0:00:00.040399322  3244      0x140ef20 WARN                 rtspsrc gstrtspsrc.c:6262:gst_rtspsrc_open:<rtspsrc0> can't get sdp
0:00:00.040417947  3244      0x140ef20 WARN                 rtspsrc gstrtspsrc.c:4560:gst_rtspsrc_loop:<rtspsrc0> we are not connected
ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(6183): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0:
Failed to connect. (Generic error)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

Could you give me some suggestions? Thank you in advance!

The error message seems pretty on target here:

What part of that is unclear?

Additional note on the “Connection refused”…this probably means that no software is listening at 192.168.0.106 for the protocol used in rtsp. That particular message would not be from a route failing due to a firewall or router issue…whatever your software is that is supposed to listen to that address/port/protocol combination is not running (probably port 80).

So what is your suggestion to troubleshooting this?

  • look at the ports?
  • change the “test-launch” arguments to … (suggestion)?

I have the same issue with mine and the ports are LISTENING.

Here is my setup:

nvidia@jetson2:~/Downloads/gst-rtsp-server-1.14.5/examples$ ./test-video "( filesrc location=/home/nvidia/streamer/Vehicle.Target.Sample_EO.ts ! videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )"

stream ready at rtsp://127.0.0.1:8554/test

nvidia@jetson2:~/Downloads/gst-rtsp-server-1.14.5/examples$ gst-launch-1.0 -e rtspsrc location=rtsp://127.0.0.1:8554/test ! tee name=t ! queue ! video/x-h264,stream-format=byte-stream,alignment=nal ! udpsink host=172.22.0.1 port=50007 auto-multicast=true t. ! queue ! tsdemux ! fakesink sync=true

The suggested changes for pt=96 to payload=96 also failed

nvidia@jetson2:~/Downloads/gst-rtsp-server-1.14.5/examples$ ./test-video "( filesrc location=/home/nvidia/streamer/Vehicle.Target.Sample_EO.ts ! videotestsrc ! x264enc ! rtph264pay name=pay0 payload=96 )"

failed to attach the server

Your pipeline in server is wrong, so test-launch (I assume test-video is just renaming test-launch) won’t start.
There may not be meaningful error messages, so first elaborate your pipeline with gst-launch-1.0 using appsink or fakesink, and when it works just remove that sink for test-launch (it will add appsink).

You pipeline is wrong because you have videotestsrc after filesrc. You would have to choose which source you want to use, and for filesrc demux and/or decode/re-encode further depending on what is in this file.

Not sure if x264enc outputs parsed H264. If not, you would add h264parse between h264encoder and rtph264pay. You may also try specifying stream-format=byte-stream into caps.

My advice was weird. rtph264pay option is pt. payload would be used in caps and mostly on receiver side…anyway 96 is the default, and if you’re only streaming one h264 video it should be ok.

1 Like