open-webrtc-toolkit / owt-server

General server (streaming/conference/transcoding/anayltics) for OWT. (A.k.a. MediaServer)
https://01.org/open-webrtc-toolkit
Apache License 2.0
1.14k stars 369 forks source link

Safari plays HLS streamed out by OWT incorrectly. #1331

Open GStarP opened 1 year ago

GStarP commented 1 year ago

We build such flow: WebRTC(Browser) => publish and mix into view "common"(OWT) => streaming out as RTMP(NMS/SRS) => play by Safari <video>(HSL). We also tried generating HLS files directly from OWT and serve them by express.js for safari to request, but the problem remains the same.

The problem is that after normally played for abount 1min, the video keeps still (the video screen not change any more). However, in browser developer tool, we can see .m3u8 and .ts files are still being requested correctly, you can even download .ts and play!

By the way, Chrome on Android and Windows can play the same url using https://livepush.io/hls-player/index.html. It seems that only Safari <video> doesn't work well with OWT streaming out.

A recurrent reference:

starwarfan commented 1 year ago

Are there any quality changes(such as resolution, bitrate) of your HLS streaming when video starts to freeze in safari?

GStarP commented 1 year ago

Are there any quality changes(such as resolution, bitrate) of your HLS streaming when video starts to freeze in safari?

Accroding to ffprobe ${url}, output keeps showing as bellow, no changes:

Input #0, hls, from '${url}':
  Duration: N/A, start: 85.378000, bitrate: N/A
  Program 0
    Metadata:
      variant_bitrate : 0
  Stream #0:0: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp
    Metadata:
      variant_bitrate : 0
  Stream #0:1: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 1920x1080, 31 tbr, 90k tbn
    Metadata:
      variant_bitrate : 0
GStarP commented 1 year ago

New progress! A temporary solution is using SRS transcode to create another 1280x720 stream, Safari can play this new stream correctly.

New routes: streaming out to rtmp://x.x.x.x/stream1 (SRS) => transcoding to rtmp://x.x.x.x/stream2 (SRS), then you can play http://x.x.x.x/stream2.m3u8 in Safari correctly.

SRS config reference:

vhost __defaultVhost__ {
    hls {
        enabled         on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    transcode {
        enabled on;
        ffmpeg /usr/bin/ffmpeg;
        engine 720p {
            enabled on;
            vcodec libx264;
            vwidth 1280;
            vheight 720;
            vprofile main;
            vpreset medium;

            acodec copy;

            output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_720p;
        }
    }
}