How to set up your own private RTMP server using nginx

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

dodgepong

Administrator
Community Helper
You are reloading the nginx config after changing it, right? And you're entering the RTMP server and stream key in correctly?
 

OriginDev

New Member
yes on reloading. Rebooted each of the servers a few times as well and then restarted nginx. no change.

The settings in OBS are:
Streaming Service: Custom
Server: rtmp://ip.address/live
Play Path/Stream Key: test

Is there a specific release of nginx I need to use? I've tried 1.8 as well as the version referenced in this post.

Looking for log files I can check or command scripts I can run that would indicate anything regarding why it isn't working.
nginx is running, I can load pages. Even did one with JW player embedded. However, the rtmp module doesn't appear to be working. Not sure what is holding rtmp up and don't know how to trace it down.
 

OriginDev

New Member
For the google VM, I canguess that Google is blocking the traffic. For the local VM, no idea, RPi started working once I recompiled with --debug and made no other changes. Not sure why turning Debug on made a difference, but apparently it does.
 

Josue Panada

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


****************************************************************************************************************************
rtmp works fine for me,,, but HLS does not, can you help me? when I try pasting the http://198.168.15.10/hls/livestream.m3u8 into safari from my mac computer, it does not recognize the rest of the path, just the IP
 

Jack0r

The Helping Squad
Nginx needs to be build with the rtmp module selected as described in the guide, so you would need to do that and replace your installed version with the build.
 

JOY

New Member
I have one problem. If I follow the guide, I cannot start nginx:
[root@JPlay nginx-1.9.2]# systemctl status nginx.service nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Sun 2015-06-28 17:11:51 UTC; 33min ago
Docs: http://nginx.org/en/docs/

Jun 28 17:11:51 JPlay systemd[1]: Starting nginx - high performance web server...
Jun 28 17:11:51 JPlay systemd[8674]: Failed at step EXEC spawning /usr/sbin/ng...ry
Jun 28 17:11:51 JPlay systemd[1]: nginx.service: control process exited, code=...03
Jun 28 17:11:51 JPlay systemd[1]: Failed to start nginx - high performance web...r.
Jun 28 17:11:51 JPlay systemd[1]: Unit nginx.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.

If I use yum -y install nginx to install nginx, I can start it normally.
I'm using CentOS 7.1 with nginx 1.9.2

Thanks,
Giang Anh
 

EpicLPer

New Member
Not sure if anyone here mentioned it already (searching in threads is a nightmare here) but this won't work with the RTMP function the DJI Pilot App offers you.
I tried to set up a stream for me flying around my drone/quadcopter and the DJI Pilot App gives a function to stream to an RTMP server. However it won't allow me to set a Stream Key nor does it allow to stream to "..../live/test" (as you showed in your tutorial). Always says "Streaming initation error!" when trying to start the stream.

(The "YouTube Live Streaming" isn't right here. It's indeed an RTMP Stream.)
OtL2qAA.png
 

sneaky4oe

Member
For some reason my twitch stream gets constantly disconnected when I'm streaming through my laptop.
Config:
pc -wire-> router -wire-> laptop -wifi-> neighbour's router -> platforms.

Encoding setup:
exec ffmpeg -i rtmp://localhost/restream/ -vcodec libx264 -preset veryfast -b:v 1700k -maxrate 1700k -bufsize 2000k -s 1280x720 -sws_flags lanczos -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -r 30 -acodec copy -f flv rtmp://localhost/lowered720/;

Is it wifi stability issue or what? Hitbox and other services work just fine.
 

makarios

New Member
Hey guys, I got the server working great and all but I'm having one serious problem. When I stream 1 computer to the server it runs flawlessly but once I stream multiple computers to the server OBS will just close out of nowhere and stop everything. Is this just a software issue, OBS can't handle that many computer streams?

ex. Computer 1 streaming game to Server
Computer 2 streaming game to Server
Computer 3 streaming game to Server
Crash
Restart

Stream lasts anywhere from 1 to 30 seconds
 

David_V

New Member
Hi,

Thank you for this fantastic tutorial! I'm doing some test and I have a problem when I try to broadcast my screen. My speed is 50MB/5MB (I think that it is enough to broadcast a 720p signal) and my server has 100MB/100MB, so it should be enough to broadcast to 1 o 2 viewers for now.

The problem is that every 60 seconds, almost 10 seconds I have a freeze image and the audio continues playing. So, do you have any suggestion? I tried on two different servers (in the same network, OVH) and it happens in both.

Thank you in advance!
 

Turro

New Member
im trying to follow the steps for windows, here comes the problem; at the beginging, i cannot get into de nginx directory, could you specify the steps fro windows? I get the nginx is correctly instaled, but i cant get the RTMP to get connected with it, any help? thx
 

Kuckeli

New Member
Hey, how do i reload the config if i use the steps mentioned in the guide? Everything i find online doesn't seem to work.
 

Jack0r

The Helping Squad
arut once said that the nginx reload feature does not fully work with the rtmp module, so he recommends to close nginx and restart it to load a new config.
 

york

New Member
i want determinded specified bitrate from nginx to twitch.tv like, obs to rtmp lan server 10kbitrate/10kbuffer and nginx to twitch 2500/2500 can perform it?
 

Jack0r

The Helping Squad
Nice! But how i can change the key? (test by default)
Thank
In general you can use whatever key you want, you need to know it to watch the stream though. Unless you add some security to your nginx server, anyone can stream to it with any streamkey.
i want determinded specified bitrate from nginx to twitch.tv like, obs to rtmp lan server 10kbitrate/10kbuffer and nginx to twitch 2500/2500 can perform it?
You would need to add an exec function that starts ffmpeg to your nginx config. That converts the incoming stream to the mentioned 2500kbit and can send it to Twitch.
 

David_V

New Member
Hi,

Thank you for this fantastic tutorial! I'm doing some test and I have a problem when I try to broadcast my screen. My speed is 50MB/5MB (I think that it is enough to broadcast a 720p signal) and my server has 100MB/100MB, so it should be enough to broadcast to 1 o 2 viewers for now.

The problem is that every 60 seconds, almost 10 seconds I have a freeze image and the audio continues playing. So, do you have any suggestion? I tried on two different servers (in the same network, OVH) and it happens in both.

Thank you in advance!

Any help for this post? Thank you!
 
Top