How to set up your own private RTMP server using nginx

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

KR4KOS

New Member
"The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead."

Current ffmpeg version is 2.4, you are on 0.8 apparently, so its not up to date.

Yep, it's work now !
 

Nimble Streamer

New Member
In case someone may find it useful, our team has a couple of tools for both Nginx-rtmp and ffmpeg.

1. We've recently introduced Nginx-rtmp-module support in our reporting SaaS web panel, please check https://wmspanel.com/nginx for details.

2. We've also create a web console as part of WMSPanel which allows setting up and controlling any server-side tasks like ffmpeg processes. Check this description for details: http://blog.wmspanel.com/2014/10/server-tasks-web-management.html

I hope this will be useful for streaming media people.
Thanks!
 

KR4KOS

New Member
In case someone may find it useful, our team has a couple of tools for both Nginx-rtmp and ffmpeg.

1. We've recently introduced Nginx-rtmp-module support in our reporting SaaS web panel, please check https://wmspanel.com/nginx for details.

2. We've also create a web console as part of WMSPanel which allows setting up and controlling any server-side tasks like ffmpeg processes. Check this description for details: http://blog.wmspanel.com/2014/10/server-tasks-web-management.html

I hope this will be useful for streaming media people.
Thanks!

It is possible to create special key (streamkey) instead of putting anything and if the streamkey is not correct, he is can't stream on my website ?
 

Nimble Streamer

New Member
It is possible to create special key (streamkey) instead of putting anything and if the streamkey is not correct, he is can't stream on my website ?

This seems to be similar to hotlinking protection which is available for Wowza and Nimble Streamer as part of our Paywall framework: https://wmspanel.com/paywall There we allow creating a special signature for media URL which is checked when the player tries to connect. If the signature doesn't match the stream and address which it was initially created for, the streaming connection is rejected.
 

blimblim

New Member
Hi everyone.

First of all thanks for the tutorial and helpful replies in this topic, this helped me set up the server. Well, almost.
For some infuriating reason, everything works *perfectly*, but only for a few seconds (it seems like it varies from like 5 seconds to a minute).
So basically nginx starts up normally, I can connect obs to the rtmp no problem. I can then watch the stream from jwplayer or even vlc, or spawn ffmpeg to reencode to twitch, no problem as long as I do it fast enough.
As long as the clients stay opened, they see the stream, it keeps working for as long as I had time to test.
But a client disconnects, or if a new one tries connecting after a seemingly random but short time, they get nothing.
Here is what I get in the logs:
Working:
xxxxx [22/Oct/2014:18:12:36 +0200] PLAY "big" "1080" "" - 568 2716292 "" "WIN 15,0,0,152" (4s)
xxxxx [22/Oct/2014:18:12:46 +0200] PLAY "big" "1080" "" - 623 5302084 "" "WIN 15,0,0,152" (7s)
Not working:
xxxxx [22/Oct/2014:18:13:01 +0200] PLAY "big" "1080" "" - 511 542 "" "WIN 15,0,0,152" (13s)
xxxxx [22/Oct/2014:18:13:16 +0200] PLAY "big" "1080" "" - 511 542 "" "WIN 15,0,0,152" (12s)
xxxxx [22/Oct/2014:18:15:19 +0200] PLAY "big" "1080" "" - 511 436 "" "WIN 15,0,0,152" (12s)
xxxxx [22/Oct/2014:18:16:32 +0200] PLAY "small" "1080" "" - 519 436 "" "WIN 15,0,0,152" (41s)
These lines only appear in the logs if I press stop or reload the page in the browser. Basically it connects to nginx, nginx sends some stuff, and then nothing until the client disconnects.

Someone seemed to have a similar issue a few pages ago, but didn't post a solution.

I have tried many things, including downgrading to 1.1.4, playing with the meta/wait_video/ack_window/chunck_size/ping, but I have no solution.

After spending 3 hours on this, it's time for me to ask for your help :)

Here is a pastebin of a rtmpdump when it doesn't work:
http://pastebin.com/bw3m6zbS

Any idea would be *much* appreciated.
 

blimblim

New Member
Just replying with the answer so someone else doesn't lose a few hours for nothing. Make sure you only have one worker in nginx...
 

shok

New Member
Hello, i have a laravel homestead on virtual box with vagrant and I want to add the RTMP module but I doesn't have ./configure file.
I can't add this command :
"./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master"

because laravel homestead use : sudo apt-get install nginx
do you have any idea for install the rtmp ?
Thank You.
 

shok

New Member
Yes I know but, laravel homestead built automatically with apt-get nginx.
you write : vagrant up and everything is installed if I don't use laravel homestead i can't use laravel framework, you don't know an other way to add the module rtmp ?
 

shok

New Member
I reinstall everything from a clean machine
after several hours of searching I finally managed to install the RTMP, Laravel and everything works fully
 
the only thing this guide is missing is how to add it to init.d. i found a sysvinit script but it fails to work with these instructions most likely because the sysvinit script thinks nginx is installed in some other place and not looking in /usr/local/nginx/sbin/

Could you help me modify the sysvinit script here: https://github.com/Fleshgrinder/nginx-sysvinit-script so that it finds nginx that I installed using your guide please? Thank you
 

dodgepong

Administrator
Forum Admin
I'm pretty sure you can use that script as-is. just make sure /usr/local/nginx/sbin is in your path, or define a different install path when you ./configure.

Or better yet, put a symlink in a folder that's already in your path to the location of nginx.
 
i created a symlink within /usr/local/bin named nginx pointing to /usr/local/nginx/sbin/nginx and now it starts up using sudo service nginx start. So that means it should start up when the machine is rebooted since i added it to normal runlevels using
Code:
sudo update-rc.d nginx defaults
SWEET! Thanks for the quick response.

Anyone else wondering how to get nginx autostarted and they're using an ubuntu machine (or anything that uses sysvinit and i think even upstart) simple run the wget command found here: https://github.com/Fleshgrinder/nginx-sysvinit-script (using sudo since we're writing the file to /etc/init.d/ which is owned by root) then all you have to do is issue the following commands. the first command switches to root or you can skip the first command and use sudo with each command
Code:
sudo -i
Code:
cd /usr/local/bin
Code:
ln -s /usr/local/nginx/sbin/nginx nginx
Code:
exit
the exit command logs you out of root if you switched users to root in the beginning
 

Niamor

Member
Hi, I've been trying to use nginx for quite some time now, everything is working, people can see my stream but they also have lags and I can't figure why…
I have a pretty decent internet connection, I don't understand why and how to improve or fix it entirely.
 

sneaky4oe

Member
After a year, when I got a new CPU and learnt to stream with VCE OpenCL, I'm back to trying to make twitch a decent experience for my viewers at lagging twitch...

I just used a trial of cloudmouse.ru, and trying to setup server for encoding.

This is nginx config file.

e511a571d242.png

(exec string here is a bit messed up, but I have correct settings backed up at my desktop that worked at windows)

When I type in shell "nginx", I get this error message:

ubuntu@server14169:/$ nginx
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2014/11/13 05:19:56 [warn] 9656#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2014/11/13 05:19:56 [emerg] 9656#0: unknown directive "rtmp" in /etc/nginx/nginx.conf:11

In OBS I'm trying to stream to "rtmp://**.**.**.**/transcode/" FMS URL with key of "1234" and it says that server is offline.


Any ideas on what is wrong with this config?

Direct encoding through shell command with ffmpeg doesn't work as well, it just stucks:
Code:
ffmpeg -i rtmp://my_internet_ip/transcode/1234 -vcodec libx264 -preset faster -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -b:v 1600k -maxrate 1600k -bufsize 3200k -s 960x540 -sws_flags lanczos -acodec copy -f flv rtmp://live-fra.twitch.tv/app/*****************
 
Last edited:

dodgepong

Administrator
Forum Admin
Looks like you actually don't have the RTMP module installed. Did you follow the guide to make sure nginx was compiled with the RTMP module?

Also, remember to start nginx using the sudo command.
 
Top