How to set up your own private RTMP server using nginx

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

The nginx rtmp server is installed on a VPS, I'm using OBS on windows to capture the display(play sling player full screen and source is my satellite box), my friends can watch it via browser with flash plugin installed, trying to find solution to watch it with mobile devices such as iPad and iPhone, still finding the way to do it.

And also, I'd like to record the streaming on VPS, currently is in flv format, I can use ffmpeg to convert to mp4 format but it's manual job, looking for change the conf to let rtmp server to create a new file every five minutes and after that convert it to mp4 and move to another folder, then update the html file so people can watch early clips in their browser, I don't know how to define the varible in conf and how to put some code to do it, saw an example by using exec_xxx but having issue with bash and other stuff, not a linux guy and could not understand what programming language should I use to make it works, please advise, thanks.
 
Simple Website with JWplayer

I have a similar setup like Steveswl with VirtualBox. I've created a simple website that will center JWplayer. Using some CSS, I made JWplayer responsive so it will adjust the size according to your browser.



Here's the template:
h**p://www.speedyshare.com/TZ87R/LiveStream.zip


Select your Ubuntu image and go to settings>Network

1. In OBS go to settings>broadcast settings (To find your Ubuntu IP: Open terminal type "ifconfig") at the top it will say inet addr:Ubuntu_IP_here

2. Extract LiveStream.zip
3. Open Index.html with a text editor like gedit. Go to http://www.whatismyip.com add your IP address and stream key on line 28.

{file: "rtmp://IPADDRESSHERE/live/flv:STREAMKEYHERE.flv"}
4. Create a folder called "live" in the root directory of the website.
5. Move all the files and css folder as shown below.

Link seems broken and i can not find the free version of JWplayer, i used to use this to make a website that my co host could watch delay free during twitch livestreams, really need to suss out how to get the www part working again
i ** the link as it leads to a chrome extension that reaks of malware now :*(
 
Having an issue playing back the rtmp stream from nginx, well the stream plays fine but whenever I stop the stream obs seems to disconnect and reconnect, which will stop the stream for anyone else watching as well of course..

Haven't setup authentication yet, I guess it may be solved with that? worker_processes is also set to 1 btw..

Anyone else with similar experience or is that just me?

How to recreate; Start nginx > start stream with obs > play the rtmp url in any video player > close the video player > obs disconnects.
 
Having an issue playing back the rtmp stream from nginx, well the stream plays fine but whenever I stop the stream obs seems to disconnect and reconnect, which will stop the stream for anyone else watching as well of course..

Haven't setup authentication yet, I guess it may be solved with that? worker_processes is also set to 1 btw..

Anyone else with similar experience or is that just me?

How to recreate; Start nginx > start stream with obs > play the rtmp url in any video player > close the video player > obs disconnects.
Can you share your config? That shouldn't be happening, but you might have changed some timeout/publisher thresholds causing a disconnect when the last viewer leaves.
 
Can you share your config? That shouldn't be happening, but you might have changed some timeout/publisher thresholds causing a disconnect when the last viewer leaves.
Just did another test btw, this is the output of access and error log when i stopped playback
----
error.log (When playback stopped)

2017/05/12 19:36:07 [alert] 26953#0: worker process 26960 exited on signal 11 (core dumped)

access.log (When playback stopped)

85.166.XXX.XXX [12/May/2017:19:36:06 +0000] PLAY "live" "test" "" - 489 758608 "http://localhost/ipcam" "LNX 25,0,0,148" (13s)
----

Also versions btw;
nginx version: nginx/1.13.0
obs version: 18.0.1.1 (linux)

And current config, just tested with the default one and appending the rtmp part at the bottom: https://hastebin.com/ixuvukiwat.nginx
 
Looks like it's crashing. You'll need to reach out to the nginx support communities for more help on that one.
Did some quick research on "worker process exited on signal 11 (core dumped)", seems to be a few threads on it but didn't find any solutions, may make a thread or try different versions, configurations etc. later when i have more time.

Also for testing and curiosity, if you have a working version of ngnix+rtmp module up and running, I'd like to see the output of 'nginx -V', to see which version i could give a try or different configuration. Mine below;

> ./nginx -V
nginx version: nginx/1.13.0
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-file-aio --add-module=../nginx-rtmp-module
 
I have OBS and Nginx RTMP streaming working great, but I would like some feedback on some of my settings.

On my desktop I am streaming NVENC H.264 at 50mbps set to 'high quality' with 'two-pass encoding' enabled. Would changing the preset to 'low latency high quality' and disabling 'two-pass encoding' accelerate the encoding much? If it would have a meaningful impact on stream delay, but expend no quality, I think it would be worth changing. Is the bitrate too high or too low? Would I benefit from increasing it to 100mbps for example?

As for my streaming computer, I am using a modified 'medium' x264 preset at 3mbps.

-vcodec libx264
-preset medium
-profile high
-level 5.1
-x264-params nal-hrd=cbr:force-cfr=1:keyint=60:me=umh
-r 30
-b:v 3072k
-minrate 3072k
-maxrate 3072k
-bufsize 3072k
-threads 12
-acodec copy

Overall I suppose I would like to know what bitrate should be sent from my desktop to my encoding server and what bitrate it should be compressed to for 720p or 1080p.

Thanks for your help!
 
Last edited:
Excellent Guide. I am now using OBS and an RTMP stream in nginx to broadcast our morning news for our school.

I do have one problem. When teachers find the stream with VLC it sometimes does not load the video. The only solution I have is to ask them to close VLC and re open. Sometimes they need to do that 4 or 5 times before the video shows up. Any tips or ideas?

Even with this problem, having this option is great. We can't use Youtube here at school so running our own RTMP server works.
 
Hi, guys. I have a RTMP server with FX8350 @4ghz. I want it to transcode my stream at faster preset to fullhd 60fps at a lower bitrate to stream with a GPU from my main PC.
htop says that CPU is utilized only by about 50%, but I get constantly skipped frames on twitch in most configs when I go above 30 fps even on veryfast or even fast. Any help, please?

Current config receiving 60 fps:

-vcodec libx264
-preset veryfast
-b:v 4500k
-maxrate 6000k
-bufsize 7000k
-s 1920x1080

Yes, bitrate is big, but my internet handles it and I have transcoding enabled on twitch that works fine with 10mbit stream.
I just want people to be able to watch my stream in source in 60 fps on lower bitrates that won't look bad.

I used to stream 1080/60 veryfast on windows with the same cpu, so need help with options.

Screenshot matches config with stream on.


update:
Looks like this config doesn't drop frames at all for me, while utilizing 100% of the cpu. I think I'll stick to it.
Code:
-vcodec libx264
-preset fast
-x264opts nal-hrd=cbr:force-cfr=1:keyint=100
-r 50
-b:v 4500k
-minrate 3500k
-maxrate 6000k
-bufsize 6000k
-s 1920x1080
-acodec copy
update2 looks like all those twitch drops are twitch&me stuff. No viewer complained, and there were like 60 drops for 20 minutes of stream
 

Attachments

Last edited:
I've read through this entire thread several times over and I still have no idea what to do. Here's what I've done so far:

- Installed nginx on my Raspberry Pi (running Retropie at the time). It worked but I couldn't get the stat.xsl page to work so I switched over to Raspbian Jessie instead.
- Installed nginx on my Raspberry Pi (running Raspbian Jessie). It looked like everything was running (I could see the nginx page) but I couldn't stream to it for whatever reason. Again, I could when using Retropie but not anymore. Now I'm running Ubuntu MATE on the Raspberry Pi and still I'm getting the same problem.

Does anyone know what I can do? I've spent several hours just trying to stream to this Raspberry Pi but nothing seems to work. It worked once before so I don't think it has anything to do with my router. Seriously, any help would be amazing.
 
Thank you for the guide. I've been using this setup on windows for quite a while, to provide a low latency, direct stream for my buddies. Now, I'm trying to push the stream to twitch simultaneously. This should be fairly simple, however somehow I absolutely can't get this to work. Basically, it appears as if nginx never even tries to establish a connection to twitch.

This is the setup i use. nginx config:
Code:
#user  nobody;
worker_processes  1;
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                        record off;
                        push rtmp://live-ams.twitch.tv/app/[twitch_streaming_key];
                }
        }
}
OBS Settings

Where 192.168.1.12 is the address of the nginx machine.

I experimented with different bitrates, resolutions and such. Whatever settings I chose worked fine, if I streamed directly to twitch, but never if I relayed through nginx.


Watching the stream from nginx with VLC also works fine every time.

When I monitor the connections nginx makes, it appears that nginx never even tries to establish any connection whatsoever.


Because of this, I assume I must be missing something obvious. But I cant figure it out. Also. there's nothing in the logs. Thank you for suggestions on what to try next.
 
Excellent guide, thank you! Very thorough and helpful. I followed the instructions to the letter and actually had everything working, despite being a total Linux newbie and OBS newbie for that matter. However from that point, I decided to move on to see if I could get it to work on HTTP5 (referencing this guide: https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/) but unfortunately I had no success. Most likely I had something misconfigured on the server and I'll have to research it more thoroughly. In the meantime I reverted back to the previous working nginx.conf file and rebooted the server. Since then, OBS will not hold the connection when I start streaming.

I did try streaming through Vaughnlive instead of my privately hosted server and had no issues there. OBS held the connection just fine. But with my server, it's up and down over and over again and never fully connects. I get a never-ending loop of pop-up errors that say "OBS Studio: Disconnected. Reconnecting...", then "Reconnection successful.", then "Disconnected" again. Any ideas? Could this be an ISP issue? That is, they caught on that I'm using my connection for streaming so now they've prohibited it somehow?

I can still connect to nginx index.html test page, so the web server is functioning.

Sorry if this is a vague description. As mentioned, all this stuff is very new to me. Thanks in advance for your help.

P.S. I did take a look at this thread but: https://github.com/jp9000/obs-studio/wiki/Dropped-Frames-and-General-Connection-Issues and tried everything that was applicable with no success.

EDIT: Well, my bad. Turns out it was a router issue on my end after all. I had access control set to block any new connections. When I disabled access control, I no longer got the constant failed reconnection attempts.
 
Last edited:
Top