How to set up your own private RTMP server using nginx

All Versions How to set up your own private RTMP server using nginx

snblg

New Member
Hello Tarumes.
Thank you for helping !

Below my config and html files. They are ok :
I've just understood my webbrowsers are unable to read the files (file rights)
If I copy all files from my hls folder to a test folder and replace the html links to that folder, it does play both under firefox and chrome. Obs does the job, nginx too !

I suppose I need to add a user in my nginx.conf file to allow the files to be accessible !
I will search today and let you know.

And I can also play the files from an external ip : I did configure my internet box adding a Nat/pat rule .
I'm almost ready. My online site is here.
 

Attachments

  • index.html.txt
    3.2 KB · Views: 227
  • nginx.conf.txt
    1.2 KB · Views: 378

snblg

New Member
Whatever I do, all files generated are protected.
My html page cannot read those m3u8 and ts files ( owner is root )

I can only launch nginx as root on my archlinux machine :
sudo systemctl start nginx

I tried changing hls destination folder, files are not protected if written on an ntfs partition, but the files must be in the root nginx path, so, it does not work either.

I found this page : my problem is probably related.

As it does work for many people, what did you do to make nginx server access hls files ?
 

snblg

New Member
@Tarumes : good idea,
but symlink folders do not solve my problem.

I investigated a bit more, starting again from scratch, in a new folder located at the root of my ext4 filesystem.

I'm using the user parameter in nginx.conf, 1st line :
user me users;
Files generated in the hls folder now belong to me, thanks to 1st line parameter.
I can never play the stream.m3u file and the last .ts file.

Example at t time, hls folder
stream.m3u3 cannot be opened
stream-24.ts has been automatically deleted
stream-25.ts can be opened
stream-26.ts can be opened
stream-27.ts cannot be opened, I have to wait for stream-28.ts to be created by nginx in this hls folder to be able to open it
stream-28.ts not created yet

I suppose I've got a bug with my nginx distribution !
I've re-installed nginx-rtmp -> same problem.
I'm running an updated archlinux distribution.

I'm a bit lost now and do not know what I could do !

Any idea ?
 

TamiDuke

New Member
As per my experience where it says (KEY) replace that with you're stream key for that platform; if you don't want to stream on that platform you can remove that line,you can choose if you want to be able to connect the server and watch the stream using publish but if you're just using this to restream then can just leave it as off.
Note to change the Key in this config (also I still use beam demains for RTMP server, are less used.

pcb turnkey
 
Last edited:

super1337ist

New Member
I'm sure this has been answered before, I tried my damndest to find it first but here we go
I'm finding the nginx server *appears* to be running successfully, I'm able to connect to the splash page perfectly.
However when entering that same address into the custom OBS settings it tells me it failed to connect and the error log for OBS claims that the server is offline.

any quick fire troubleshooting I can try before going deep into posting logs?
 

Shep

New Member
dodgepong submitted a new resource:

How to set up your own private RTMP server using nginx - A somewhat advanced guide for Linux-based servers



Read more about this resource...
The only thing I am struggling with is connecting out of Network, I am pretty knowledge/capable with most hardware software stuff, but dont know jack about networking... Is it a firewall issue? Do I need to change the server name from local_host? I can connect using rtmp://local-ip/live (the local ip has an extra on one the end idk why) 192.167.1.11 without the last one i go to router page not welcome to nginx.................I see some people adding the port 1935 onto the end of that like rtmp://192.165.1.11:1935/live but that doesnt seem to do anything. When I connect to the server should it matter if I am in network or out of network...shouldnt i be able to connect via public ip all the time. Is it a problem with not having a static IP? Can I just change the server name to www.????.com and use that to connect rather than IP address? So many questions lol What the best place to start when learning about networking lol
 

digokos

New Member
I have my nginx + rtmp up and running on one computer ....ok
I have up and running the OBS from another computer ....ok
OBS connected at nginx server and it can stream at facebook ....ok

How to stream it at my own site ....? (At wordpress)
 

Mark Weiss

Member
dam sorry i missed something
here it is

HTML:
<html>

  <head>
    <title>Hls.js demo - basic usage</title>
  </head>

  <body>
      <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>


      <center>
          <h1>Hls.js demo - basic usage</h1>
          <video height="600" id="video" autoplay controls preload="metadata"></video>
      </center>

      <script>
        if(Hls.isSupported()) {
          var video = document.getElementById('video');
          var hls = new Hls();
       
       
          hls.loadSource('http://192.168.0.109:8080/hls/stream.m3u8'); //<--------- here the server path to the hls playlist file
       
       
       
          hls.attachMedia(video);
          hls.on(Hls.Events.MANIFEST_PARSED,function() {
            video.play();
        });
       }
        else if (video.canPlayType('application/vnd.apple.mpegurl')) {
     
     
          video.src = 'http://192.168.0.109:8080/hls/stream.m3u8'; //<--------- here the server path to the hls playlist file
       
       
          video.addEventListener('canplay',function() {
            video.play();
          });
        }
      </script>

  </body>
</html>

I think my problem is related to accessing the /TEMP/HLS/ path on the nginx server. Do I need to specify the full path in the video.src= line, or is there some environment variable I need to set?

I've been working on this since late November. I've got the stream files appearing in that temp folder, and OBS is streaming normally, but the client player is still not working.

I'm getting close to deadline to have a viable stream working on March 30.
 

Mark Weiss

Member
Looking at the files being created while streaming, I see a file called ".m3u8". No root file name. Just an extension. However, the HTML on the player side makes reference to 'stream.m3u8". I'm looking to find out what determines this file name or lack thereof. Nothing in the nginx.conf file makes reference to the m3u8 file name, or even where to write these files.
 

Mark Weiss

Member
Had a breakthrough this evening.... I changed the nginx.conf to point to a folder within my web site's folders, and then I change the html for the page displaying the player to hls.loadSource('hls/.m3u8'); I deleted 'stream' from 'stream.m3u8'.
When I refreshed the browser, I see the stream.

Now the problem is the stream plays for about 30 seconds and then stops and displays a circular animation, like a buffering indicator. Inching closer, but hitting roadblocks at every turn..

I measured the time. Stream stops and begins buffering at precisely 30 seconds and is repeatable with each browser refresh. Watching closely, with the time slider visible, I see the duration is 31 seconds and the current time indicator is moving like it's playing a pre-recorded video, rather than a live stream.

This is my current nginx.conf:

Code:
worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;

        application live {
            live on;
        }
      
        application hls {
            live on;
            hls on;
            hls_path D:\inetpub\wwwroot\mwprovideo\hls;
            hls_fragment 8s;
        }
    }
}

http {
    server {
        listen      8080;
      
        location / {
            root www;
        }
      
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root www;
        }
      
        location /hls {
           #server hls fragments
            types{
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            alias temp/hls;
            expires -1;
        }

    }
}

If the fragment size is 8 seconds, why is the chunk playing for 30 seconds and stopping?

I suspect it's the .m3u8 file is not dynamically loading and updating:

Here's what's in it at the particular instant in time:

Code:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:187
#EXT-X-TARGETDURATION:10
#EXTINF:10.427,
-187.ts
#EXTINF:10.428,
-188.ts
#EXTINF:10.427,
-189.ts

It's loading three recently written transport streams. That probably totals 30 seconds. Once they play, the player has reached the end of that playlist and has to be manually refreshed.

Question is how to make this dynamicly refreshing?

Apparently, it's not really a "live" stream.. I changed the content of what I'm streaming from OBS and when I refresh the web browser, I'm seeing the same old video from 30 minutes ago. So it's playing an old transport stream, not the current stuff coming out of OBS.
 
Last edited:

Franq

New Member
This thread can easily be turned into a tutorial for non-members to have more knowledge about the Ngnix server setup.
 

Tarumes

Member
This is not true. I'm running nginx-rtmp on self-compiled nginx 1.15.8 with no issues.

Only for the builds on nginx-win.ecsds.eu

- rtmp, 1.7.12.1 is the last free version with rtmp, we do have a rtmp
special offer for the 1.9 branch (which without rtmp you could use
to tcp load balance 1.7.12.1 with rtmp)

Commercial subscription only modules:
...
= Streaming with nginx-rtmp-module
...
 

ilia1234

New Member
Hello
I followed your tutorial and I am able to connect to the NGINX server over 127.0.0.1 and also to connect OBS with NGINX server
But when I try to connect VLC to the NGINX server in order to view my desktop I got the "unable to open/access address".
I then tried the ffmpeg server and got the NGINX 111 error
What am I doing wrong?
 

Akanero

New Member
So, once I have the RTMP and Nginx server set up, how would I make it so that 2 different people in separate locations can stream to it? I am trying to "combine" their streams into a single stream on my computer (via VLC player or something). Then I'm going to use that VLC window as a source in OBS.

But I'm confused about how 2 people streaming to the RTMP at the same time would work. If I do that, and then get the stream to come up on VLC I would imagine that it would only show a single stream? Or maybe it wouldn't work at all?
 
Top