josephnhtam / live-streaming-server-net

A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
https://josephnhtam.github.io/live-streaming-server-net/
MIT License
134 stars 20 forks source link

12Sec Delay on HLS URL #58

Closed kasirajansfm closed 2 months ago

kasirajansfm commented 2 months ago

Am facing 12sec delay on hls url, if i use RTMP url, it have only 2sec delay. Is there any change, that can reduce the delay?

josephnhtam commented 2 months ago

Hi @kasirajansfm

HLS, which is delivered over http, generally has larger latency. However, you can still try to reduce the keyframe interval on the publishing side and reduce the buffering time of the player to see if this can help.

Besides, LLHLS features are being considered a potential enhancement.

kasirajansfm commented 2 months ago

Tried, but no use, now am getting 8sec delay.

josephnhtam commented 2 months ago

8 seconds is indeed close to the best-case scenario for traditional HLS. In order to have 2-4 seconds latency, LL-HLS features will be required.

kasirajansfm commented 2 months ago

@josephnhtam Websocket-FLV working with 3 sec delay. Is that fine?

josephnhtam commented 2 months ago

Serving the stream via websocket-flv shouldn't add a visible latency. You may firstly check the buffering configuration of the flv player.

kasirajansfm commented 2 months ago
<!DOCTYPE html>
<html>
  <head>
    <title>WebSocket Video Player</title>
    <script src="https://cdn.jsdelivr.net/npm/flv.js@1.5.0/dist/flv.min.js"></script>
  </head>
  <body>
    <video id="videoElement" controls height="600" width="1200" autoplay muted></video>
    <script>
      var videoElement = document.getElementById('videoElement');
      var flvPlayer = flvjs.createPlayer({
        type: 'flv',
        url: 'ws://localhost:8080/live/d2.flv',
        stashedBufferTime: 0.1,
        bufferSize: 1024 * 1024, // 1MB
        lowLatency: true,
        maxBufferLength: 0.5 
      });
      flvPlayer.attachMediaElement(videoElement);
      flvPlayer.load();

    </script>
  </body>
</html>

@josephnhtam this is the code am using for player. am i using correctly.?

josephnhtam commented 2 months ago

I may not be able to help much if the limitation coming from the client side. Have you also tried xqq/mpegts.js?

kasirajansfm commented 2 months ago
<!DOCTYPE html>
<html>
<head>
    <title>WebSocket FLV Player</title>
</head>
<body>
        <script src="https://cdn.jsdelivr.net/npm/mpegts.js@latest/dist/mpegts.min.js"></script>

    <video id="videoElement" controls height="600" width="1200" autoplay muted></video>
    <script>
        if (mpegts.getFeatureList().mseLivePlayback) {
            var videoElement = document.getElementById('videoElement');
            var player = mpegts.createPlayer({
                type: 'flv', // could also be mpegts, m2ts, flv
                isLive: true,
                url: 'ws://localhost:8080/live/d2.flv', // replace with your WebSocket FLV stream URL
bufferSize: 1024 * 1024, // 1MB buffer size
                maxLatency: 500, // 500ms maximum latency
                lowLatency: true
            });
            player.attachMediaElement(videoElement);
            player.load();
            //player.play();
        }
    </script>
</body>
</html>

@josephnhtam Same 3-5 sec delay with this also. But in RTMP its like near realtime. is there any way to play RTMP on browser.

josephnhtam commented 2 months ago

I don't think it is possible to play rtmp directly in the browser. I will try to investigate the flv latency issue in the coming weekend.

josephnhtam commented 2 months ago

Hi @kasirajansfm

I tried the FlvDemo and used VLC player to play streams with both HTTP-FLV and RTMP. They both exhibit the same latency of 2 seconds. However, when the FLV stream is played with flv.js instead of VLC player, the latency increases to around 3 seconds. It’s evident that the flv.js library itself introduces some latency.

kasirajansfm commented 2 months ago

when i try with ffplay its around 1sec latency for both flv and rtmp. client side is causing the issue. thanks for the response.