How to set up your own private RTMP server using nginx

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

jagr_200

Member
This has to be one of the most frustrating things I have ever tried. I've been at this for almost 6 hours now.

So where I am....

I created a DNS name at freedns.afraid.org and pointed it to my public IP address as found at whatismyip.com.

I then changed the JW player information to point to that as follows :

<script src="http://jwpsrv.com/library/fyzhtoNSEeSbtQoORWfmyA.js"></script>

<div id='playerJbqgIkraQqGt'></div>
<script type='text/javascript'>
jwplayer('playerJbqgIkraQqGt').setup({
file: 'rtmp://XXXXXXX.mooo.com/live/test',
image: '//www.longtailvideo.com/content/images/jw-player/lWMJeVvV-876.jpg',
width: '100%',
aspectratio: '16:9',
autostart: 'true'
});
</script>

I've embedded that on my website and it works when I am on my local wifi network. When I turn on my hotspot and connect to an outside network then it does not work.

I've forwarded port 1935 to the IP address of my Raspberry Pi.

I don't know what else to check.
 

smite

New Member
Mine connects locally and plays back just fine, but doesn't connect over the net for myself or others when we use my real IP. I get connection timeout error 10060 in OBS. Have disabled firewalls and forwarded port 1935, but no change. I'm trying to receive streams from others to combine with my own.
 

jagr_200

Member
Mine connects locally and plays back just fine, but doesn't connect over the net for myself or others when we use my real IP. I get connection timeout error 10060 in OBS. Have disabled firewalls and forwarded port 1935, but no change. I'm trying to receive streams from others to combine with my own.

I'm in the same boat. I've embedded JW player on my website. It loads great on my computer on my LAN. Soon as I connect to a hotspot and try it doesn't work. Working on getting that fixed but I think it is above my knowledge.
 

smite

New Member
I tried it with a different person and they were able to connect. We went ahead and tried it over a VPN as well and that worked too. If I have to use a VPN with some people, I guess that's what I'll have to do. I do need to figure out how to optimize the nginx settings though, was not the quality level I'm looking for.
 

sneaky4oe

Member
Guys, could you please give me links to your vps/vds you're using for transcoding with pricings and setup? I want to buy one for myself, and skip long testing process with getting money back.
 

jagr_200

Member
I tried it with a different person and they were able to connect. We went ahead and tried it over a VPN as well and that worked too. If I have to use a VPN with some people, I guess that's what I'll have to do. I do need to figure out how to optimize the nginx settings though, was not the quality level I'm looking for.

Were they streaming to you or viewing your feed? How were they viewing it?

Well after 50+ hours on this I think I'm about to throw in the towel. If anyone wants to buy a Raspberry Pi B+ message me. I can't get the feed to push outside of my LAN and if I can't do that I can't use the system. I've exhausted myself to the point where I'm not enjoying this anymore. So if anyone has any insight that would be appreciated.

Wahooo! I got it running thanks to 014's help! I went through a million plus settings. Turns out my Xbox 1 was conflicting with the rtmp server. They both use Port 80. So I had to move the xbox one off of that port for the time being.

Dodge - You recommended Linode. I'm looking at their services and it looks good. How many viewers would I be able to have it I went with a Linode 2gb service? Also do I build this RTMP server on their device remotely?

I'm impatient so I started building one using Linode as my host. I'm building it in Ubuntu 14.04 LTS system. I keep getting a [waiting for headers] and it seems to hang. I'm also running into a few 404 errors.

Has anyone built one using Linode?

Dodge - I'd let you take it for a test run and try and build it out if you wanted to help add to this writeup.

So I'm impatient. I built the RTMP server on Linode. Working great. Funny. The thing that took me 50+ hours to get working on my Raspberry Pi only took me about 45 minutes to make remotely. It works perfectly. Very happy with the results.

That said so far I can't recommend Linode enough. You don't have to deal with forwarding ports or anything. Just follow the step by step instructions and you are done. So easy.
 
Last edited by a moderator:

jagr_200

Member
Ok, guys. I've made a transcoding 6-core server at http://server4you.net (5EUR/month first 6 months, than 15 EUR). Looks like one of the cheapers servers out there with 6 cores.

exec_static ffmpeg -i rtmp://localhost/restream/1234 -vcodec libx264 -preset veryfast -b:v 2200k -maxrate 2400k -bufsize 4000k -s 1280x720 -sws_flags lanczos -r 30 -acodec copy -f flv *************;

Demo http://www.twitch.tv/gotchahere186/c/5723437
So, I guess, if you guys need a server for transcoding with decent price and quality (it also allows to stream in higher bitrates too, even 1080p 30fps is acceptable with faster presets), you can use this. I guess...

Or, if you're a Russian or need a server just to restream, go to cloudmouse.com, not sure if it's available in English, but it costs $3.5/month and you get $7 by registering and contacting support.

Unless I missed it I didn't see a bandwidth cap. Is there one? Looks like bandwidth is unlimited.
 

sneaky4oe

Member
Ok, guys. I've made a transcoding 6-core server at http://server4you.net (5EUR/month first 6 months, than 15 EUR). Looks like one of the cheapers servers out there with 6 cores.

exec_static ffmpeg -i rtmp://localhost/restream/1234 -vcodec libx264 -preset veryfast -b:v 2200k -maxrate 2400k -bufsize 4000k -s 1280x720 -sws_flags lanczos -r 30 -acodec copy -f flv *************;

Demo http://www.twitch.tv/gotchahere186/c/5723437
So, I guess, if you guys need a server for transcoding with decent price and quality (it also allows to stream in higher bitrates too, even 1080p 30fps is acceptable with faster presets), you can use this. I guess...

Or, if you're a Russian or need a server just to restream, go to cloudmouse.com, not sure if it's available in English, but it costs $3.5/month and you get $7 by registering and contacting support.
 
Last edited:

Shadowfury333

New Member
I've been playing around with this (mostly based off TimeRocker's guide, but that thread is dead and it's just nginx anyway), and while my setup only uses my one PC (no Raspberry Pi for nginx), I can't seem to get it to stream at a constant rate. Essentially, I push to Hitbox and Twitch, but they are both really choppy/bursty, and looking at Task Manager's Networking tab, I see repeated spikes of network usage. It switches from ~2000kbps to ~6000kbps and back (the target total bitrate, NB that I have 10mbps upload available) every second or so. If I only push to Twitch or Hitbox, I get the same result, but if I stream directly to one, I get a near-constant ~3500kbps.

My nginx settings:

Code:
#user  nobody;
worker_processes  1;
error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                        record off;
                        push rtmp://live.twitch.tv/app/<streamkey>;
                        push rtmp://live.hitbox.tv/push/shadowfury333?key=<streamkey>;
                }
        }
}
 
Last edited by a moderator:

dodgepong

Administrator
Community Helper
You might want to change your stream keys, don't post them publicly or else someone will be able to stream to your channel without your permission. I fixed your post and removed them.
 

Shadowfury333

New Member
Dammit, I thought I had scrubbed them. Thanks for hiding them, though. I've reset both and set OBS and the nginx.conf file to use the new ones.
 

harakiwi

New Member
found a bug: After your internet crashed and you're able to reconnect to your VPS/server the stream won't work (using the same streamkey) because of a new ip?

Steps to reproduce:

  • crash your internet, after some time your ISP reconnects you.
  • streaming via the previous key isn't working
  • now, kill nginx
  • restart nginx
  • stream works again
 
Last edited:

illmtk

New Member
edit: holy shit I figured it out. Using Oracle VM, I changed the network type from NAT to Bridged. Fuuuuuuck


Alright so I have a hit a wall. Got everything setup on my 2nd pc, the streamer--ubuntu vm, installed nginx, configured files, etc. But now having problems with the 1st pc, the gamer, specifically the FMS url in the OBS settings and how it keeps telling me either 1) The connection is timed out. Try a different server, or check that connection is not being blocked by a firewall or other security software. or 2) "FMS URL" is offline. Try a different server. It will connect for 20 seconds or less without sending any data and the error messages will pop up. I tried all sorts of combinations for the FMS url. What exactly am I putting in the FMS URL? I've disabled all firewalls, and I have fowarded ports.

Here is my config file for nginx:
#user nobody;
worker_processes 1;

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

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


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

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

rtmp {
server {
listen 1935;
chunk_size 4000;

application transcode {
live on;
record off;
exec ffmpeg -re -i rtmp://localhost:1935/transcode/test -vcodec libx264 -preset medium -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -r 30 -b:v 2000k -maxrate 2000k -bufsize 2000k -threads 12 -s hd720 -sws_flags lanczos -acodec copy -f flv rtmp://localhost:1935/live/test;
}
application live {
live on;
record off;
push rtmp://live-dfw.twitch.tv/app/"twitch key";
}
}
}

Sorry if there is a simple solution. Thanks.
 
Last edited:

Jack0r

The Helping Squad
@illmtk, you mailed me too right? Guess Ill answer you here then. You need to find out your local network IP of the 2nd PC and stream to that ip. The FMS URL would be rtmp://local.network.ip/transcode and your streamkey test.
On the 2nd PC you can open a command prompt in windows and enter ipconfig. Then search for your network adapter and the ipv4 address. Its often something like 192.xxx.xxx.xxx or 5.xxx and so on. You also have to make sure your VirtualMachine is reachable from your network. I think bridge mode works for most VM software (google around a bit to find out how to setup your vm software).
Oh, and now I noticed your edit :D
 

illmtk

New Member
@illmtk, you mailed me too right? Guess Ill answer you here then. You need to find out your local network IP of the 2nd PC and stream to that ip. The FMS URL would be rtmp://local.network.ip/transcode and your streamkey test.
On the 2nd PC you can open a command prompt in windows and enter ipconfig. Then search for your network adapter and the ipv4 address. Its often something like 192.xxx.xxx.xxx or 5.xxx and so on. You also have to make sure your VirtualMachine is reachable from your network. I think bridge mode works for most VM software (google around a bit to find out how to setup your vm software).
Oh, and now I noticed your edit :D

Wait, so I'm using the host ip instead of the one inside the VM (using ifconfig in ubuntu)? The problem with this is if I input the host ip inside the FMS url, I cannot connect in OBS, but I can connect using the VM's ip. However, connecting to VM ip shows that my twitch stream "offline" even when I am "connected" through OBS (cannot preview either, but sending data successfully).
 

nurde

New Member
How can i protect my server? If somebody knows my server rtmp, he can stream. How can i protect so that nobody can stream except me and cant create a chanelll ?
I use JWPlayer as player.
 
Top