How to set up your own private RTMP server using nginx

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

malone76

New Member
macharborguy said:
well I did the recompile with the latest rtmp module, set it up using "meta copy", but it is still unable to broadcast to UStream. On a side note, I do have it set up to broadcast to YouTube Live, Twitch and Hashd.tv successfully at the same time.

I read a few pages past this post and saw that nobody answered your question about ustream. It can be done, you just have to specify things. My app will take my input and stream to my website, ustream, livestream

This should get you going with a push to ustream
Code:
 application xxxxx {
                live on;
                meta copy;
                record off;
                push rtmp://1.XXXXXXX.fme.ustream.tv app=ustreamVideo/XXXXXXX name=incomingstreamname playPath=ustreamsessionkey;
        }

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"
 

ventea

New Member
First off, this guide has been great in helping me get an RTMP server setup. As someone very new to linux and such, it has been pretty straightforward to follow.

I'm trying to stream to twitch and youtube simultaneously, and having some problems. I have the RTMP server set up on a Raspberry Pi. It works fine for a while (sometimes 5 minutes, sometimes 20 or more minutes), and then the transfer rate that OBS shows in the bottom right corner begins to fluctuate, then the stream disconnects. Sometimes it comes right back, and is stable again, sometimes I have to restart my RTMP server to get it back. Occasionally only the youtube stream comes back and the twitch stream doesn't work until I restart the RTMP server...

I have just finished verifying that streaming to only twitch through the RTMP server works for about an hour, I am satisfied that works. Streaming to twitch straight from OBS also works. When I streamed to youtube only through the RTMP server, it disconnected after about 20 minutes. I am currently running a test streaming direct to the youtube channel through OBS, not the RTMP server. Here are the lines in my nginx.conf file to push to my streams.

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

        application live {
              live on;
              record off;
              push rtmp://live.twitch.tv/app/[streamkeyfromtwitch];
              push rtmp://a.rtmp.youtube.com/live2/[streamkeyfromyoutube];
             }
       }
}

Is it possible that I am just surpassing the amount of data that the Raspberry Pi can transfer? I have tried different bitrates, and it seems like even if I make the rate very low, I still have the instability problems. My internet is 10 Mbps upload, I do not think I am maxing that out. Plus the fact I get the disconnect on youtube and not on twitch when I run only one at a time, makes me skeptical the Pi is the problem.

If anyone has any insight on what might be happening, please let me know. I'd be happy to post any further information you request, although I will warn you I am very inexperienced with linux, so I may need instruction on how to get to/post any log files or anything like that.

Thanks for your time,
Ventea
 

Carefoot

Member
Can I use this to cast to YouTube & Twitch.TV at the same time? I want to build a twitch following, but I prefer YouTube for VODS.
 

Fenrir

Forum Admin
Just wanted to say thanks to everyone who put work into this. Got one set up and working perfectly.

Does anyone have a decent tutorial on how to set up transcoding? That's the last piece I'm still trying to do. I found a few suggestions to use VODServer (http://vodserver.sourceforge.net/), but curious if there's a better way. I tend to avoid Java applications as a rule of thumb as they are very resource hungry.
 

Fenrir

Forum Admin
Jack0r said:
http://www.helping-squad.com/wp/server/
or to be more precise: http://www.helping-squad.com/wp/transco ... ith-nginx/

You can also use nginx to host VoD's, but I havent looked into that yet. Probably best to check the nginx-rtmp-module github wiki :D

Excellent, thanks for the links!

Next challenge is how to snag viewer count. Any advice on how I can get that? Anything on the wiki? Done a little searching but haven't found much. I have a little experience with web development stuff, and I'm a quick study, but a lot of this is over my head still. Set this up to learn more than anything. :)

Basically, I'd like to try and emulate Twitch (more as a personal experiment than anything else) at the basic functionality level, learning the different systems as I go and how to integrate them, heh.
 

malone76

New Member
You could add the stats.xsl from the test/ directory to the nginx/html directory and pull the stats from the xml. Should be easily doable to parse the info out of it.
 

Fenrir

Forum Admin
malone76 said:
You could add the stats.xsl from the test/ directory to the nginx/html directory and pull the stats from the xml. Should be easily doable to parse the info out of it.

Hmm, I can't seem to get this to display properly. I set it up per multiple setup guides I found, but the output doesn't display properly in the browser. Looks like the xsl is not being loaded into the browser, and I can't figure out for the life of me why not.
 

malone76

New Member
Backup your current nginx.conf file and then replace your http {...} section with this. Make sure the location "root" option points to the correct location of your html. Mine for instance are in the /usr/local/nginx/html directory on my server. This setup also assumes you don't have anything on port 8080, but this works for me (Ubuntu 12.04 vps server). You can also comment out/remove the control section if you don't want to use the web-based control of the rtmp module.

Code:
http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;

        # rtmp stat
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            # you can move stat.xsl to a different location
            root /usr/local/nginx/html;
        }

        # rtmp control
        location /control {
            rtmp_control all;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/nginx/html;
        }
    }
}
 

phils

New Member
This product and thread seems as if it may be a solution to a configuration need but would like to verify before spending the time trying to implement, (it will entail a major learning curve).

Scenario: Printing department serving 3 locations + its own.
Input: Four LAN computers, (running XP PRO with VGA connectors) running different instances of the same MIS application each with it's own job status window. Three connected to remote locations through VPN tunnel.
Output: One large screen monitor/TV (37-40"+) on LAN approx 20' or 75' away depending on final layout.
Preferred Layout: Stacked with simple dividing graphic (location name) rather than 4 corners, (though not a deal killer).
Video: Normal computer monitor feed without concern for lag time.
Audio: None Required

Old P4 computer re-purposed with Ubuntu server to run OBS and RTMP, JWplayer or VLC as needed.

Is this doable and the right approach or is there a simpler solution?
 

dodgepong

Administrator
Community Helper
This product and thread seems as if it may be a solution to a configuration need but would like to verify before spending the time trying to implement, (it will entail a major learning curve).

Scenario: Printing department serving 3 locations + its own.
Input: Four LAN computers, (running XP PRO with VGA connectors) running different instances of the same MIS application each with it's own job status window. Three connected to remote locations through VPN tunnel.
Output: One large screen monitor/TV (37-40"+) on LAN approx 20' or 75' away depending on final layout.
Preferred Layout: Stacked with simple dividing graphic (location name) rather than 4 corners, (though not a deal killer).
Video: Normal computer monitor feed without concern for lag time.
Audio: None Required

Old P4 computer re-purposed with Ubuntu server to run OBS and RTMP, JWplayer or VLC as needed.

Is this doable and the right approach or is there a simpler solution?
I'm not exactly sure what you're trying to do here, but I can't imagine OBS would be a better solution than using a computer with several RDP instances running in different corners of a monitor.

Furthermore, OBS currently does not run on XP or Ubuntu, so you're going ot have a pretty hard time using OBS on those machines.

Finally, OBS transmits video by doing real-time h.264 video encoding, which none of those computers would be powerful enough to perform in a high enough resolution.

So no, I don't think this is the tool you're looking for.
 

Dennis

New Member
Hello there!

That's a fantastic guide. I will definitely give it a try one day. I am running a couple of Linux servers but both of them are on apache with a 'long delayed' plan to switch one server over to nginx. Now this delayed plan will speed up I guess :-)

I have a couple of pretty straight forward questions though.

1.) How many concurrent long-term connections would setting RTMP module on nginx allow me to have?

Currently, I easily stream my live IP camera using a very simple function of JavaScript without any help of video servers at all. It broadcasts live on 99% of all known browser capable devices including RTMP, HLS, RTSP and so on. The refreshed snapshots method allows to have up to 80 concurrent short-term connections if I am not mistaken. However, the long-term concurrent connections are only limited to 5. Now this is the main point why I would like to try to run RTMP server, that is to increase the number of concurrent long-term connections and (my second point) to have more control over it all. Now things like DoS attacks, iptables rules and so on will be under my control, is that not right? The camera is on my local network with ports forwarded externally which in turn makes my camera accessible from the Internet and thus my camera's external IP becomes my ISP's IP. This is also what bothers me. Do I have to 'attach' my IP camera on my server's network (not my ISP) in order for it to work? For example click2stream.com takes your online IP camera from absolutely any network it is on and somehow creates thousands of concurrent connections for it...

2.) Is it only true about recorded videos of any format? In other words it applies only to recordings doesn't it?

I can also record it as much as I want to but my live streams are really live, they are not recorded in any ways, they are just live all the time and have no 'starts' or 'ends' like recorded movies do.

Would highly appreciate it if someone advised on that. Many thanks in advance!
 

Jack0r

The Helping Squad
1.) the concurrent viewers are mainly limited by your servers upload bandwidth. Nginx can support a huge amount of viewers and even use more than process to support even more. A single process can definitely supply about 1000 people, if not more.
2.) Nginx can be used for livestreaming or Video on demand, both is possible just depends on your setup.

3.) You would have to use a software to send your ip camera as an rtmp stream to the server. Only the server will know your ip address, and the users will only know the server ip. There are different options to secure the server.

I have a small collection of nginx guides on my blog, if you want to see some more examples etc: http://www.helping-squad.com/wp/server/
 

Dennis

New Member
Thank you for your message JackOr. I appreciate your advise. I'll definitely take a look at your collection.

I am pretty much confident as far as Linux is concerned and I can install / do basically anything as long as it is Linux. However, I am not an expert on video and IP cameras. There are two types of concurrent connections short-term and long term. Every single IP camera in the world has limited long-term connections, normally up to 5, but there are many more short-term connections allowed, could be up to 80. The user number 6 that logs in to watch the live stream will automatically bring the camera down because he/she will be number 6 out of 5 allowed. The only way is to restart the camera to drop all the connections. That is that much I have found lately by reading and testing it on my servers. That's why I was wondering how it will be on nginx RTMP module. Concurrent connections in general depend on upload bandwidth all right but what about the types of those connections? I hope I will find that out by testing but I am not sure if I manage to simulate 1000, 2000 and so on connections at the same time to test it all.. perhaps writing another script will help.. My guess also is that nginx's RTMP module won't make a difference whether it is a long-term or a short-term connection so I should be fine on that. Any advises / suggestions in these respects? Many thanks!
 

esevenf

New Member
Hey, great guide - used it to set up a small streaming site for my guild to use.

I have a question and I hope it hasn't been asked before:
Is there a somewhat easy way to see which stream is online at any given time and display that on a website?
 

dodgepong

Administrator
Community Helper
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.
 
Top