How to set up your own private RTMP server using nginx

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

Gshine

New Member
I wanted to try this for a project at work. I created a VM through Linodes and had this running in a couple hours. It would have been shorter but I had to correct syntax errors that I created myself through sucky typing. I'll play with this for a bit then try putting it on a Raspberry Pi. Thanks for the instructions.
 

MidiaNinja

New Member
Its work well for me.
i'm using a windows server on amazon EC-2 instance.
i've follow this instruction for instal server, ports, and enginx: https://www.youtube.com/watch?v=rA_06zRKE4c&feature=youtu.be
and complete with this instructions for facebook: https://josuesworld.wordpress.com/2019/04/05/how-to-use-rtmp-and-rtmps-with-nginx-on-windows/

But now my question, i can duplicate the aplication on enginx for do a multiple diferent streams for multiple channels?

samething like:

Code:
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record off;
    #   YT Line
            push rtmp
    #   FB Line
            push rtmp
                }
                 application live2 {
                        live on;
                        record off;
    #   YT Line
            push rtmp
    #   FB Line
            push rtmp
                }
        }
}

Same think like that?

thank you all.
 

Lilrex

Member
When I tune in via VLC the stream freezes on VLC after about 5 minutes, and when I try and add it as a media source on OBS OBs crashes.
 

Lilrex

Member
Hi, thanks for the guide!
I have a problem. I can't connect to the rtmp server even inside a Lan.
Always shows this error:
NeZpjBn.jpg


All step were followed correctly.
No errors in the build stage, nginx is working fine in the standard http port and shows the sample webpage. The server doesn't have a firewall configured.
Tried on Ubuntu and Archlinux.
And I think this is correctly configured:
v0ta3m7.jpg



Some ideas?
did you open the port on your router? and allow the exception on your firewall?
 

MidiaNinja

New Member
Its work well for me.
i'm using a windows server on amazon EC-2 instance.
i've follow this instruction for instal server, ports, and enginx: https://www.youtube.com/watch?v=rA_06zRKE4c&feature=youtu.be
and complete with this instructions for facebook: https://josuesworld.wordpress.com/2019/04/05/how-to-use-rtmp-and-rtmps-with-nginx-on-windows/

But now my question, i can duplicate the aplication on enginx for do a multiple diferent streams for multiple channels?

samething like:

Code:
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record off;
    #   YT Line
            push rtmp
    #   FB Line
            push rtmp
                }
                 application live2 {
                        live on;
                        record off;
    #   YT Line
            push rtmp
    #   FB Line
            push rtmp
                }
        }
}

Same think like that?

thank you all.


ok i've tested it and works perfectly for youtube.
tomorrow i will teste with multiple signals ands multiple facebook recivers.
 

MidiaNinja

New Member
I wrote a little program that will help ease the creation of the config file for Windows. You will need to provide your own copy of Nginx with RTMP for it to work properly.
Main Window
9QYKJpQ.png


Config Window (Example)
0LsNKQH.png


nginx.conf with settings from previous window.
ELwmlm8.png

The ingest will allow for up to 5 applications for other people to stream TO so they can be mixed with OBS on the RTMP server and then rebroadcast out from the Stream application. You can use this with another person to produce multicam streams.

I think its operation is fairly straight forward.
Any feedback is appreciated.

https://1drv.ms/u/s!Ar4s89ZajRLcocVjj_y0D_NZVYLmew?e=pM1yRB

Hi i will try it on my nginx running on a AWS EC2.
But i use it a little diferente way, i'm searching how to create a aplication like yours.

2 questions
i use 4 diferent aplications for 4 diferent signals for diferentes fonts.

Like it:

Code:
Live 1
Push 1.1
push 1.2
push 1.3

live2
push 2.1
push 2.2
push 2.3
...

u cant adapt your aplication for use like that?
or u can share the code for we work on them?


Now the second case:
you said:
The ingest will allow for up to 5 applications for other people to stream TO so they can be mixed with OBS on the RTMP server and then rebroadcast out from the Stream application. You can use this with another person to produce multicam streams.

Using it, how we add it like a font on OBS?
 

samfisher5986

New Member
Hi Everyone

I've successfully run my nginx obs live stream locally but I've run into a problem.

There seems to be a chance, especially on first run that it will stop working after 5+ users connect and. Most of the time when I click "start live stream" again, it will keep going without issues and 15+ people can connect without issues. Its hard to make it happen on purpose though.

Nginx and OBS itself does not crash, but the live stream shows 0 kbps and a red icon, instead of 3000kbps and a green icon.

My keyframe interval is 2, my resolution is 720p and I have a lot of spare computer power (AMD 3900x and Nvidia 2060)

I feel like its something network related because it seems to happen when people join, its generally only using 40mbit of my 1000mbit gigabit lan connection though.

Has anyone run into anything similar? Is there something I can do to make it run more reliably?

I ran the "Tweak-Optimize tcpip parameters for nginx connections.reg" that came with it, but now I'm wondering if I should increase the limits higher, they already seem very high though.

-------

Here is my log for the period where it stopped working. It does show dropped frames, but some users are watching via wifi etc so that should be their end.

9:06:30 AM.646: [ffmpeg muxer: 'adv_file_output'] Output of file 'D:/OBS Recordings/2020-05-28 08-57-14.mkv' stopped
9:06:30 AM.646: Output 'adv_file_output': stopping
9:06:30 AM.646: Output 'adv_file_output': Total frames output: 16630
9:06:30 AM.646: Output 'adv_file_output': Total drawn frames: 16677
9:06:30 AM.647: ==== Recording Stop ================================================
9:06:30 AM.647: warning: 2 frames left in the queue on closing
9:06:34 AM.733: [rtmp stream: 'adv_stream'] User stopped the stream
9:06:34 AM.733: Output 'adv_stream': stopping
9:06:34 AM.733: Output 'adv_stream': Total frames output: 16443 (17712 attempted)
9:06:34 AM.733: Output 'adv_stream': Total drawn frames: 17749
9:06:34 AM.733: Output 'adv_stream': Number of dropped frames due to insufficient bandwidth/connection stalls: 1269 (7.2%)
9:06:34 AM.733: [rtmp stream: 'adv_stream'] Freeing 210 remaining packets
9:06:34 AM.737: ==== Streaming Stop ================================================
9:06:34 AM.770: warning: 2 frames left in the queue on closing
9:06:38 AM.490: ---------------------------------
9:06:38 AM.490: [x264 encoder: 'streaming_h264'] preset: veryfast
9:06:38 AM.490: [x264 encoder: 'streaming_h264'] settings:
9:06:38 AM.490: rate_control: CBR
9:06:38 AM.490: bitrate: 3000
9:06:38 AM.490: buffer size: 3000
9:06:38 AM.490: crf: 0
9:06:38 AM.490: fps_num: 30
9:06:38 AM.490: fps_den: 1
9:06:38 AM.490: width: 1280
9:06:38 AM.490: height: 720
9:06:38 AM.490: keyint: 60
9:06:38 AM.490:
9:06:38 AM.494: ---------------------------------
9:06:38 AM.494: [FFmpeg aac encoder: 'Track1'] bitrate: 160, channels: 2, channel_layout: 3
9:06:38 AM.494:
 
Last edited:

vitaminshred

New Member
Hello Dodgepodge!

I've been able to successfully setup the Nginx server and push a single stream from outside of my local network and then view it on VLC and use it as a source on OBS.That said, I am running into a problem when I try to push multiple stream to the server and then try to retrieve them. I am able to stream from multiple computers to my server (they connect, they upload, no problem). I did this by adding mutiple server entries that listen on ports 1936 and 1937; however, when I try to bring bring those sources into OBS, I can't see them. They all have discrete application names and they are on different ports. As I mentioned, It works fine for 1 source going through the server and I can even push multiple streams to the server, but I can't seem to retrieve them once I add more than one source. Any ideas?
 

christina98

New Member
Nginx-RTMP is an open-source extension module for the Nginx web server that can be used as a media streaming server for both live streams and video on demand using RTMP. This doesn’t come pre-packaged for the operating system, so we’ll need to build Nginx with this module from source code. The first thing we need to do is get some bits. To do so, enter the following:
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev unzip
This will take some time. Once these are installed we then need to grab the nginx source code. Version 1.8.1 is the latest stable version so we will use that one:
mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
The next thing we will need is the source for Nginx-RTMP:
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip master.zip
At this point, we should have a directory named nginx-1.8.1 which contains the Nginx source code, and one named nginx-rtmp-module-master which contains the Nginx-RTMP source code. The next step is to reconfigure the Nginx source to compile with the Nginx-RTMP module:
cd nginx-1.8.1
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
You should see a scroll of text while it is configured, after which you can make and install nginx:
make
sudo make install
At this point Nginx will be installed into the /usr/local/nginx directory. To test everything is working let’s fire Nginx up:
sudo /usr/local/nginx/sbin/nginx
If everything is working as expected, you should now get the Nginx test page if you navigate to your server’s IP address in a web browser. To stop Nginx you need to call the program again and give it the stop command:
sudo /usr/local/nginx/sbin/nginx -s stop
Now you will need to add the code to configure the RTMP module. This is done in the default config file which is stored with the other files. I’m going to use nano here, but other text editors are available:
sudo nano /usr/local/nginx/conf/nginx.conf
Go to the end of the file and paste in the following configuration:
rtmp {
server {
listen 1935;
chunk_size 8192;
application vod {
play /usr/local/nginx/rtmp;
}
}
}
Save and exit the file. In this file, we’ve told Nginx to listen on port 1935 for RTMP, which is the default port. We’ve also set it to use a chunk size in transfers of 8192 bits. Next, we’ve created an “application” called vod for video on demand. You can have as many of these as you wish, and name them anything you like. We’ve then told it that the vod application will play files from /usr/local/nginx/rtmp directory. This directory doesn’t actually exist yet, so you will need to create it and place some media into it. Note that Nginx-RTMP can only serve flash flv video and mp4 video.
sudo mkdir /usr/local/nginx/rtmp
The next thing to do is start Nginx again, at which point everything is configured and ready for use:
sudo /usr/local/nginx/sbin/nginx
To test you just need to open a stream from your server. The easiest method is to use VLC media player. To open this, go to the “Media” menu and then select “Open Network Stream”. A window will open for you where you can enter the URL for your media.
The URL will start with rtmp:// to tell VLC the protocol to use, and then the domain name or IP address of your server. Next will be a slash, then your application name, in our case “vod”, another slash and finally the filename of the file. So as an example:
rtmp://your-domain.com/vod/test.mp4
rtmp://your-domain.com/vod/test.flv
This will have more control over your live streaming platform like twitch on iOS, Windows, Linux etc.
So there you have it – a simple streaming server using RTMP based on open source components. Happy streaming!
 

MidiaNinja

New Member
Hello,
i need to convert my signal for diferent resolution, audiobitrate for diferent pushs on same aplication.

for exemple.
i'm using a obs, with 1920x1080 resolution, 160kbps audio 4500kbps for video, interval keyframe 2

in 1 aplication callend "exemple" i have 4 push.
youtube, it work well
facebook it work well
twitch it work well
but periscope need lower bitrate of video and audio and lower resolution too.

we have any way to convert for only one push on same aplication?
 

newuser01

New Member
Hi, me and my gf want to dual gameplay stream to twitch over the internet because we arent living together yet.

I tried setting up nginx on my windows 10 which worked quite well but when we go live, she has a delay of about 2-3 seconds while i have almost no delay.

I put her game in my obs by using vlc network stream. My gameplay is local so i have no delay.

My idea was to stream our gameplays to raspberry pi (no clue if its possible) and then restream it somehow to twitch so we have same delay (at least i hope) or whatsoever. So my local network would be the host.

I have no clue how to do this though.

So it's kinda like getting 2 streams to my obs and then restream it or something like that.

I would truly appreciate if someone could help me <3
 
Hi, me and my gf want to dual gameplay stream to twitch over the internet because we arent living together yet.

I tried setting up nginx on my windows 10 which worked quite well but when we go live, she has a delay of about 2-3 seconds while i have almost no delay.

I put her game in my obs by using vlc network stream. My gameplay is local so i have no delay.

My idea was to stream our gameplays to raspberry pi (no clue if its possible) and then restream it somehow to twitch so we have same delay (at least i hope) or whatsoever. So my local network would be the host.

I have no clue how to do this though.

So it's kinda like getting 2 streams to my obs and then restream it or something like that.

I would truly appreciate if someone could help me <3

Having no delay from two different locations seems impossible - you would have at least 1 second delay from a remote location.
I've received video from a mobile device using Larix Broadcaster and I have a 1 second delay from that feed.

The setup I have is this:

Mobile Device (Larix Broadcaster) -> Nginx Server (1)->|......................................................... |--->YouTube
...............................................................................................|--->My OBS--->Nginx Server (2)-->|----> Stunnel--->Facebook
..................................................Local Media (videos)------>|

I have two Nginx Servers in the mix, but I could use one....I have two because Server 1 is exposed to the internet, while 2 is internal.
But with this setup I can stream from multiple sources to multiple sources with a 1 second delay from the external source.

Is she using nginx + OBS to broadcast and you are using vlc to get her stream?

You could have her nginx push the stream to your local Niginx Server (you'd have to figure what port to expose in the config file to receive the stream). The you can load it as a Media source in your OBS instead going through VLC.

I doubt it will help with the delay, but at least you wont have an extra application open.

You can then push your OBS stream via Nginx to multiple locations.

I created a tutorial on multsreaming with nignx on Windows: https://www.youtube.com/watch?v=wJaz59ZHgCo

Hope this helps, the one thing to remember is your internet UP/Down speeds have to be good to handle all that traffic. Mines 300/30 but I only stream 720 5Mbs and my upload traffic is ~10Mbs (youtube + facebook) when everything is running.
 

Mark Weiss

Member
It seems that Twitch.tv changed their code again, breaking my embedded live stream on basspig.com.

I've been trying to figure out how to stream live, (the way I used to in 2005 with Windows Media Encoder) from a capture card, for the past two years.

I've gotten a few steps along the way, getting OBS to see a valid streaming server with nginx, and I've been able to get an embedded player to appear on a test website, but the most I was able to do was get 8 seconds of video to play over and over again. It's not live.

Now that Twitch has thrown it's embedded streamers under the bus, I really need to get my own streaming working.

For the bandwidth issue, I'm moving to Japan, where I get 1000mb/s upstream speed with NTT Docomo, so I think that will be enough to serve my audience with each stream being 2.5 mb/s. I just need to fix this problem.

My Windows XP laptop from 2005 still has Windows Media Encoder on it. I am wondering if that can be copied to my Windows 7 server and used to create a stream from the output of OBS?
 

Mark Weiss

Member
Same here, Same for FB. Only Twitch start automatically.

Unfortunately, on June 10, Twitch embedding code was broken again. I can't get embedding to work. That leaves me with having to figure out how to stream from my own PC now, a problem I have not been able to solve for two years. Ironically, in 2003-2005 I did it with Windows Media Encoder real easily. But nothing like that exists now.
 

ustoopia

New Member
For those people who prefer to setup their nginx livestream server on a Windows machine, I've created a github and instructions video for you all that allows for fast and easy install and some extra's like php and a webpage that will show your stream using videojs. To know what you are actualkly doing when installing it, I advice you to also have a look at the video I made for it.

https://github.com/ustoopia/nginx-rtmp-1.17.10-windows-php-videojs-dashjs
Please make sure yiou go through the README file since it hold essential information.

If you decide to use my build to install your livestream server, I strongly advice you to also check out the video because I explain everything that must be done.
https://www.youtube.com/watch?v=sRdDNhALeVo

Have a look at my other video's on youtube (here, here, here and here) to learn more on how to set up a live-stream server on a linux server. Also I show how to install and use NodeMedia Server and Ant Media Server. These both allow you to run your own livestream server similar to using nginx. All my video's include a webpage with all the instructions step-by-step that you can use to copy/paste yourself through it all.
 

coscino

New Member
Hello, I would like to try this method because I would like to be able to pause my university online lessons with Microsoft teams meetings like it was a YouTube live(be able to pause or go back in the live).So I am planning on playing the teams meeting on a pc, record with obs and use a raspberry pi as server to cast to a second pc where I will watch the lesson with VLC. Will i be able to stop or go back 30 seconds with VLC network stream? Is there a simpler method to obtain such capabilities?
 

Tonydenson

New Member
I have setup an RTMP server as above on a Raspberry Pi and it works great. However, the one thing I can't seem to do is play the stream locally on the Pi itself. If I run VLC there and point it at localhost nothing happens. Any suggestions ?
 

MidiaNinja

New Member
For those people who prefer to setup their nginx livestream server on a Windows machine, I've created a github and instructions video for you all that allows for fast and easy install and some extra's like php and a webpage that will show your stream using videojs. To know what you are actualkly doing when installing it, I advice you to also have a look at the video I made for it.

https://github.com/ustoopia/nginx-rtmp-1.17.10-windows-php-videojs-dashjs
Please make sure yiou go through the README file since it hold essential information.

If you decide to use my build to install your livestream server, I strongly advice you to also check out the video because I explain everything that must be done.
https://www.youtube.com/watch?v=sRdDNhALeVo

Have a look at my other video's on youtube (here, here, here and here) to learn more on how to set up a live-stream server on a linux server. Also I show how to install and use NodeMedia Server and Ant Media Server. These both allow you to run your own livestream server similar to using nginx. All my video's include a webpage with all the instructions step-by-step that you can use to copy/paste yourself through it all.

Its amazing content, i`ve learned alot, thank you.
I`m planing build a open-source tv, and i have same questions wich is important for choose ways.

I can use a similar server on a cloudmachine, like AWS, Googlecloud or anythink like, and control the nginx config remotely, via web, by browser?

I look for features like
Another one is use ffmpeg for stream directly a local network ndi source.
Dynamically choose between 3 obs transmitting to the server which would go on air
Use different sources of obs transmitting remotely to the server as a source in a central obs
A interface to change streamkeys of diferent RTMP destinations aplications.
its Possible?

if you are interested in collaborating on our project we can make a call about.
 
So this work in windows? I can change ip adress with vpn of ngnix server somehow if i want to stream to twitch with different ip?
 
Top