Tutorial: A working example for rtsp output in c

• DeepStream Version 6.x
This sample is modified from deepstream-test3. User can use VLC to watch this rtsp stream remotely. User should install gstreamer rtsp server first.

sudo apt-get install libgstrtspserver-1.0 libgstreamer1.0-dev

First you can check you environment is ready for rtsp streaming. Copy the rtsp server example here and compile this file.

gcc test-launch.c -o test-launch $(pkg-config --cflags --libs gstreamer-1.0 gstreamer-rtsp-server-1.0)

Then start the test rtsp server. Note this command did not use nvvidconv and nvv4l2h264enc element like the reference post because it will cause a broken pipeline without any error in dGPU environment.

./test-launch "videotestsrc is-live=1 ! videoconvert  ! x264enc ! h264parse ! rtph264pay name=pay0 pt=96"

Then you can start a client using VLC connect to rtsp://<host ip>:8554/test. If it fail to connect, start a client in the same computer in another termal by

gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! fakesink

If success, the program will keep running without error.

After check the environment is OK, you can build the modified deepstream-test3 code in attachment. After compile the code, change the source-list: in dstest3_config.yml. Run the app with command

./deepstream-test3-app dstest3_config.yml

and use VLC connect to rtsp://<host ip>:8554/ds-test then you can see the stream.

This example code copy functions start_rtsp_streaming, client_filter, destroy_sink_bin from /opt/nvidia/deepstream/deepstream/sources/apps/apps-common/src/deepstream_sink_bin.c
The main idea is deepstream pipeline stream go to udp sink on 5400 port, and then we start a rtsp server using start_rtsp_streaming. This rtsp server receive the udp as source and turn it into rtsp stream.

Reference:

deepstream-test3-rtsp.zip (14.8 KB)

1 Like

Thanks for sharing!

Thanks for sharing, but it does not work on deepstream 6.1.1

Hi, could you provide the error message?

Sure.

After compiling code by
gcc test-launch.c -o test-launch $(pkg-config --cflags --libs gstreamer-1.0 gstreamer-rtsp-server-1.0)

Then by running
./test-launch "videotestsrc is-live=1 ! videoconvert ! x264enc ! h264parse ! rtph264pay name=pay0 pt=96"

I got these message:
stream ready at rtsp://127.0.0.1:8554/test

Now by running this command in another terminal
gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! fakesink

I got these message:


Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://127.0.0.1:8554/test
Progress: (open) Retrieving server options
Progress: (open) Retrieving media info
ERROR: from element /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source: Unhandled error
Additional debug info:
gstrtspsrc.c(6585): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source:
Service Unavailable (503)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

And by opening stream in VLC , I got this error:


Your input can't be opened:

VLC is unable to open the MRL 'rtsp://MY_IP:8554/test'. Check the log for details.

Hi, Could you try to modify the test-launch.c code line 84 from 127.0.0.1 to 0.0.0.0. I think this is the reason.

But this line is just a print not anything more.

g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port);

And your attached file is corrupted and can not be opened.

My bad, I did not look carefully. How about you try the command in your

remote server ? Could gstreamer get stream in the same computer?

gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! fakesink

Please try 7-zip to unzip this file

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://127.0.0.1:8554/test
Progress: (open) Retrieving server options
Progress: (open) Retrieving media info
ERROR: from element /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source: Unhandled error
Additional debug info:
gstrtspsrc.c(6585): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source:
Service Unavailable (503)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...
nvs@mehrabad-airport:

After building your project and by running it I got these :

Now playing : rtsp://MY_IP/live.sdp

(deepstream-test6-app:29765): GLib-GObject-CRITICAL **: 13:37:16.801: g_object_set: assertion 'G_IS_OBJECT (object)' failed

(deepstream-test6-app:29765): GLib-GObject-CRITICAL **: 13:37:16.801: g_object_set: assertion 'G_IS_OBJECT (object)' failed

(deepstream-test6-app:29765): GLib-GObject-CRITICAL **: 13:37:16.801: g_object_set: assertion 'G_IS_OBJECT (object)' failed
[ERROR] Passed element is not nveglglessink
Using file: dstest6_config.yml
WARNING: [TRT]: Using an engine plan file across different models of devices is not recommended and is likely to affect performance or even cause errors.
0:00:01.048592937 29765 0x557b0b94ea10 INFO                 nvinfer gstnvinfer.cpp:646:gst_nvinfer_logger:<primary-nvinference-engine> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::deserializeEngineAndBackend() <nvdsinfer_context_impl.cpp:1909> [UID = 1]: deserialized trt engine from :/opt/nvidia/deepstream/deepstream-6.1/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
INFO: ../nvdsinfer/nvdsinfer_model_builder.cpp:610 [Implicit Engine Info]: layers num: 3
0   INPUT  kFLOAT input_1         3x368x640       
1   OUTPUT kFLOAT conv2d_bbox     16x23x40        
2   OUTPUT kFLOAT conv2d_cov/Sigmoid 4x23x40         

0:00:01.070749547 29765 0x557b0b94ea10 INFO                 nvinfer gstnvinfer.cpp:646:gst_nvinfer_logger:<primary-nvinference-engine> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2012> [UID = 1]: Use deserialized engine model: /opt/nvidia/deepstream/deepstream-6.1/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
0:00:01.071685219 29765 0x557b0b94ea10 INFO                 nvinfer gstnvinfer_impl.cpp:328:notifyLoadModelStatus:<primary-nvinference-engine> [UID 1]: Load new model:dstest6_pgie_config.yml sucessfully
Decodebin child added: source

 *** DeepStream: Launched RTSP Streaming at rtsp://localhost:8554/ds-test ***

Running...




ERROR from element source: Could not open resource for reading and writing.
Error details: gstrtspsrc.c(7893): gst_rtspsrc_retrieve_sdp (): /GstPipeline:dstest3-pipeline/GstBin:source-bin-00/GstURIDecodeBin:uri-decode-bin/GstRTSPSrc:source:
Failed to connect. (Generic error)
Returned, stopping playback
Deleting pipeline

And it cant be played in VLC.

Hi, I see dstest6_config.yml in you log, could you provide the content?

I just renamed dstest3_config to dstest6_config. As you know there is a directory in the deepstream sample with name deepstream-test3.

OK, So we first check if you can open the RTSP stream in the same computer. Are you sure you run the command
gst-launch-1.0 uridecodebin uri=rtsp://127.0.0.1:8554/test ! fakesink
and ./test-launch "videotestsrc is-live=1 ! videoconvert ! x264enc ! h264parse ! rtph264pay name=pay0 pt=96"
in the same computer (the remote server)?

If you do, it mean you can not watch the stream even in the same computer. Did you have fire wall on this computer?(please check the ufw status, disable the firewall temporarily)

I try this one and it does not work.

I run both commands on the same computer and they don’t work.

I check ufw and it is inactive.

It’s necessary to say that deepstream-test1-rtsp-out works properly. This example has been written in python.