Search code examples
nginxrtmpflv

Live stream stops when a second viewer joins


I am trying to build a live stream platform using nginx and nginx-http-flv-module (with nginx-rtmp-module).

I have been using nginx-http-flv-module's guide.

I built an nginx server with rtmp and http-flv support.

My nginx.conf file:

#user  nobody;
worker_processes  1;

error_log  logs/error.log debug;

events {
  worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;

  sendfile        on;
  keepalive_timeout  65;

  server {
    listen       8080;
    server_name  localhost;

    ...

    location /live {
      flv_live on; #open flv live streaming (subscribe)
      chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response

      add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
      add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
      add_header 'Access-Control-Expose-Headers' 'Content-Length';
    }
  }
}

rtmp {
  server {
    listen 1935;
    ping 30s;
    notify_method get;

    application myapp {
      live on;
    }
  }
}

I start publishing my stream using OBS and play the stream in the browser using flv.js like this:

<video id="videoElement" controls autoplay></video>

...

<script>

    let videoElement = document.getElementById('videoElement');

    let flvPlayer = flvjs.createPlayer({
        type: 'flv',
        isLive: "true",
        url: 'http://192.168.1.122:8080/live?port=1935&app=myapp&stream=test'
    });

    flvPlayer.attachMediaElement(videoElement);
    flvPlayer.load();

</script>

And everything works great! The stream is playing in the browser as expected. But the problem is whenever a second viewer starts watching the stream (if I open it in another browser tab f.e). The player stops playing and starts infinite loading. So what can cause this problem?


Solution

  • I am the owner of nginx-http-flv-module, I am sorry that the bug was caused by the commit on July 7, 2019 and it has been fixed already.
    You can try the latest code.