ossrs / srs

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

WebRTC: The DVR file becomes corrupt when the frames per second (fps) is very low. The recorded FLV video, which is streamed using WebRTC and has a frame rate of only 1 frame every 2-3 seconds, fails to play. #3122

Open ziyue7575 opened 2 years ago

ziyue7575 commented 2 years ago

The video streaming part sometimes has a frame rate of around 1 frame per 1.2 seconds, and sometimes only 1 frame is pushed every 2-3 seconds. This part, where only 1 frame is pushed every 2-3 seconds, will fail to play.

Description

Description The video stream is only pushed at a rate of 1 frame every 2-3 seconds. It can be recorded and played in real-time using WebRTC, but the recorded video fails to play. When pushed for 5 minutes, it only plays for a moment.

1. SRS Version: 4.0.212

1. SRS Log:

Attachment

1. SRS Config (Configuration):

 listen              13425;
max_connections     1000;
daemon              on;
srs_log_tank        file;

http_server {
    enabled         on;
    listen          13423;
**# Configure an empty directory to disable usage**
    dir             ./objs/nginx/html;
}

http_api {
    enabled         on;
    listen          1985;
    raw_api {
        enabled on;
        allow_reload on;
        allow_query on;
        allow_update on;
    }
}
stats {
    network         0;
}
rtc_server {
    enabled on;
    listen 13427; # UDP port
    # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#config-candidate
    # candidate $CANDIDATE;
    candidate 192.168.3.90;
}

vhost __defaultVhost__ {
    rtc {
        enabled     on;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc
        rtmp_to_rtc on;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
        rtc_to_rtmp on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    http_hooks {
        enabled on;
**on_unpublish http://cc-web-1:8090/web/srs/actionSrs; # Callback for ucare, disconnect other streams for this push**
    }
}
vhost saveVhost {
    rtc {
        enabled     on;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc
        rtmp_to_rtc on;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
        rtc_to_rtmp on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    dvr {
        enabled on;
        dvr_path /usr/local/stuff/srs/srs.oschina-4.0release/trunk/objs/nginx/html/dvrfile/saveVhost/[app]/[stream]/[timestamp].flv;
        dvr_plan segment;
**dvr_duration 3600; # 1 hour per video**
        dvr_wait_keyframe on;
        dvr_apply all;
    }
    http_hooks {
        enabled on;
**on_unpublish http://cc-web-1:8090/web/srs/actionSrs; # Callback for ucare, disconnect other streams for this publishing
        on_dvr http://cc-web-1:8090/web/srs/actionSrs; # Callback for ucare, disconnect other streams for this publishing**
    }
}

vhost test {
    rtc {
        enabled     on;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc
        rtmp_to_rtc on;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp
        rtc_to_rtmp on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].mp4;
    }
    dvr {
        enabled on;
        dvr_path /usr/local/stuff/srs/srs.oschina-4.0release/trunk/objs/nginx/html/dvrfile/test/[app]/[stream]/[timestamp].mp4;
        dvr_plan segment;
**dvr_duration 3600; # 1 hour per video**
        dvr_wait_keyframe on;
        dvr_apply all;
    }
    http_hooks {
        enabled on;
    }
}

Replay (重现)

When pushing the video, 1 frame is pushed every 2-3 seconds, and the recorded video cannot be played.

Expect (Expected Behavior)

Hope that even with such slow buffering, it can still be recorded and played back normally.

TRANS_BY_GPT3

ziyue7575 commented 2 years ago

srs_err.log log

TRANS_BY_GPT3

winlinvip commented 2 years ago

Are you using WebRTC for streaming? Is the recorded content normal? Are there any instances of fast-forwarding or slow playback?

TRANS_BY_GPT3

ziyue7575 commented 2 years ago

@winlinvip When streaming with WebRTC, it can immediately play and generate a temporary video file. However, it takes 5-6 seconds to start recording with the above configuration. I changed the configuration to the following (pli_for_rtmp 0.5;) and after streaming, it can start recording in about 0.5 seconds. However, it can only save videos with 8 frames per second, and streams with 1 frame every 3 seconds still cannot be saved.


listen 1935;
max_connections 1000;
daemon on;
srs_log_tank file;
## Disable version check
query_latest_version off;
http_server {
    enabled on;
    listen 8080;
    dir ./objs/nginx/html;
}
http_api {
    enabled on;
    listen 1985;
    raw_api {
        enabled on;
        allow_reload on;
        allow_query on;
        allow_update on;
    }
}
## WebRtc Configuration
rtc_server {
    enabled on;
    listen 18000;
    candidate *;
    api_as_candidates off;
}
vhost saveVhost {
    tcp_nodelay on;
    # Enable Low Latency Mode
    min_latency on;
    play {
        # If minimum latency is required, set it to off;
        # If fast client startup is required, set it to on.
        gop_cache off;
        # Maximum real-time queue length (in seconds).
        queue_length 10;
        # atc                     on;
        # mix_correct             on;
        mw_latency      100;
    }
     publish {
        mr off;
    }
    # Play webrtc
    rtc {
        enabled     on;
        rtmp_to_rtc on;
        rtc_to_rtmp on;
        stun_timeout 5;
        stun_strict_check on;
        nack on;
        twcc on;
         pli_for_rtmp 0.5;
    }
    # Play flv
    http_remux {
        enabled on;
        mount [vhost]/[app]/[stream].flv;
    }
    dvr {
        enabled on;
        # The address cannot use relative address, otherwise the callback address will also be a relative address, and the callback interface cannot handle it.
        dvr_path /usr/local/stuff/srs413/trunk/objs/nginx/html/dvrfile/[vhost]/[app]/[stream]/[timestamp].flv;
        dvr_plan segment;
        dvr_duration 3600; # 1 hour per video
        dvr_wait_keyframe off;
        dvr_apply all;
    }
    http_hooks {
        enabled off;
    }
}

`TRANS_BY_GPT3`
ziyue7575 commented 2 years ago

1660126459708.zip This is a recorded video that was pushed for several minutes, but after the recording was completed, it cannot be played.

TRANS_BY_GPT3

ziyue7575 commented 2 years ago

dvr setting time_jitter zero; The video can be recorded normally, but previously the webRTC streaming could be played immediately, now it takes almost 20 seconds to start playing, and the video also starts recording at this time.

TRANS_BY_GPT3