How to set up your own private RTMP server using nginx

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

esevenf

New Member
You would probably have to set something up in the nginx config that sends some sort of signal to a database or something that marks a stream as live or offline. So, not out of the box.
Mh yeah I figured it would be a bit complicated like that. :/
Guess I have some reading to do.

Thanks.
 

godsyn

New Member
Mh yeah I figured it would be a bit complicated like that. :/
Guess I have some reading to do.

Thanks.
Using the nginx rtmp stats XML output, and php's xml parser, you can get simple stats from the nginx http server without the need of a full DB (mysql, etc.).
See: https://github.com/arut/nginx-rtmp-module/wiki/Directives#rtmp_stat
I threw together some php in the past (nginx wasn't fitting my needs) to read some data from said stats:
http://pastebin.com/kVccUqZy
 

Someone777

New Member
So, I installed nginx previously using aptitude.

Code:
sudo /bin/bash

aptitude update

aptitude install python-software-properties

aptitude upgrade

add-apt-repository ppa:nginx/development

aptitude update

aptitude install nginx

I have two questions. The first is how do I add the rtmp module without breaking the existing nginx install? The other question is can I add the module as a repository somehow and have it update with the aptitude command?

I kind have already found an answer to the first question but I know next to nothing about Linux so it's all Greek to me. https://github.com/arut/nginx-rtmp-module/wiki/Installing-on-Ubuntu-using-PPAs

I have no idea if that will actually work for me. If there's no way to get it to update through the aptitude command, what is the recommended way of keeping it updated?

I did follow the tutorial and install a second copy of nginx and got streaming to jwplayer working. I know I could remove the aptitude install and keep the other one but your install doesn't auto-launch at start up and the only way to update it, that I know of, is to do it manually.

For anyone who doesn't know how, I got jwplayer working with this:
Code:
Commands (don't remember if sudo was necessary for any of these):

cd /usr/local/nginx/html

wget http://www.longtailvideo.com/download/jwplayer-3359.zip

unzip jwplayer-3359.zip

HTML Code

<script type="text/javascript" src="/jwplayer/jwplayer.js"></script>
<div id="myElement">Loading the player...</div>

<script type="text/javascript">
        jwplayer("myElement").setup({
                file: "rtmp://server.ip/live/test",
                height: 480,
                width: 720
                });
</script>

Thanks for the tutorial and any answers I get.
 

dodgepong

Administrator
Forum Admin
You can't add RTMP support to an already-compiled version of nginx, so those instructions tell you how to recompile the dpkg with the module added in. Honestly, it's just as easy to compile it yourself from scratch. But if you got it working, then great!

As for auto-starting, I didn't include any instructions because Linux systems have many different ways to manage startup programs. For Ubuntu, here's something to get you started: http://askubuntu.com/questions/256025/initialize-script-on-startup
 

Someone777

New Member
I looked at your link for making a startup script and that seems really involved for something that's a drag and drop operation in Windows.

Anyways, I decided to try the instructions for recompiling the dpkg and I can't get that to work at all. Whenever I try to run "dpkg-buildpackage -b" I always get this error:

Code:
dpkg-checkbuilddeps: Unmet build dependencies: libgd2-dev | libgd2-noxpm-dev
dpkg-buildpackage: warning: Build dependencies/conflicts unsatisfied; aborting.
dpkg-buildpackage: warning: (Use -d flag to override.)

I tried using the -d flag, I got this error instead:

Code:
./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.

I've spent the last hour or so trying every solution I could find on google for those errors and nothing works. When I run "apt-get install libgd2-xpm libgd2-xpm-dev" it tells me they're already installed. I'm at a complete loss for how to get around this.

At this point, making the startup script seems like less work. I'll save that for tomorrow though, I'm already fairly over messing with Linux today.

Edit:

I forgot to mention, I was trying to find ways to improve the instructions in your tutorial and this is what I have so far:
Code:
mkdir nginx-build
cd nginx-build
wget http://nginx.org/download/nginx-1.7.1.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip master.zip
tar -zxvf nginx-1.7.1.tar.gz --strip-components=1
./configure --with-http_ssl_module --add-module=/nginx-rtmp-module-master
make
make install
cd ..
rm -rf nginx-build
All I did was create a temporary directory to do all the work in and remove the directory once I was done with it. I've been looking for an automated way to retrieve the current version of nginx rather than having to manually find it but no luck so far.

I finally figured out how to fix the conflict over libgd2-noxpm-dev. All I had to do was edit debian/control and change "libgd2-noxpm-dev" to "libgd2-xpm-dev"

After running the following commands I finally have it installed and running:

Code:
aptitude install init-system-helpers
dpkg --install nginx-common_1.7.0-1+precise0_all.deb nginx-full_1.7.0-1+precise0_amd64.deb
 
Last edited:

Someone777

New Member
So, this is pretty much what it took me to use the PPA repository:

This was a fresh Ubuntu Server install. So, I'm starting from that point. I didn't keep perfect notes, so I can't make any promises that I didn't leave something out. However, the parts that gave me problems should be detailed and correct.

I start off by elevating to root and installing SSH, updating and installing some other stuff I needed.

Code:
sudo /bin/bash

apt-get install openssh-server

aptitude update

aptitude install python-software-properties

aptitude upgrade

aptitude install nano

nano /etc/ssh/sshd_config

Add line at the end:
Code:
AllowUsers [username]

Be sure you replace [username] with whatever your username is. So, if your login is bob, it would be:
Code:
AllowUsers bob

Code:
/etc/init.d/SSH restart

Now you, and only you, can SSH in. You'll probably want to use "sudo /bin/bash" again, if you connect through SSH at this point.

This is where I start things for adding the module to the source.

Code:
apt-get install dpkg-dev

add-apt-repository ppa:nginx/development

aptitude install init-system-helpers

aptitude install unzip

aptitude update

apt-get source nginx

apt-get build-dep nginx

cd nginx-1.7.0/debian/modules

wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

unzip master.zip

cd ..

cd ..

nano debian/rules

Add "--add-module=$(MODULESDIR)/nginx-rtmp-module-master \" and "--with-http_ssl_module \" to full_configure_flags and extras_configure_flags and naxsi_configure_flags

Code:
nano debian/control

Change "libgd2-noxpm-dev" to "libgd2-xpm-dev" to resolve a conflict.

Code:
dpkg-buildpackage -b

cd ..

dpkg --install nginx-common_1.7.0-1+precise0_all.deb nginx-full_1.7.0-1+precise0_amd64.deb

nano /etc/nginx/nginx.conf

Now, as with your guide, just add a function to the end of nginx.conf:

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

  application live {
  live on;
  record off;
  }
  }
}

Alternatively, you could use something like this:

Code:
rtmp {
   server {
     listen 1935;
     chunk_size 4086;
    
     application live {
       live on;
       push_reconnect 5s;
       #access_log /var/my_records/logs/rtmp_access.log;
      
       interleave on;
       meta on;
       publish_notify on;
       wait_key on;
       wait_video on;
      
       recorder audio {
         record audio;
         record_unique on;
         record_path XXXXX;
         record_suffix .audio.flv;
       }
      
       recorder chunked {
         record all;
         record_unique on;
         record_interval 240m;
         record_path XXXXX;
       }
      
      
      
       # Twitch.TV
       push rtmp://live.twitch.tv/app/XXXXX;
      
      
       # YouTube Live  # push rtmp://  ;
      
      
       # HASHD.TV  #
       push "rtmp://ingest-dal1.hashd.tv/live/XXXXXX?key=XXXXXX";
      
      
       # USTREAM.TV  #  name=incomingstreamname is whatever you're specifying as your streamname. So if you use rtmp://yourserver:1935/live/test then the name would be "test"
       push rtmp://1.XXXXXXX.fme.ustream.tv app=ustreamVideo/XXXXXXX name=incomingstreamname playPath=ustreamsessionkey;
     }
   }
}

Now, to reload nginx, add jwplayer and add a test page.

Code:
/etc/init.d/nginx reload

cd /usr/share/nginx/html

wget http://www.longtailvideo.com/download/jwplayer-3359.zip

unzip jwplayer-3359.zip

nano test.html

HTML Code:

Code:
<!DOCTYPE html>
<html>
<head>
<title>The Page for Testing</title>
<style>
  body {
  width: 35em;
  margin: 0 auto;
  font-family: Tahoma, Verdana, Arial, sans-serif;
  }
</style>
</head>
<body>
<h1>Test Page</h1>
<br>
<script type="text/javascript" src="/jwplayer/jwplayer.js"></script>
<div id="myElement">Loading the player...</div>

<script type="text/javascript">
  jwplayer("myElement").setup({
  file: "rtmp://your.ip/live/test",
  height: 480,
  width: 720
  });
</script>
</body>
</html>

At this point, if you visit your.ip/test.html, you should be able to see your own stream. This was a bit more complicated than your guide but now nginx autostarts and aptitude should recognize the install.

The only problem with the instructions is that it'll be somewhat obsolete when they release a new version.
 
Last edited:

e7d

New Member
Hey everyone,

Configuration of a private RTMP server could be difficult and quite long for many people. I had myself to set up a private RTMP server recently and decided to make a "Virtual Machine Package" from that.

Basically, it contains :
  • a preconfigured nginx 1.6.0 with RTMP support from arut/nginx-rtmp-module @github
  • a self developped web interface for watching/recording live streams and watching/downloading previously recorded sessions
Interested people are free to have a look at my project's dedicated web page: http://projects.e7d.fr/media-streaming/

I'll be happy to have feedbacks from you guys if you spot any difficulty or problem. Just keep in mind that project is at a starting point.
 

Jack0r

The Helping Squad
Hey @e7d, a bit more documentation would be great :D I got it running so far, but I had a hard time finding the nginx config file, then I had to search the html folder, etc. Also a root user should be available if you want to install more stuff. The interface looks really nice, but I will have to dig through the config to see how I can actually use it, apart of the transcode app :)

I definitely like your current descriptions which should also help "noob" users, but I personally would prefer a more to the point documentation, maybe everything important on one page! Definitely a big thanks for your work so far, will keep an eye on it!
 

Fenrir

Forum Admin
Hey everyone,

Configuration of a private RTMP server could be difficult and quite long for many people. I had myself to set up a private RTMP server recently and decided to make a "Virtual Machine Package" from that.

Basically, it contains :
  • a preconfigured nginx 1.6.0 with RTMP support from arut/nginx-rtmp-module @github
  • a self developped web interface for watching/recording live streams and watching/downloading previously recorded sessions
Interested people are free to have a look at my project's dedicated web page: http://projects.e7d.fr/media-streaming/

I'll be happy to have feedbacks from you guys if you spot any difficulty or problem. Just keep in mind that project is at a starting point.

Any chance you'd be willing to offer the interface part as a standalone package? I already have my server up and running how I like it, but that interface looks pretty wicked!
 

e7d

New Member
Hey @e7d
I definitely like your current descriptions which should also help "noob" users, but I personally would prefer a more to the point documentation, maybe everything important on one page! Definitely a big thanks for your work so far, will keep an eye on it!

Yeah, my first position with the documentation was to aim for "beginners" who would not be willing to modify deep parts of the machinery.
But i think you are right and would offer a sort of advanced documentation, basically indicating were to find the different parts (nginx, web interface), how it is setup and what could be done (because yes, i have more plans).


Any chance you'd be willing to offer the interface part as a standalone package? I already have my server up and running how I like it, but that interface looks pretty wicked!

That was not part of my first intentions. But yes, you can extract the whole web part if you need to. You can find the whole package on /var/html/www. Pretty much every sub part is required to make it work. Just note that the "recording video" part depends on my specific configuration since it plugs on a "recorder" from rtmp configuration file.
 

Fenrir

Forum Admin
Yeah, my first position with the documentation was to aim for "beginners" who would not be willing to modify deep parts of the machinery.
But i think you are right and would offer a sort of advanced documentation, basically indicating were to find the different parts (nginx, web interface), how it is setup and what could be done (because yes, i have more plans).




That was not part of my first intentions. But yes, you can extract the whole web part if you need to. You can find the whole package on /var/html/www. Pretty much every sub part is required to make it work. Just note that the "recording video" part depends on my specific configuration since it plugs on a "recorder" from rtmp configuration file.

Fair enough! I ended up just spinning up a new VM with your whole setup on it, and been trying to go through and piece together how it's configured :)

One issue I'm having is that I can stream to /live and the streams show up in the list of active channels, but streaming to /transcode doesn't seem to work properly. The channel doesn't show up live, and I can't view it. I haven't changed any config (outside the root PW), so I'm not sure why it isn't working. Recording also doesn't seem to be working either.
 

Fenrir

Forum Admin
error.log is showing this if it helps:

Code:
2014/06/10 16:03:48 [error] 9915#0: *222 FastCGI sent in stderr: "PHP Notice:  A session had already been started - ignoring session_start() in /var/www/html/lib/RTMP.class.php on line 2
PHP Warning:  simplexml_load_file(http://localhost/stat.xml): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
 in /var/www/html/lib/RTMP.class.php on line 28
PHP Warning:  simplexml_load_file(): I/O warning : failed to load external entity &quot;http://localhost/stat.xml&quot; in /var/www/html/lib/RTMP.class.php on line 28
PHP Notice:  Undefined index: server in /var/www/html/lib/RTMP.class.php on line 30
PHP Warning:  array_key_exists() expects parameter 2 to be array, null given in /var/www/html/lib/RTMP.class.php on line 30
PHP Notice:  Undefined index: server in /var/www/html/lib/RTMP.class.php on line 40
PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/lib/RTMP.class.php on line 40" while reading response header from upstream, client: xxx.xxx.xxx.xx, server: localhost, request: "GET /api.json?action=channels HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xx.xx.xx.xx", referrer: "http://xx.xx.xx.xx/?videos"

Hid the IPs as I'd rather not broadcast those.
 

Fenrir

Forum Admin
Ignore my previous post, I figured out why it wasn't working. :) I had an .htpasswd enabled, but typo'ed the filepath. Works all as expected now, including recording.

Any way to make it save the player choice? Firefox doesn't seem to like the js players very much. But very nice work, sir. I hope you don't mind if I change the aesthetics a bit!
 

e7d

New Member
Ignore my previous post, I figured out why it wasn't working. :) I had an .htpasswd enabled, but typo'ed the filepath. Works all as expected now, including recording.

Any way to make it save the player choice? Firefox doesn't seem to like the js players very much. But very nice work, sir. I hope you don't mind if I change the aesthetics a bit!

The player choice is remembered via cookie, but only for a session time lapse, meaning it's lost upon browser close. It's something that could be updated through app.js though.

About aesthetics, you are completly free to adapt everything you way you want. No restriction to state. :)


EDIT: Since i opened a dedicated thread, i will not continue to answer in this thread. Please head to https://obsproject.com/forum/threads/media-streaming-server.15117/ :)
 
Last edited:

Swidtter

New Member
I dont know if anyone can help me. I have set up my rtmp config to look like this

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

                application live {
                        live on;
                        record video;
                        record_path /temp/rec;
                        record_suffix _recorded.flv;
                }
        }
}

What command should I do to download the recoded video file, a pull?
 
is it at all possible to send video to Twitch as normal, but also host a video, but the hosted video is delayed by, say, 5-10 seconds?

Reason: I am working on a way to do an Instant Replay for my stream. Currently, I can just use a Window Capture of our own stream via our Twitch channel, but the delay is so variable it could be 8 seconds, it could be 30.

Being able to send video as normal to Twitch, but have another copy of the feed that has a much lower delay (from my own server) would make this hacked together method of Instant Replay much more "instant"
 
Top