How to set up your own private RTMP server using nginx

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

mkdr

New Member
I was using test for the stream key. It doesnt matter what I type in there. I setup a stat http too for debug, with:

Code:
http {
    server {
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root /root/nginx;
        }
    }
}

And I get this:

sV5Qlyt.gif


Accepted changes from 0 to 1 when I try to connect.
 

mkdr

New Member
Log output may help:

2013/07/24 01:02:21 [info] 7349#0: *1 client connected '10.0.0.2'
2013/07/24 01:02:21 [info] 7349#0: *1 too big message: 1048576, client: 10.0.0.2, server: 0.0.0.0:1936
2013/07/24 01:02:21 [info] 7349#0: *1 disconnect, client: 10.0.0.2, server: 0.0.0.0:1936
2013/07/24 01:02:21 [info] 7349#0: *1 deleteStream, client: 10.0.0.2, server: 0.0.0.0:1936

What's too big message: 1048576 meaning?
 

dodgepong

Administrator
Community Helper
I'm not sure, perhaps this is something to ask the creator of the RTMP module about. I've never seen that before, personally.
 

Jack0r

The Helping Squad
http://nginx-rtmp.blogspot.com/2013/06/ ... n-101.html

I've updated the nginx-rtmp code to compile and run on MS Windows. The limitations are

execs are not supported

static pulls are not supported

auto_push is not supported


Moreover the code is now much more portable so it can probably compile on uncommon platforms not supported earlier.

UPD: Nginx for Windows compilation guide
Add RTMP module with the usual option --add=module=PATH/TO/nginx-rtmp-module

UPD2: You can use Microsoft Visual C++ 2010 Express to compile nginx. It's free. Download it from Microsoft web site.
Posted 13th June by Roman Arutyunyan
 

mkdr

New Member
@Jack0r why mentioning this, it doesn't 'make sense' to use a win32 build of nginx like I suggested, all other people on here are saying, because there's already this 'awesome' red5, and hey, why using a win32 build, when you have vm's, right (;

@Kharay not the same problem. Ive already contacted the author, I hope we can handle it out why it's not working.
 

dodgepong

Administrator
Community Helper
Cool, I didn't know he was working on a Windows build. That's a new development.

mkdr, I never said having a Windows version didn't make sense. I said that I didn't know of a Windows version that already existed and you would probably have to build it yourself (not knowing that the author was already working on a Windows version). I don't think Red5 is awesome - I've avoided using it because the impression I get from it is that it's difficult to use and poorly documented - but as far as I knew, it was the only FOSS solution for hosting a Windows-based RTMP server, which is why Kharay and I suggested you try that instead of messing with nginx on Windows, which I anticipated could get ugly.

Also, running a VM for the sole purpose of operating a simple server is extremely common practice. It is done all the time in professional production environments. A lot of servers you use these days are just VMs. Heck, EC2 practically runs the entire internet these days, and that is all based on virtualized servers. Running a single-purpose server is not unreasonable at all, and is standard practice for many people these days.
 

mkdr

New Member
I get lots of "VLC does not support the audio or video format "undf" messages, sometimes it works, but then I also have like every 15 seconds a stop for a few seconds. What could be the reason for this? Also using that HLS plugin spams my tmp folder with ts files and does not delete them, it's not usable too because of that 30 seconds lag :/

--
I have build a win32 compilation, if someone wants it to test it out, pm me.
 

mkdr

New Member
So the linux version has the same behaviour like the windows one, thought it was a windows issue, but no. No one has noticed this? It's mostly unusable, it's just luck if you can connect with rtmpdump + vlc, I mostly always get this undf error message for the video. Also the stream stops every few seconds if it's "working".
 

Jack0r

The Helping Squad
Hmm, couldnt reproduce this error, but vlc + rtmpdump isnt working that great for me anyway.
I used the jwplayer on a webpage for a short 3 hour test and had not a single framedrop or lag. But I would be interested in the w32 version, could you message me a link maybe? Had problems getting it build so far.
 

dodgepong

Administrator
Community Helper
VLC + RTMPdump isn't a permanent solution, just one way of many that you can test to see if it's working. When I tested it a while ago, I had no problems with it, but I don't use it as the primary way of consuming custom streams, nor do I recommend it. Do you have the same problems consuming the stream with something more reasonable, like JWPlayer?

Maybe I should update the OP to remove the RTMPdump stuff altogether, since I only mentioned that due to the fact that I didn't feel like taking the time to get JWPlayer set up for general use...
 

mkdr

New Member
I had lots of problems building the w32 vesion too, because the howto on the page of the modules author is incorrect and incomplete, but I finally made it after some hassle. Like I said, send me a PM and Ill give you a link, or I can help you building it if you want. I tested it for some days, but gave it up, it just was too unstable with VLC and rtmpdump. I thought then that it was because of the w32 version, but I have the same behaviour with the linux build too. So both Linux and W32 aren't working for me, and I question why, and why it seems to work for everyone else here? It can't be related to VLC+rtmpdump, because I use rtmpdump for other rtmp streams, and it works flawless. So the problem is in nginx/the module. I spoke with the author, but he wasnt any help at all.

@dodgepong, maybe can you post a short howto for setting up JWPlayer then? I would want to test that out as my last resort.

--edit:

Omg... It's working with JWPlayer -.- But I don't understand, why it is isn't with VLC+rtmpdump. Seems the module has some kind of incompatibilty somewhere. But all other streams I've tried before are working that way...

So, nginx w32 build seems to work for me (=
 

Yamato64

New Member
Thanks a lot Dodgepong for this awesome tutorial.
I have been using Nginx on my VPS only to push RTMP on several platforms like Twitch Dailymotion and Youtube and it's nearly perfect.

Now, i need to adress to issues with Twitch
-When Twitch get the video, which is 720p, in the transcoder it's listed as "Best" instead of "720p+" (all other transcoding options are fine, 480 and 360) It not trouble
-On a particular Twitch Channel (Gamekultlive) when i start streaming with nginx pushing the stream (only push, no recording), after a short while, Twitch stream freeze a little bit and transcoding is gone, people can only chose "best". I have to stop stream and start again on Open Broadcaster (or Xsplit, tested with both). Testing without the RTMP server, it doesn't happen. Even more strange, sometimes the transcoding option on Twitch is gone forever, and the only way to get it back is asking for a new key on Twitch.

I must say i'm pretty lost on these 2 things, especially since Youtube and Daily are doing just fine. Thanks in advance for any tip on the matter !
 

dodgepong

Administrator
Community Helper
Sounds like a Twitch issue to me. If you're only using the passthrough from the RTMP server to Twitch, then the data should be exactly the same from OBS as from your server.

I don't know the details of Twitch's partner/transocde system, but one thing I've heard is that you might not get all transcode options if you don't have many viewers. I'm not certain, though.

EDIT: Indeed, it seems that Twitch is having problems with transcodes: https://twitter.com/TwitchTVSupport/sta ... 1369628672

EDIT 2: More things relevant to your interests: http://blog.twitch.tv/2013/08/major-cha ... transcodes
 
Hi all,

im using the win nginx build from mkdr and it's working good for me but im having some troubles getting some config's done, and perhaps someone can point me in the right direction.

I'm trying to get the recording done but for some reason it doesn't seem to record anything.

Here is what i have done so far:

nginx.conf:

Code:
#user nobody nogroup;
worker_processes  1;

error_log  logs/error.log debug;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include mime.types;
    default_type application/octet-stream;
    keepalive_timeout 10;
    server {
        listen 8185;
        server_name localhost;

        location /on_play {
            return 201;
                           }
        location /on_publish {
            return 201;
        }
        location /vod {
            alias /temp/records;
        }
        location /control {
            rtmp_control all;
        }
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root c:/Users/Gebruiker/Desktop/nginx_rtmp_w32/html;
        }
     }
}
rtmp {
    server {
        listen 1935;
        ping 30s;
        chunk_size 4096;
        notify_method GET;

        application live {
            live on;
            allow publish all;
            allow play all;
            on_play http://***.***.***.***:8185/on_play;                                             
            recorder rec1 {
                record all;
                record_path c:/Users/Gebruiker/Desktop/nginx_rtmp_w32/html/temp/records;
                record_unique on;
             }
                   
        }
        application vod {
            play /temp/records;
        }
        application vod_http {
            play http://***.***.***.***:8185/vod/;
        }
    }
}
index.html:

Code:
<!DOCTYPE html>

<head>
<title>LAN Broadcaster</title>
<script type="text/javascript" src="jwplayer/jwplayer.js" ></script>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
</head>
<body>
<table>

<tbody>
<tr> 
<td>
<div id="my-video"></div>
<script type="text/javascript">
    jwplayer("my-video").setup({
        file: "rtmp://***.***.***.***:1935/live/flv:test",
        height: 540,
        autostart: true,
        image: "/Images/offline.jpg",
        width: 960,
        controls: true,
        mute: true,
        stretching: "exactfit",
    });
</script>
</td>
<td>
<div id="my-video1"></div>
<script type="text/javascript">
    jwplayer("my-video1").setup({
        file: "rtmp://***.***.***.***:1935/live/flv:test1",
        height: 540,
        autostart: true,
        image: "/Images/offline.jpg",
        width: 960,
        controls: true,
        mute: true,
        stretching: "exactfit",
    });
</script>
</td>
</tr>
<tr> 
<td>
<div id="my-video2"></div>
<script type="text/javascript">
    jwplayer("my-video2").setup({
        file: "rtmp://***.***.***.***:1935/live/flv:test2",
        height: 540,
        autostart: true,
        image: "/Images/offline.jpg",
        width: 960,
        controls: true,
        mute: true,
        stretching: "exactfit", 
    });
</script>
</td>
<td>
<div id="my-video3"></div>
<script type="text/javascript">
    jwplayer("my-video3").setup({
        file: "rtmp://***.***.***.***:1935/live/flv:test3",
        height: 540,
        autostart: true,
        image: "/Images/offline.jpg",
        width: 960,
        controls: true,
        mute: true,
        stretching: "exactfit", 
    });
</script>
</td>
</tr>
<tr>
<td>
<object data=http://***.***.***.***:8185/stat width="900" height="400"> <embed src=http://***.***.***.***:8185/stat width="600" height="400"> </embed> Error: Embedded data could not be displayed. </object>
</td>
</tr>
</tbody>
</table>
</body>
</html>

stylesheet.css :

Code:
body {
          border: 0px;
          border-spacing: 0px;
          border-color: black;
          padding: 0px;
          margin: -2px;
          background-color: black;
          overflow-y: hidden;
          overflow-x: hidden;
          }
tr      {
          border: 0px;
          border-spacing: 0px;
          border-color: black;
          padding: 0px;
          margin: 0px;
          background-color: white; 
         }         
table  {
          border: 0px;
          border-spacing: 0px;
          border-color: black;
          padding: 0px;
          margin: 0px;
          background-color: white;
         }

Please keep in mind that i'm a beginner with coding:
I only managed to get this all by teaching myself on codeacademy.com in the last couple of days.
But it's a LOT to learn :) and after a 100+ excercises i got a bit weary and hoped someone could give me advice.

Ah perhaps i should explain the perpous of this setup:
I wanted to make a simple lan server that collects a couple lan streams and display them simultaniously on one webpage so it can be showed on a beamer (full screen webpage).
Currently it's hardcoded for 1920*1080 screens but my plan is to make it also compatible for mobile devices, pushing streams , vod's ect via a neat frontend. But for now im trying to get the skeleton working properly.

It already captures 4 streams and show them properly so im happy that i got that working.
(i know there is still some styling that i have to look into but im already discussing with the guys from jwplayer to see it's caused by their player. I get a 2px border inherited from that jwplayer that i can't seem to get rid off :S)

Any input is much appreciated
 

Hogie

New Member
Greendweller said:
Code:
        application live {
            live on;
            allow publish all;
            allow play all;
            on_play http://***.***.***.***:8185/on_play;                                             
            recorder rec1 {
                record all;
                record_path c:/Users/Gebruiker/Desktop/nginx_rtmp_w32/html/temp/records;
                record_unique on;
             }
                   
        }

Please keep in mind that i'm a beginner with coding:
I only managed to get this all by teaching myself on codeacademy.com in the last couple of days.
But it's a LOT to learn :) and after a 100+ excercises i got a bit weary and hoped someone could give me advice.

Ah perhaps i should explain the perpous of this setup:
I wanted to make a simple lan server that collects a couple lan streams and display them simultaniously on one webpage so it can be showed on a beamer (full screen webpage).
Currently it's hardcoded for 1920*1080 screens but my plan is to make it also compatible for mobile devices, pushing streams , vod's ect via a neat frontend. But for now im trying to get the skeleton working properly.

It already captures 4 streams and show them properly so im happy that i got that working.
(i know there is still some styling that i have to look into but im already discussing with the guys from jwplayer to see it's caused by their player. I get a 2px border inherited from that jwplayer that i can't seem to get rid off :S)

Any input is much appreciated


Ive actually set this up this weekend (but on Linux)...

My application block looks like this:
Code:
                application xxxxxx {
                        live on;
                        push rtmp://live-dfw.twitch.tv/app/live_thisisprivateyoudontgetit;
                        allow publish aa.bb.cc.dd;
                        deny publish all;
                        record all;
                        record_suffix _%y-%m-%d--%T.mp4;
                        record_unique on;
                        record_path /home/mypathshere/streams;
                }

This makes files /home/mypathshere/streams/whateverthekeyinOBSis-12-08-25--23:21:00.mp4

Since I have 2 different people streaming to the nginx server, I actually have application for each of us.

With jwplayer, I used:

Code:
jwplayer("myElement").setup({
   file:  "rtmp://hosthere/appname/flv:whateverthekeyinOBSis",
   height:  720,
   width:  1280
  });

With flowplayer:

Code:
<div data-swf="//releases.flowplayer.org/5.4.3/flowplayer.swf"
    class="flowplayer no-time color-light"
    data-rtmp="rtmp://hosthere/appname"
    data-embed="false">

<video preload="none">
    <source type="video/flash" src="whateverthekeyinOBSis" />
</video>
</div>
 
Thanks for your setup man.
But i have to confess that i apperently managed to get it to work already before i posted all this :(:S

It seems that under win32 it likes the absolute path instead of the relative path.
I already changed that on saturday but forgot to reboot the server -.-'

Scrolling the debug logs showed that it was solved properly for a while already. But i was just to wasted to noticed it.

Well up onto the next step in my project...: making an rss feed that auto populates all recorded vid's so i can use it as a playback list for jwplayer.

**EDIT**

found out that if i use
record_suffix _%y-%m-%d--%T.mp4;
it crashes my nginx.exe.
Why i dont know (yet) but removing that line and leaving it on unique makes it work.
Guess its a syntax thingy linux vs win or something.
 

Hogie

New Member
hah. That's fine. I was just browsing last night and decided to register to answer. I should have registered earlier instead of just lurking.

The problem I have is that our twitch.tv streams look fine (when forwarded from the server), but jwplayer and flowplayer both are not keeping up with 720 streams.... (twitch marks them as best in the new system). I tried both the html5 and flash players of those two, but still seems like they are dropping frames when we get into high movement moments (Payday 2, Saints Row IV). I can have 1 browser open on each monitor, and the twitch stream is fine, but the other two go jerky randomly:\
 
Top