How to set up your own private RTMP server using nginx

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

sneaky4oe

Member
No, I was using their own server.

Got a clear one and installed nginx as shown in the tutorial.
d76eaf1c3af8.png


For some reason, encoding never starts even with "_static" after exec.

Can't start it manually in shell as well, using that push link as a source. It can push source stream to twitch though, if don't use transcoding - that's already something. Now just need to understand why my ffmpeg stucks.


RTMP_Connect0, failed to connect socket. 110 (Connection timed out)
rtmp://***.***.***.***/transcode/1234: Unknown error occurred

That's what I get if connect manually


UPD: found a way -
ffmpeg -i rtmp://localhost/transcode/1234 -vcodec libx264 -preset faster -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -b:v 1600k -maxrate 2200k -bufsize 3600k -s 960x540 -sws_flags lanczos -acodec copy -f flv rtmp://live-fra.twitch.tv/app/***

Messed up the string.
 
Last edited:

Insire

New Member
Hello
I currently run a 2 PC setup. PC#1 runs OBS with quicksync and streams to PC#2. PC#2 runs a ubuntu vm with nginx and the rtmp module. Everything works fine aslong i only forward the stream through PC#2 to hitbox, but since i'm using a highquality stream, i have to transcode it to something hitbox can handle.
Here comes my problem. I dont really know why or what i messed up in my exec string, but i dont get my stream transcoded. Here is the string i'm talking about:
unbenannte9swd.png

If i comment the exec and use the push instead, everything works fine. Can someone help me please and point out the mistake i made?
 

sneaky4oe

Member
Yesterday I've been solving the exact same problem. Here's the working config for me:

Look at my config:
OBS at main PC streams to LOCAL nginx:
rtmp://127.0.0.1/stream
1234

Than, that Nginx sends streams to different servers:

Code:
#user  nobody;
worker_processes  1;

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

events
{
    worker_connections  1024;
}

rtmp
{
    server
    {
        listen 1935;
        chunk_size 8192;

        application stream
        {
            live on;
            meta copy;
                push rtmp://broadcast.gaminglive.tv/push/******************;
                push rtmp://msk.goodgame.ru:1940/************;
                push rtmp://**.**.**.**/transcode/1234;
        }

    }
}

The last push is my virtual server in Holland that is supposed to encode my stream for twitch.

This server has Nginx and Ffmpeg installed onto Ubuntu - nothing else.

Code:
application transcode
{
live on;
meta copy;
record off;

push rtmp://localhost/lower/1234;
exec ffmpeg -i rtmp://localhost/transcode/1234 -vcodec libx264 -preset veryfast -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -b:v 1600k -maxrate 2200k -bufsize 3600k -s 1066x600 -sws_flags lanczos -acodec copy -f flv rtmp://live-fra.twitch.tv/app/***********
}
 
Last edited:

Jack0r

The Helping Squad
Its always a good test to try and run the ffmpeg commandline manually on your linux system, to see if it throws an error or the commandline is incorrect for some reason.
 

Croncher

New Member
Hey man this guide is great. I got the server to work so that I can view it here on my network, but how do you have it stream to others outside my network. When they type the address into the vlc player it will not load for them.
 

Insire

New Member
Alright. My Setup is almost running.
Here is the full config i use at the moment.
Code:
events {
  worker_connections  1024;
}

rtmp
{
  server
  {
  listen 1935;
  chunk_size 8192;

  application stream
  {
     live on;
     meta copy;
     record off;
     push rtmp://localhost/transcode/1234;
  }

   application transcode
   {
     live on;
     meta copy;
     record off;
     exec ffmpeg -i rtmp://localhost/stream/1234 -vcodec libx264 -preset veryfast -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -b:v 3000k -maxrate 3500k -bufsize 7000k -s 1920x1080 -sws_flags lanczos -acodec copy -f flv rtmp://live.fra.hitbox.tv/push/insire?key=****;
   }
  }
}
Problem is: if i only start nginx, nothing is happening. Ngninx receives the stream, but its not doing any transcoding(watching the load inside my vm is how i noticed that). But if i open up the terminal and enter the following:
Code:
ffmpeg -i rtmp://localhost/stream/1234 -vcodec libx264 -preset veryfast -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -b:v 3000k -maxrate 3500k -bufsize 7000k -s 1920x1080 -sws_flags lanczos -acodec copy -f flv rtmp://live.fra.hitbox.tv/push/insire?key=****
My stream gets published to hitbox. Its lagging rly bad, but its working. So is there something i did miss or do wrong? Because i dont rly know what to try next :(
 

sneaky4oe

Member
Transcoding consumes almost equal ammount of CPU power as ordinary streaming. If you want to use transcoding of your source stream, better do it at second PC or at remote server. Or you can try streaming with vce/quicksync/nvenc and transcode at the same time to lower qualitys.
 

Insire

New Member
Yea thats what i am doing.

I capture my footage using quicksync on my main pc in high quality and send that to my second pc running ubuntu in virtual box with nginx on it. Thats where i'm using the configs i posted above. Unfortunately i still havent figured out what i messed up in the transcoding bit, since i pretty much copied and pasted it.

But i solved the lagging bit. I just had to allocate more cpu cores to that vm and when transcoding manually(via terminal) its running smoothly now.
 

Adrii

New Member
Hi all,

I'm working for a french gaming clan which have one webTV (www.warlegend.net).

We have one server where I installed RTMP server using nginx. So with it, we can stream on Twitch and Dailymotion at the same time (we're mainly using Dailymotion on the website).

PROBLEM => we want to broadcast record video (previous stream recorded) from our server to the webTV when TV is OFF.

How can we do that ?

Thank you by advance.

Adrii
 

Insire

New Member
Code:
events {
  worker_connections  1024;
}

rtmp
{
  server
  {
  listen 1935;
  chunk_size 8192;

  application stream
  {
     live on;
     record off;

     exec_push /home/insire/bin/ffmpeg -i rtmp://localhost/stream/1234 -vcodec libx264 -preset veryfast -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -b:v 3000k -maxrate 3500k -bufsize 7000k -s 1920x1080 -sws_flags lanczos -acodec copy -f flv rtmp://live.fra.hitbox.tv/push/insire?key=****;
   }
  }
}
found the issue :D
turns out nginx needed the full path to my ffmpeg location even though i did set that up in my PATH
 

Zodiarc

New Member
Hello

I want know if is possible to hide RTMP URL?
Thank you

I'm also interested if something like this is possible.

Because right now when I add the stream url to let's say JWPlayer, one can easily inspect the code, copy the url and stream to it by himself. If I don't embed the javascript in the html code, there's nothing preventing others to download the linked javascript and see the url.

I simply want to know: Is there a way to make the url not appear in the html inspection or make sure that only the person who this channel belongs to can stream to it and nobody else?
 

Saavy

New Member
Either obfuscation or inventing stream key system like Twitch's or Livestream's. I actually was wondering myself how these work and was trying to create one.
 

Zodiarc

New Member
Thanks.

Obfuscating indeed could work but I have to find a way to do it "live".

Another idea I had is, if someone is good at flash and ActionScript3, you should be able to write your own player and get the streaming keys at runtime from a database into the flash sho they won't appear in the html code either (not tested, just an idea).
 

Saavy

New Member
Thanks.

Obfuscating indeed could work but I have to find a way to do it "live".

Another idea I had is, if someone is good at flash and ActionScript3, you should be able to write your own player and get the streaming keys at runtime from a database into the flash sho they won't appear in the html code either (not tested, just an idea).
That could work too :)
Recently I saw Picarto.tv using jwplayer, and they don't show stream keys in code. about 2 days ago I found some page where I read that nginx can create publisher's key and viewer's key (on_publish and on_play?), I'll let you know if I find it again, because it's propably what we seek for.

@edit
You propably can make it work, and likely you can get nginx to get back key information as variable from remote PHP script. I will try to make it work...
 
Last edited:

Zodiarc

New Member
That could work too :)
Recently I saw Picarto.tv using jwplayer, and they don't show stream keys in code. about 2 days ago I found some page where I read that nginx can create publisher's key and viewer's key (on_publish and on_play?), I'll let you know if I find it again, because it's propably what we seek for.

@edit
You propably can make it work, and likely you can get nginx to get back key information as variable from remote PHP script. I will try to make it work...

That would be awesome.

For the own flash video player solution I found this: http://www.endseven.net/as3-introduction-to-rtmp-streaming-publishing

Add the database connection to that and there it is.

@EDIT: I think this is also twitch's solution. I inspected their site and there's a call to a TwitchPlayer.swf and they also set an id in the flashVars attribute of the <object>-tag.
 
Last edited:

Cloudwolf

Member
So i'm trying this with the windows version and that may complicate things I don't know. I have the config set up approximately how it was in the tutorial. When i attempt to stream to my local ip 10.0.0.14/live with key test OBS disconnects after about 15 seconds every about 15 seconds as well as VLC with the RTMP url using my outside IP address gives me errors saying can't open the file. from vlc
Code:
"
Your input can't be opened:

VLC is unable to open the MRL 'rtmp://ip:1935/live/test'. Check the log for details."

als OBS tells me that it has 0 kb/s upload granted i am trying to stream with OBS to an RTMP server on the exact same computer and i'm not sure that's even possible. EG my nginx server and my obs computer are the same computer.
 

Insire

New Member
@Cloudwolf Seems like obs cant find your server - did you try to replace your ip with localhost? aka "rtmp://localhost:1935/live/test"

maybe you should link your nginx.conf file here aswell
 

Cloudwolf

Member
@Cloudwolf Seems like obs cant find your server - did you try to replace your ip with localhost? aka "rtmp://localhost:1935/live/test"

maybe you should link your nginx.conf file here aswell

trying localhost:1935 worked. thank you. I'm just dumb :)

Fixed the crashing. don't use constant bit rate apparently... Now comes the fun part of trying to figure out how to set it up so outside sources can connect.
 
Last edited:
Top