How to set up your own private RTMP server using nginx

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

Kurt

New Member
I'm hoping someone can help me out. I think this will be a simple one but I'm missing something here obviously.

I'm using nginx in the precompiled Media Server VM from the Tools section. Internally everything works fine, I can connect and watch the stream from any PC in the house, but people externally can't view the streams (I've been testing from my work pc).

On the router I forwarded external port 999 to local port 80 of the VM, and I also forwarded external port 1935 to the local port 1935 of the VM.

Externally I can bring up the main webpage by going to http://myipaddress:999, click the stream to load it but then in jw player I get 'Can't load stream'

If I try to use FlowPlayer I get the error message: Unable to load stream or clip file, connection failed.

Is there another port I need to forward that I'm missing?
 

Jack0r

The Helping Squad
Did you try playing back the stream in vlc for example, and what address did you use in jw player?
It is important to set the external IP of your server. If you try to playback the stream from the internet thats is the only IP visible to you, so for example rtmp://serverip:1935/app/stream or for jw player /app/flv:stream
 

Aqeel Shoukat

New Member
Hi dodgepong!
I want to stream a video from usb cam attached with raspberry pi to vlc/web browser/ android phone.
Is it possible with the method you described here or any changes are required...???
 

Kurt

New Member
Did you try playing back the stream in vlc for example, and what address did you use in jw player?
It is important to set the external IP of your server. If you try to playback the stream from the internet thats is the only IP visible to you, so for example rtmp://serverip:1935/app/stream or for jw player /app/flv:stream

The version of nginx I've been using is from this thread:

https://obsproject.com/forum/threads/media-streaming-server.15117/

It is an oracle VM with a debian install with nginx compiled into it. I was using the external IP address from my work machine to try and connect, but I was using flow player within the web interface so I'm not sure which address I was trying to conncet to. I was able to connect to the basic web page of the VM but once I click the stream I got the errors I mentioned.

Maybe I should just create my own VM and try installing nginx in it from scratch, other than opening the basic web port and 1935 I don't know how to troubleshoot the one in the thread.
 

Jack0r

The Helping Squad
The IP that got you the webpage is probably the one you should use for flowplayer/jwplayer. But yea, learn a bit about it and install it locally. Thats always good when you have problems later (after the current one is fixed).
 

franktitude

New Member
Hi Guys

So I tried this setup, broadcasting from Gaming PC to Streaming PC, but this doesn't seems to improve my gaming experience at all, as compared to a one PC gaming/streaming setup.

To achieve the best gaming experience and steaming quality setup, it is best to have a Capture Card, HDMI Splitter + Audio Mixer setup?
 

prodyn

New Member
dodgepong,
Excellent and straight forward guide. I installed it on my spare laptop, the O/S is Ubuntu desktop version, which I use for basic things like web surfing etc. Now I have an easy way to share things with my family and friends without going through an additional service, ie: Twitch.


I thought I'd pass along another way of viewing the stream, without going through VLC, if you have Flash installed on your system. Below is a link that opens the Flash player in your web browser. Modify with your broadcast configuration.

https://fpdownload.adobe.com/strobe...pe=live&autoPlay=true&playButtonOverlay=false

It works well and allows me to send the link to people I want to share with and they don't have to worry about VLC or downloading it.

Minor gripe: I forgot to change my OBS profile, one which points to my newly installed personal RTMP server, and accidentally left the Twitch profile in place. So with my test stream using a dvd, I broadcast to Twitch which of course suspended my account for broadcasting the content.
Caution 0, Excitement 1
 
Last edited:

DjRiff

New Member
Hi there, i'm not to familiar with linux, much less with nginx besides what i've read here. I seem to be running into a wall that i've been trying for 3 days to get past to no avail. I have done the following things.

Have Ubuntu 14.04 installed on a spare laptop I have that far exceeds the requirements for nginx.
Configured it exactly as the guide stated.
Try to stream to it using OBS using the IP of the computer nginx is running on and did not work.
Says "Could not connect to server <my ip>/live is offline. Try a different server (10061). (my ip is actually filled out on my system.)

When that didn't work I reinstalled nginx and tried it again, same issue.

I read another guide that said it would work in a virtual machine.
Set everything up using a VM, running into the exact same problems. Is there something i'm missing here? Do I need to install a server version of ubuntu?

I also have all the necessary ports forward on both of my routers. (Running 2 routers, 1 for my main house, and 1 for my man cave setup.
 
Last edited:

prodyn

New Member
DjRiff,

It might be the firewall on your laptop. You can adjust it through the command line interface (CLI) or an easier way is to use the Firewall Configuration gui. The gui doesn't come with Ubuntu by default, but you can get it through the Ubuntu Software Center by typing "Firewall Configuration". Once you have it installed just create a rule to allow port 1935, or which ever port you are using.

The router port forward would only be useful if you are trying to access the laptop, with NginX and RTMP module installed, from the internet. If you read my earlier post you see I have it working with the Ubuntu Desktop just fine.
 

DjRiff

New Member
Awesome, finally got it to work! Pretty sure it was the firewall stopping me. Thanks for helping me break down this wall. I do have plans to be able to access my stream from elsewhere, I also plan on building a media server for use on my consoles that are in the living room. Cheers.
 

Jack0r

The Helping Squad
You would have to set up several ffmpeg encoders, one for each resolution, then you need the procesing power to encode them at the same time, and you need to find a way to combine them into one stream using a flash player which then offers you the option to select the resolution.
 

KR4KOS

New Member
You would have to set up several ffmpeg encoders, one for each resolution, then you need the procesing power to encode them at the same time, and you need to find a way to combine them into one stream using a flash player which then offers you the option to select the resolution.

I have 32GB ram. And I have already an flash player with a quality selector :)
Just need to conf NGINX
 

Jack0r

The Helping Squad
Not sure how RAM is important in this case, but the flash player with quality selector is a good start. Probably best to setup nginx on linux in this case, get the latest ffmpeg and setup a config with an app to receive the stream, for example "origin" and a final app "stream".
The app "origin" should then have the exec commandlines for ffmpeg, for example:
exec ffmpeg -i rtmp://server.ip/origin/test -c:v libx264 -c:a copy -s 640x480 rtmp://server.ip/stream/480p
exec ffmpeg -i rtmp://server.ip/origin/test -c:v libx264 -c:a copy -s 320x240 rtmp://server.ip/stream/240p
exec ffmpeg -i rtmp://server.ip/origin/test -c:v libx264 -c:a copy -s 160x120 rtmp://server.ip/stream/120p
 

KR4KOS

New Member
Not sure how RAM is important in this case, but the flash player with quality selector is a good start. Probably best to setup nginx on linux in this case, get the latest ffmpeg and setup a config with an app to receive the stream, for example "origin" and a final app "stream".
The app "origin" should then have the exec commandlines for ffmpeg, for example:
exec ffmpeg -i rtmp://server.ip/origin/test -c:v libx264 -c:a copy -s 640x480 rtmp://server.ip/stream/480p
exec ffmpeg -i rtmp://server.ip/origin/test -c:v libx264 -c:a copy -s 320x240 rtmp://server.ip/stream/240p
exec ffmpeg -i rtmp://server.ip/origin/test -c:v libx264 -c:a copy -s 160x120 rtmp://server.ip/stream/120p


I have this :

rtmp {
server {
listen 1935;
chunk_size 4096;

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


So, now is ? :
rtmp {
server {
listen 1935;
chunk_size 4096;

application live {
live on;
record off;

exec ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -c:a copy -s 640x480 rtmp://localhost/live/480p_$name;
exec ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -c:a copy -s 320x240 rtmp://localhost/live/240p_$name;
exec ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -c:a copy -s 160x120 rtmp://localhost/live/120p_$name;

}
}
}

Does it work ?
 
Last edited:

Jack0r

The Helping Squad
Code:
application origin {
    live on;
    meta copy;
    exec ffmpeg -i rtmp://localhost/origin/$name -c:v libx264 -c:a copy -s 640x480 rtmp://localhost/live/480p_$name;
    exec ffmpeg -i rtmp://localhost/origin/$name -c:v libx264 -c:a copy -s 320x240 rtmp://localhost/live/240p_$name;
    exec ffmpeg -i rtmp://localhost/origin/$name -c:v libx264 -c:a copy -s 160x120 rtmp://localhost/live/120p_$name;
}

application live {
    live on;
    meta copy;
}
As I said, you need to use two applications, or each ffmpeg stream would cause a new execution of all commandlines.
 

KR4KOS

New Member
Code:
application origin {
    live on;
    meta copy;
    exec ffmpeg -i rtmp://localhost/origin/$name -c:v libx264 -c:a copy -s 640x480 rtmp://localhost/live/480p_$name;
    exec ffmpeg -i rtmp://localhost/origin/$name -c:v libx264 -c:a copy -s 320x240 rtmp://localhost/live/240p_$name;
    exec ffmpeg -i rtmp://localhost/origin/$name -c:v libx264 -c:a copy -s 160x120 rtmp://localhost/live/120p_$name;
}

application live {
    live on;
    meta copy;
}
As I said, you need to use two applications, or each ffmpeg stream would cause a new execution of all commandlines.

I have 2 errors :


Unrecognized option 'c:v'
and
Failed to set value 'libx264' for option 'c:v'
 

Jack0r

The Helping Squad
Hmm, on a pretty up to date ffmpeg that command should work, at least it does under windows. On linux you might have to update ffmpeg manually though as most distributions only have very old versions in their repository, or use avconv which needs different commands.
One small thing I noticed though, copied the lines from arut, ffmpeg wants to know the output format:
ffmpeg -i rtmp://localhost/origin/$name -c:v libx264 -c:a copy -s 640x480 -f flv rtmp://localhost/live/480p_$name
 

KR4KOS

New Member
Code:
ffmpeg version 0.8.16-6:0.8.16-1, Copyright (c) 2000-2014 the Libav developers
  built on Sep 16 2014 23:10:48 with gcc 4.7.2
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
Metadata:
  duration              0.00
  fileSize              0.00
  width                 1280.00
  height                720.00
  videocodecid          avc1
  videodatarate         600.00
  framerate             30.00
  audiocodecid          mp4a
  audiodatarate         64.00
  audiosamplerate       44100.00
  audiosamplesize       16.00
  audiochannels         2.00
  stereo                TRUE
  encoder               Open Broadcaster Software v0.637b

I have add : -f flv
but don't work...
Same problem


My version is up to date or not?
 

Jack0r

The Helping Squad
"The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead."

Current ffmpeg version is 2.4, you are on 0.8 apparently, so its not up to date.
 
Top