ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.74k stars 5.28k forks source link

How to implement reconnection after an RTSP stream capture does not report an error? #3972

Open djkcyl opened 4 months ago

djkcyl commented 4 months ago

Describe the bug When an RTSP stream is interrupted due to network issues or abnormalities in the device pulling the stream, it cannot reconnect without restarting the SRS to restore functionality.

Version SRS/6.0.113

To Reproduce Steps to reproduce the behavior:

  1. Initiate RTSP stream pulling.
  2. Restart the streaming source device (Hikvision camera).
  3. SRS fails to re-establish connection.

Config

root@a60:~# cat srs/trunk/conf/aunly.conf 

listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;

http_server {
    enabled on;
    listen 8180;
    dir ./objs/nginx/html;
}

http_api {
    enabled on;
    listen 8180;
}

stats {
    network 0;
}

rtc_server {
    enabled on;
    listen 8000; # UDP port
    candidate 1.1.1.1;
    tcp {
        enabled on;
        listen 8000;
    }
    protocol all;
}

vhost __defaultVhost__ {
    # tcp_nodelay on;
    # min_latency on;
    # hls {
    #     enabled         off;
    #     hls_fragment    2;
    #     hls_window      5;
    # }
    rtc {
        enabled on;
        rtmp_to_rtc on;
        rtc_to_rtmp on;
        keep_bframe off;
    }
    http_remux {
        enabled on;
        mount [vhost]/[app]/[stream].flv;
        # mount [vhost]/[app]/[stream].ts;
    }

    ingest {
        enabled      on;
        input {
            type    stream;
            url     rtsp://admin:admin@10.0.0.100:8554/Streaming/Channels/101;
        }
        ffmpeg      ./objs/ffmpeg/bin/ffmpeg;
        engine {
            enabled          on;
            perfile {
                rtsp_transport tcp;
            }
            vcodec copy;
            acodec copy;
            output          rtmp://127.0.0.1:[port]/live/live_1?vhost=[vhost];
        }
    }
}

TRANS_BY_GPT4

winlinvip commented 3 months ago

Actually, this bug is caused by FFmpeg failing to reconnect when the RTSP stream is blocked while being pulled. Therefore, you need to modify SRS to detect this issue and restart FFmpeg when the RTSP stream pulling is blocked. We have implemented this feature in the SRS stack camera streaming. We monitor FFmpeg's log, check the time, and the speed rate. If any exceptions are detected, we restart the FFmpeg process. Thus, you can simply switch to using the SRS stack instead. We have already done this.

If you insist on using the SRS media server, you will need to patch the ingest feature, and we would be happy to accept such a patch. However, we currently do not have the time to do this ourselves, especially since we have already implemented it in the SRS stack. Therefore, this feature in SRS is not a high priority for us.