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.72k stars 5.39k forks source link

HLS Playlists and Video Fragments break if RTMP upload is interrupted temporarily. #2263

Closed Baa14453 closed 3 years ago

Baa14453 commented 3 years ago

Description'

Please ensure that the markdown structure is maintained.

HLS Playlist and Fragments break if RTMP upload is interrupted temporarily.

  1. SRS version: 4.0.81
  2. The log of SRS is as follows:'

Please ensure that the markdown structure is maintained.

Pending
  1. The configuration of SRS is as follows:

Please ensure that the markdown structure is maintained.

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

vhost Vhost {
    gop_cache       off;
    queue_length    10;
    mr {
        enabled     off;
    }
    mw_latency      100;
    transcode {
        enabled     on;
        ffmpeg      /opt/ffmpeg/ffmpeg;
        engine ff {
            enabled         on;
            vfilter {
                vf scale=w=1920:h=1080:force_original_aspect_ratio=decrease;
                loglevel       debug;
            }
            vcodec          libx264;
            vbitrate        4500;
            vfps            60;
            vwidth          0;
            vheight         0;
            vthreads        4;
            vprofile        high;
            vpreset         superfast;
            vparams {
                g       120;
                tune    zerolatency;
                vlevel  4;
            }
            acodec          aac;
            abitrate        256;
            achannels       2;
            aparams {
            }
            output          rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]-HLS/[stream]_1080-60fps;
        }

        engine ff {
            enabled         on;
            vfilter {
                vf scale=w=1280:h=720:force_original_aspect_ratio=decrease;
                loglevel       quiet;
            }
            vcodec          libx264;
            vbitrate        4000;
            vfps            30;
            vwidth          0;
            vheight         0;
            vthreads        4;
            vprofile        high;
            vpreset         superfast;
            vparams {
                g       60;
                tune    zerolatency;
                vlevel  3.1;
            }
            acodec          aac;
            abitrate        256;
            achannels       2;
            aparams {
            }
            output          rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]-HLS/[stream]_720;
        }

        engine ff {
            enabled         on;
            vfilter {
                vf scale=w=640:h=360:force_original_aspect_ratio=decrease;
                loglevel       debug;
            }
            vcodec          libx264;
            vbitrate        1000;
            vfps            30;
            vwidth          0;
            vheight         0;
            vthreads        4;
            vprofile        high;
            vpreset         superfast;
            vparams {
                g       60;
                tune    zerolatency;
                vlevel  3.1;
            }
            acodec          aac;
            abitrate        128;
            achannels       2;
            aparams {
            }
            output          rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]-HLS/[stream]_360;
        }
    }
}

vhost Vhost-HLS {
    gop_cache       off;
    queue_length    10;
    min_latency     on;
    mr {
        enabled     on;
    }
    mw_latency      100;
    hls {
        enabled         on;
        hls_on_error    disconnect;
        hls_fragment    4;
        hls_window      32;
        hls_path        /var/www/srs-hls-axiscult;
        hls_dispose 1;
        hls_m3u8_file   [app]/[stream].m3u8;
        hls_ts_file     [app]/[stream]-[seq].ts;
    }
}

Replay

Please ensure that the markdown structure is maintained.

How to replay bug?

Please ensure that the markdown structure is maintained.

  1. Use Open Broadcaster to livestream to SRS using the RTMP protocol.
  2. Interrupt the stream somehow, for me it happens whenever I upload a large image somewhere else, like to Discord or to a website. Anything that makes OBS drop into the red zone for upload capacity.
  3. When the stream is interrupted, SRS will stop creating HLS playlists and video fragments. Even if OBS recovers and continues to upload as normal SRS won't make new fragments.
  4. SRS will continue to function as if everything is fine, but the HLS playlist wont come back until the stream is stopped and started again.

Expected behavior (Expect)

Please ensure that the markdown structure is maintained.

  1. Start streaming RTMP from Open Broadcaster to SRS.
  2. Interrupt the stream somehow, for me it happens whenever I upload a large image somewhere else, like to Discord or to a website. Anything that makes OBS drop into the red zone for upload capacity.
  3. SRS might stop creating HLS playlists and video fragments temporarily but will start again once the connection is restored.

I will make a demonstration video later.

TRANS_BY_GPT3

Baa14453 commented 3 years ago

Hi, please see the attached video: https://user-images.githubusercontent.com/9057997/112766185-8165c280-9008-11eb-8067-ecd40f8c77d9.mp4

At first the stream is running fine. When I upload an image to Discord, my upload bandwidth is consumed and OBS starts dropping frames. When this happens the HLS playlists being made by SRS stop, this is what the brown window at the top is showing. Even when the upload bandwidth is restored and OBS goes back to normal, HLS playlists do not resume.

praisegeek commented 3 years ago

I have experienced this as well. Thanks @Baa14453 for opening this.

Perhaps some digging and we can get past this.

Baa14453 commented 3 years ago

I have experienced this as well. Thanks @Baa14453 for opening this. @praisegeek

I think I've found two solutions please try them out:

  1. Set hls_dispose to a high number, like 300. I misread the docs and though this was a binary option for whether or not video fragments are deleted when the stream stops, but it's a timeout in seconds for how long SRS waits for data before deleting the video files. By increasing it I think I've given OBS more time to transfer and it seems to be working as fine, from the user's perspective the video feed just halts for a few seconds until my upload speed catches up.

  2. Use Hardware encoding in OBS. I have no idea why but using NVENC encoding in OBS made the issue go away, even without changing hls_hispose...

praisegeek commented 3 years ago

@Baa14453 I can confirm hls_dispose does work. Thanks