How to set up your own private RTMP server using nginx

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

dk-info

New Member
dk-info said:
My final goal is to show my stream in a webbrowser.
So right now I am trying to set up an internal webserver to show the stream with JW player.
I have not yet figured out the right setup for the webserver but am working on it.

And it wasn't as hard as I feared. :o)

I just installed another ngnix-server, put the JW-stuff in the 'html' folder ... and there you go.
And it is running without problems in the JW-player, not pausing like the VLC.

Now I can finish my project in time. Great!
 

dodgepong

Administrator
Community Helper
dk-info said:
I could not install latest nginx (1.4.1) - but 1.2.9 worked.
I've heard some people having problems with the 1.4.x releases following this guide, and some people who haven't...I'm not sure what's up, as I haven't bothered to upgrade from 1.2.7 myself. I'd like to hear if others are able to get 1.4.x working.
 

ExitSign

Member
Using nginx / rtmp module, is this setup possible?

PC1 and PC2 are in the same LAN.

PC1 - gaming pc, streams at very high bandwidth to PC2.
PC2 - save original stream locally (for after editing) and re-encode (at lower bitrate) to ie. twitch.tv

Is it true, that using a higher bitrate, it stresses the cpu less to get the same quality? If so, this would be a nice alternative to a capture card also.
 

dodgepong

Administrator
Community Helper
Streaming at a high bit rate doesn't necessarily mean less CPU usage. It means you can get high quality while not using an intense preset, but it's still not exactly the same.

I wouldn't know how to set up the re-encode...you'd probably have to use ffmpeg for that and somehow configure nginx to run its input through ffmpeg for the re-encode. It might be possible if you want to investigate it. But I don't think it's going to work out like you want in terms of quality and load reduction.
 

jhn123

New Member
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.

3hyc.png


Here's the template:
http://www.speedyshare.com/TZ87R/LiveStream.zip


Select your Ubuntu image and go to settings>Network
3gj.png

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
h6jp.png

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.
c54g.png
 

jhn123

New Member
Stream with HLS

HLS can work with VLC natively so you don't need rtmp dump to playback your live stream.

Note: HLS has about a 30 second delay.

Nginx.conf
Code:
#user  nobody;
worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {

    server {

        listen 1935;

        application myapp {
            live on;
            hls on;
            hls_path /tmp/hls;
            hls_fragment 3s;
            hls_playlist_length 10s;
            hls_sync 200ms;
            allow publish all;
            allow play all;
        }

    }
}

# HTTP can be used for accessing RTMP stats

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

# ~test these later
#    sendfile        on;
#    keepalive_timeout  65;

    server {

        listen      80;
        server_name  localhost;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html{
            root   html;
}

        # This URL provides RTMP statistics in XML
        location /stat {
            rtmp_stat all;

            # Use this stylesheet to view XML as web page
            # in browser
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            # XML stylesheet to view RTMP stats.
            # Copy stat.xsl wherever you want
            # and put the full directory path here
            root /usr/build/nginx-rtmp-module;
        }

        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
            }
            alias /tmp/hls;
            expires -1;  
        }

    }
}
OBS Broadcast Settings
Mode: Live Stream
Streaming Service: Custom
Server: rtmp://Ubuntu_IP_HERE/myapp
Play Path/Stream Key (if any): livestream


You can view the stream here:
http://IPADDRESSHERE/hls/livestream.m3u8
 

jhn123

New Member
1.4.1 Nginx not compiling fix

dk-info wrote:
I could not install latest nginx (1.4.1) - but 1.2.9 worked.
Nginx 1.4.0+ you need to add --with-http_ssl_module

./configure --add-module=../nginx-rtmp-module-master --with-http_ssl_module
 

Calabazal

New Member
Hi let me start by saying it's a great guide, all working with no problems at all and already had fun with tweaking little bits here and there! However I'm looking to further what your guide has started by streaming the video to a web based player instead of through programs like VLC media player and wondering if anyone knew how to progress to that?

Is there a guide to further my knowledge on how to do that anywhere or could there be some light shed on how I could go around doing that? From what I gather It'll need to be something like adding the Adobe Flash Media Live Encoder plugin to Linux and then from there have a file that has a video player?
 

dodgepong

Administrator
Community Helper
JWPlayer is a basic Flash video player that you can set to point at an RTMP URL.

You shouldn't need to install a video decoder on the server. The client program (the viewer) should be able to do that all. Unless I'm confused as to what you're trying to do.
 

mkdr

New Member
Why Linux, why a VM? Why not a Windows build of nginx? Could someone please build a copy of nginx with that module for Windows, or is there already one somewhere?
 

mkdr

New Member
o_0 ... What does that have to do with what I said?? It's stupid to use a VM with a whole Linux JUST to run that single nxginx. Therefor... someone should build a win32 compilation of nxginx with that module.
 

Kharay

Member
You're not getting the point; there is no need to build a Win32 nginx. There is an existing cross-platform media server that is also Open Source and free to use.

If you actually had read what I had said and had bothered to investigate the matter you would have found out that nginx on Win32 has been researched but at the moment it is very much in a Beta state at best and does not render the performance you would need from a media server.

At least far less than simply using a media server written in Java.
 

mkdr

New Member
Omg. No o0 YOU are not getting the point.

But anyway. How can I check if nginx was build succeessfully with the modul? I cant connect from Open Broadcaster, it says: "RTMP_Connect(), failed to connect socket", so I guess there is just no RTMP server running. Is there any debug methode to check if my nginx executable has the module build into?
 

dodgepong

Administrator
Community Helper
mkdr, Kharay is suggesting an alternative to nginx. Red5 is an RTMP server that runs on Windows so you don't need to use nginx or follow this guide.

As far as I know, there is not a version of nginx with the RTMP module compiled in with it. Unless you want to compile it yourself, then you're pretty much forced to use Linux if you want to use nginx with the RTMP module. Using a VM is a nice way of keeping Windows as your primary OS but still have nginx accessible.

As for the error you're getting, did you follow the guide? Did you get an error when compiling nginx or installing it? Did you make sure you configured the RTMP server in the configuration file? And did you make sure you started nginx after saving the configuration options? You also might want to double check to make sure your RTMP URL is correct, including the right port.
 

mkdr

New Member
You both dont get what I wanted to say, but, like I also said, <anyway>.

Yes of course it is running /: And it seems the module is build into it, otherwise the rtmp { would produce an error that it's unknown. But I just get this when I want to connect:

oAd4Jjv.gif


The compilation had to work, otherwise it would have not made an ipk file. Do I have to copy anything from the module directory somewhere too?

config file:

Code:
user nobody nogroup;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
error_log  error.log debug;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

rtmp {
        server {
                listen 1935;
                chunk_size 4096;

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

And it's running,

6452 root 7048 S nginx: master process /usr/sbin/nginx
6453 nobody 7256 S nginx: worker process
6455 root 1500 S grep nginx

url: rtmp://10.0.0.201/live
 

dodgepong

Administrator
Community Helper
Can you post your nginx.conf file and the RTMP URL you are using? (Feel free to censor the server address)

EDIT: Oops, you edited your post with the conf file while I wrote this.

Does specifying port 1935 in the RTMP URL help at all? Does your server have a firewall that might be blocking the connection somehow?
 

mkdr

New Member
No. I also tried to change the port to 1936, and use rtmp://10.0.0.201:1936/live which results in the same error message above. If I change the port, just for testing, just on the client, to another like 1937, I get this:

u1Cb13f.gif


So there server is there on port 1936, but not working.
 

dodgepong

Administrator
Community Helper
So when you were running on 1935 and specifying no port, it looked like it was hitting the server but the server was returning the stream key error. What are you specifying for your stream key?
 
Top