Reconnecting a disrupted RTSP stream

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) GPU
• DeepStream Version Deepstream 6.2
• Issue Type( questions, new requirements, bugs) question
• Language Python

(runtime source add and delete)
whenever RTSP stream get disrupted I get EOS signal, and later if the stream gets online i get these error and warning messages:

Warning: gst-resource-error-quark: Could not read from resource. (9):: gstrtspsrc.c(5624): gst_rtspsrc_loop_udp (): /GstPipeline:pipeline0/GstURIDecodeBin:source-bin-02/GstRTSPSrc:source:
The server closed the connection.

Error: gst-resource-error-quark: Could not open resource for reading and writing. (7):: gstrtspsrc.c(5692): gst_rtspsrc_loop_udp (): /GstPipeline:pipeline0/GstURIDecodeBin:source-bin-02/GstRTSPSrc:source:
Could not connect to server. (Generic error)

Error: gst-stream-error-quark: Internal data stream error. (1):: gstrtspsrc.c(6057): gst_rtspsrc_loop (): /GstPipeline:pipeline0/GstURIDecodeBin:source-bin-02/GstRTSPSrc:source:
streaming stopped, reason error (-5)

and the state of the bin is as follows :

(<enum GST_STATE_CHANGE_FAILURE of type Gst.StateChangeReturn>, state=<enum GST_STATE_PLAYING of type Gst.State>, pending=<enum GST_STATE_VOID_PENDING of type Gst.State>)

right now, when i get a Could not connect to server error , i change the state to null, unlink from streammux and then remove it from pipeline. then again add the source to the pipeline, connect to the streammux and set the state to play.

Is there a better way to do this?

thanks

nvurisrcbin has RTSP reconnection functionality. please refer to this topic.

but its not working as expected, if i enter an invalid uri, it tries to reconnect (log messages), bt it doesn’t read any frames when i feed in valid uri

how did you test? could you provide a gst-launch command to reproduce this issue?

how to read frames from a valid uri?

running this command gives me a window with black screen (the provide RTSP is a valid url)
gst-launch-1.0 -v nvurisrcbin uri=rtsp://admin:123456@192.168.99.93 rtsp-reconnect-interval=5 ! nveglglessink

i have connected a prode to nvdsosd, for debug purpose i am printing the stream ID, thereby i know if frames are passing through the pipeline

adding a snip of code here

 while l_frame is not None:

            logger.debug("Counter value:", temp_counter)
            temp_counter += 1
            try:
                frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
            except StopIteration:
                logger.error("debug1------------------------------->at the except ")
                continue
            try:
            
                    
                source_id = frame_meta.source_id
                print(source_id, "debug-----")

duplicate with this topic.

@fanzh i tried nvurisrcbin , but it didn’t work for, can you suggest a solution if i am using uridecodebin

  1. as you know, uridecodebin has no reconnection functionality. please refer to How to use this “gst_element_send_nvevent_new_stream_reset” to reconnect rtsp stream in python
    the C rtsp-reconnect mechanism can works fine, currently you might port it to python version.

  2. I have tested this commandline. it works fine after the rtsp source became unacessible then recovered. the user in this topic also confirmed.
    gst-launch-1.0 -v nvurisrcbin uri=rtsp://127.0.0.1:8554/test rtsp-reconnect-interval=5 ! nv3dsink

i went through forum and saw users confirming it, but for some reason it is not working for me, in my case it tries to reconnect when an invalid uri is provided, bt doesn’t work if a valid uri is provided

the rtsp url in the below command is invalid

gst-launch-1.0 -v nvurisrcbin uri=rtsp://192.168.99.20:8554/test rtsp-reconnect-interval=5 ! nveglglessink

corresponding logs are

setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Got context from element 'eglglessink0': gst.egl.EGLDisplay=context, display=(GstEGLDisplay)NULL;
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.99.20:8554/test
WARNING: from element /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0/GstRTSPSrc:src: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(7893): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0/GstRTSPSrc:src:
Failed to connect. (Generic error)
Progress: (open) Open failed
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Redistribute latency...
Progress: (request) Sending PLAY request
Progress: (request) PLAY failed
Resetting source rtsp://192.168.99.20:8554/test
WARNING: from element /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0: No data from source rtsp://192.168.99.20:8554/test since last 5 sec. Trying reconnection
Additional debug info:
gstdsnvurisrcbin.cpp(1253): watch_source_status (): /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0
Progress: (request) Sending PAUSE request
Progress: (close) Closing Stream
Progress: (request) PAUSE canceled
Progress: (close) Closed Stream
Progress: (open) Opening Stream
Progress: (open) Open canceled
Progress: (request) Sending PLAY request
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.99.20:8554/test
WARNING: from element /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0/GstRTSPSrc:src: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(7893): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0/GstRTSPSrc:src:
Failed to connect. (Generic error)
Progress: (open) Open failed
Progress: (request) PLAY failed
Resetting source rtsp://192.168.99.20:8554/test
WARNING: from element /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0: No data from source rtsp://192.168.99.20:8554/test since last 5 sec. Trying reconnection
Additional debug info:
gstdsnvurisrcbin.cpp(1253): watch_source_status (): /GstPipeline:pipeline0/GstDsNvUriSrcBin:dsnvurisrcbin0
Progress: (request) Sending PAUSE request
Progress: (close) Closing Stream
Progress: (request) PAUSE canceled
Progress: (close) Closed Stream
Progress: (open) Opening Stream
Progress: (open) Open canceled
Progress: (request) Sending PLAY request
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.99.20:8554/test
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:07.817890449
Setting pipeline to NULL ...
Freeing pipeline ...

thanks for responding to my query

sorry for misreading the words “valid”. the current issue is “gst-launch-1.0 -v nvurisrcbin uri=rtsp://admin:123456@192.168.99.93 rtsp-reconnect-interval=5 ! nveglglessink” can’t work when the url is valid.
duplicate with this topic, which I have replied. let’s focus on the topic new relied. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.