Jump to content
  • M1GC

Private NGINX/RTMP server live-streaming


M1GC
 Share

Recommended Posts

Creating Your own Private RTMP server for streaming

Your Private RTMP Streaming Server 

NGINX/FFMPEG-based Media Streaming Server

Ubuntu Latest LTS x64 Based OS with NGINX LATEST w RTMP SUPPORT / FFMPEG LATEST

  • RTMP/HLS/MPEG-DASH live streaming
  • RTMP Video on demand FLV/MP4, playing from local filesystem or HTTP
  • Stream relay support for distributed streaming: push & pull models
  • Recording streams in multiple FLVs
  • H264/AAC support
  • Online transcoding with FFmpeg
  • HTTP callbacks (publish/play/record/update etc)
  • Running external programs on certain events (exec)
  • HTTP control module for recording audio/video and dropping clients
  • Advanced buffering techniques to keep memory allocations at a minimum level for faster streaming and low memory footprint
  • Proved to work with Wirecast, FMS, Wowza, JWPlayer, FlowPlayer, StrobeMediaPlayback, ffmpeg, avconv, rtmpdump, flvstreamer and many more<
  • Statistics in XML/XSL in machine- & human- readable form

REQUIREMENTS

  • X2 PC's - One for Broadcasting / One for Streaming for Best Results.
  • If you only have X1 PC - System must have enough resources to support Broadcasting / Streaming, including running virtualization technology and virtual machines.
  • Ubuntu OS (May work on other Operating Systems with command modifications)

  • Multi-core CPU for FFMPEG / 2GB RAM Minimum / 4GB+ or more Recommended

  • Disk space as required for any media files or recordings...

  • PLEASE NOTE: You can also try our Docker Version which may save you some resources and time.

The Tutorial below will describe for both x1 or x2 pc / server setups..

Setting up the RTMP Streaming Server on 2nd Streaming PC or VM

PLEASE NOTE:

IF YOU DO NOT HAVE A 2ND PC FOR STREAMING

You can run a 2nd Operating System / system on your main computer you use by utilizing virtualization:
VMWare Workstation (Paid) or VirtualBox (Free) or Docker (Free)

You may also use Cloud Providers such as Digital Ocean, AWS, Google Cloud, Microsoft Azure or M1-Serverz VPS to create a machine but may be costly..
We recommend having enough CPU, Memory, & Bandwidth Resources to achieve stable streaming on the same PC.  

If you do not know how to install Ubuntu Server to VMWare WorkstationVirtualBox, & Docker,

Check the links below:

Purchase: VMWare Workstation

Download: Virtualbox

Download Docker Desktop

NOTE: DOCKER DESKTOP UPDATED THERE SUBSCRIPTION LICENSE
THIS MAY AFFECT WINDOWS USERS USING DOCKER DESKTOP.
CLICK
HERE FOR MORE INFORMATION

Download Ubuntu Server OS Latest


Once your Virtualization Software is installed, & you have created a VM (Virtual Machine) with the latest Ubuntu Server operating system on your VM,

Login to your Ubuntu Server System. 
Install SSH on your Ubuntu Server

apt install ssh openssh-server -y

(You can now use Putty to SSH into your VM - Example: yourubuntuusername@yourlocalorexternalip )

User is logged in as root. (Not Recommended)

During this example, i am logged in a root.

To login as root user:

sudo su

We recommend using a standard user without administrator permissions for best security.

  • If logged in as root - You do not need to add sudo to every command.
  • If logged in as a user - add sudo to all commands below (Example: sudo apt install ffmpeg )

Installing FFmpeg on Ubuntu Server (Optional)

Notice: 

FFMPEG is back in Ubuntu.

Ubuntu Server now comes with FFMPEG by default in its repositories. 

Therefore, to install it, You only need to run:

apt install ffmpeg -y

For Updated FFMPEG

apt install software-properties-common -y

For Updated FFMPEG 5.x

The FFmpeg 5 requires packages from the existing 4 FFmpeg PPA, import this first.

  sudo add-apt-repository ppa:savoury1/ffmpeg4 -y

Next, import FFmpeg 5 PPA.

sudo add-apt-repository ppa:savoury1/ffmpeg5 -y

Once imported, run an APT update to reflect the new addition to your Ubuntu sources list.

sudo apt update

Next, quite a few upgrades are available for the dependencies required. Before proceeding any further, run a quick upgrade.

sudo apt upgrade

Install FFmpeg
With the PPA repository now added, run the following command to install FFmpeg.

sudo apt -y install ffmpeg


Next, verify the installation with the following terminal command:

ffmpeg -version

Screenshot_4.png

Compiling and installing NGINX with the RTMP module

You need to install the prerequisite libraries

Install the Prerequisite Libraries

apt install unzip zlib1g-dev wget vim-nox nano build-essential libpcre3 libpcre3-dev libssl-dev -y

Now you need to download the latest NGINX and the RTMP Module and unpack them
Check this link for NGINX latest mainline version.

wget https://nginx.org/download/nginx-1.23.1.tar.gz

wget https://github.com/MurderousOne/nginx-rtmp-module/archive/master.zip

tar -xvf nginx-1.23.1.tar.gz

unzip master.zip

cd nginx-1.23.1

Build NGINX with the NGINX-RTMP Module

Configure, Make, Make Install

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master --with-debug --with-cc-opt="-Wimplicit-fallthrough=0"
make 
make install

Configuring NGINX
Once Nginx is compiled,
The default location for the configuration file is: 
/usr/local/nginx/conf/nginx.conf

Edit the NGINX Configuration File

vi /usr/local/nginx/conf/nginx.conf

or 

nano /usr/local/nginx/conf/nginx.conf

and at the end of the file, add the following:

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;

        application live {
            live on;
        
        #push to restream.io
        push rtmp://live.restream.io/live/streamkey;

        }
    }
}

That's it.
Above the live application will publish a stream direct from your streaming software to any platform you listed as push.
in this case, it is sending a stream from my PC with OBS Studio, to the 2nc PC Streaming Server, which then sends the stream out to the platform listed.

Want to send more? Just add another push and send your stream to that platform as well.

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;

        application live {
            live on;
        
        #push to restream.io
        push rtmp://live.restream.io/live/streamkey;
		
		#push to youtube
		push rtmp://a.rtmp.youtube.com/live2/streamkey;

        }
    }
}

PLEASE NOTE: You will require the same amount of bandwidth for both push streams.
If you use 6mbps to stream a 1080p60fps stream to one platform, it will require 12mbps of Upload Bandwidth for streaming to x2 platforms.

Using restream.io will save you on streaming to multi-platforms simultaneously. You can stream to 30+ platforms and only use 6mbps..
Adding additional push to platforms, will require additional upload bandwidth...
Be sure to speed test your upload speeds to test your networks full capabilities.

Running the server
You can start the nginx server manually by running the following command:

/usr/local/nginx/sbin/nginx

But we recommend you add it in your services for convenience.

wget https://raw.githubusercontent.com/MurderousOne/nginx-rtmp-ffmpeg-docker/main/nginx -O /etc/init.d/nginx
chmod +x /etc/init.d/nginx
update-rc.d -f nginx defaults

Start / Stop / Restart the NGINX server

service nginx start
service nginx stop
service nginx restart

Back out of NGINX FOLDER

cd ..

Download the above commands as shell scripts for easy executing.

wget https://raw.githubusercontent.com/MurderousOne/nginx-rtmp-ffmpeg-docker/main/upgrade

wget https://raw.githubusercontent.com/MurderousOne/nginx-rtmp-ffmpeg-docker/main/edit-rtmp

wget https://raw.githubusercontent.com/MurderousOne/nginx-rtmp-ffmpeg-docker/main/start-rtmp

wget https://raw.githubusercontent.com/MurderousOne/nginx-rtmp-ffmpeg-docker/main/stop-rtmp

wget https://raw.githubusercontent.com/MurderousOne/nginx-rtmp-ffmpeg-docker/main/restart-rtmp

Make the scripts executable

chmod +x upgrade edit-rtmp restart-rtmp start-rtmp stop-rtmp 

Cleaning up left over files and folders

These installation files are no longer needed and will reduce space on your server

rm -r master.zip nginx-1.23.1 nginx-rtmp-module-master nginx-1.23.1.tar.gz

Execute the shell commands
Start / Stop / Restart the NGINX server

Start the NGINX Server

./start-rtmp

Stop the server

./stop-rtmp

Restart the server

./restart-rtmp

Edit the rtmp server config 

./edit-rtmp

Upgrade the software packages

./upgrade

Setting up the main broadcasting computer
Main broadcasting computer or Any ol PC Capable of running OBS Studio with x264 or NVENC encoding.

In OBS, i use NVENC encoding and I use my monitor’s native resolution (1080p). 

Using OBS Studio, in your broadcast settings you need to use the “Custom” streaming service.

Screenshot 2022-09-17 181741.jpg

NOTE: (You can use your servers local IP or External IP Address)

Your Stream Key needs to be the same you used in your nginx configuration. (Stream-Key is Case-Sensitive)

In the Encoding, use Nvidia NVENC (Since it doesn’t use a lot of CPU).

Bitrates
Click here for Live encoder settings, bitrates, and resolutions

You may need to reduce your bitrate depending on services bandwidth limits.
You may need to adjust your max bitrate according to your needs and capabilities

Audio
As for Audio encoding, I use the AAC codec, 96k bit rate and a Format of 44 or 48Khz.

That's it

You can now stream direct with your own lightweight private rtmp server, just like a restream.io, using your own bandwidth, but without the platform limit's.

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

  • M1GC featured this topic
  • M1GC locked this topic
  • M1GC unlocked this topic
Guest
This topic is now closed to further replies.
 Share

  • M1GC

  • Welcome to M1GC

    tenor.gif

    We accept players of all skill levels and help members grow at their own pace.

    We are respectful, determined, and proud to be M1GC members..

  • twitch-logo.gif.6e366685b5d45bf948dad544bc71f521.gif

    Check out M1GC on Twitch

  • Sign up to Restream.io

    M1-Gaming Is Inviting you to Join Restream. The best way to stream video live to 30+ platforms simultaneously for free.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.