Jump to content
Search In
  • More options...
Find results that contain...
Find results in...



#0
Guest

User Menu


Sign In

Sign In



Or sign in with one of these services

Sign Up

Forum Menu


Register now to M1GC to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an M1GC account for free today!

  • M1GC

M1GC

Private NGINX/RTMP server live-streaming

Recommended Posts

Creating Your own Private RTMP server for streaming

Your Private RTMP Streaming Server 

NGINX/FFMPEG-based Media Streaming Server

Ubuntu 20.04.1 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 Gaming / One for Streaming for Best Results.
  • If you only have X1 PC - System must have enough resources to support Gaming, and Streaming, including running virtualization technology and virtual machines.
  • Ubuntu OS (May work on other Operating Systems with command modifications)

  • Multi-core CPU / 2GB RAM Minimum / 4GB+ 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 on your streaming pc if required.

The Tutorial below will describe for both x1 or x2 pc 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 on your main gaming computer you use:
VMWare Workstation (Paid) or VirtualBox (Free) or Docker (Free)

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

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

Check the links below:

How to install Ubuntu Server to VMWare Workstation
How to install Ubuntu Server to Virtualbox
How to Install Ubuntu Server to Docker Desktop

Download Ubuntu Server OS 20.04.1 LTS (.iso)


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 4.x

apt install software-properties-common -y
apt install ffmpeg -y

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 build-essential libpcre3 libpcre3-dev libssl-dev -y

Now you need to download the latest NGINX and the RTMP Module and unpack them
as of this post, NGINX v1.19.7 is the latest main-line version.

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

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

tar -xvf nginx-1.19.7.tar.gz

unzip master.zip

cd nginx-1.19.7

Build NGINX with the NGINX-RTMP Module

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
make
make install

If you receive this build error:

../nginx-rtmp-module-master/ngx_rtmp_eval.c: In function 'ngx_rtmp_eval':
../nginx-rtmp-module-master/ngx_rtmp_eval.c:160:17: error: this statement may fall through [-Werror=implicit-fallthrough=]
                 switch (c) {
                 ^~~~~~
../nginx-rtmp-module-master/ngx_rtmp_eval.c:170:13: note: here
             case ESCAPE:
             ^~~~

Add this line of code to the end of your build config

--with-debug --with-cc-opt="-Wimplicit-fallthrough=0"

EXAMPLE:

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

Reconfigure, 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 myapp {
            live on;
        
        #push to restream.io
        push rtmp://live.restream.io/live/streamkey;

        }
    }
}

That's it.
Above the myapp 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 Gaming 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 myapp {
            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.github.com/JasonGiedymin/nginx-init-ubuntu/master/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

Setting up the main gaming computer
Main gaming computer or Any ol Gaming 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.

OBS Tutorial for Dacast (PC): How to connect OBS Studio to Dacast

The Streaming URL will be something like: rtmp://yourserverslocalipaddressoryourserversexternalipaddress/myapp

(Use your own 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 private rtmp server.

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

Publishing with FFMPEG
The easiest way to publish live video streams is by using ffmpeg (or avconv).

It's already installed on most systems and easy to install on others.

RTMP supports only a limited number of codecs.

The most popular RTMP video codecs are H264, Sorenson-H263 (aka flv) and audio codecs AAC, MP3, Nellymoser, Speex.

If your video is encoded with these codecs (the most common pair is H264/AAC) then you do not need any conversion.

Otherwise you need to convert video to one of supported codecs.

We'll stream test file /var/videos/test.mp4 to server with ffmpeg.


Below are some different examples of how to use FFMPEG To Stream Live Video.

Streaming without conversion (given test.mp4 codecs are compatible with RTMP)

ffmpeg -re -i /var/Videos/test.mp4 -c copy -f flv rtmp://localhost/myapp/mystream

Streaming and encoding audio (AAC) and video (H264), need libx264 and libfaac

ffmpeg -re -i /var/Videos/test.mp4 -c:v libx264 -c:a libfaac -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream

Streaming and encoding audio (MP3) and video (H264), need libx264 and libmp3lame

ffmpeg -re -i /var/Videos/test.mp4 -c:v libx264 -c:a libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream

Streaming and encoding audio (Nellymoser) and video (Sorenson H263)

ffmpeg -re -i /var/Videos/test.mp4 -c:v flv -c:a nellymoser -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream

Publishing video from webcam (Linux)

ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an -f flv rtmp://localhost/myapp/mystream

Publishing video from webcam (MacOS)

ffmpeg -f avfoundation -framerate 30 -i "0" -c:v libx264 -an -f flv rtmp://localhost/myapp/mystream

Playing with ffplay

ffplay rtmp://localhost/myapp/mystream

OK NOW LETS  MODIFY OUR CONFIG TO USE FFMPEG TO CONVERT OUR STREAM AND PUBLISH TO OUR PLATFORMS.

Publishing a live stream to Restream.io & Facebook.com using FFMPEG

This config is an example of how we will publish to multi-platforms using FFMPEG...

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application myapp {
            live on;
#FFMPEG COPYING AND SENDING THE STREAM TO LIVEOUT
        exec ffmpeg -re -i "rtmp://127.0.0.1/myapp/YOURSTREAMKEY" -c:v libx264 -crf 0 -c copy -f flv "rtmp://127.0.0.1/liveout/YOURSTREAMKEY";

        }

        application liveout {
            live on;
            record off;

#LIVE OUT RECEIVING THE STREAM FROM ( myapp ) AND SENDING THE COPY OUT TO RESTREAM AND FACEBOOK

#RESTREAM.IO DIRECT
push rtmp://live.restream.io/live/YOUR_STREAM_KEY;

#FACEBOOK DIRECT
push rtmp://live-api-s.facebook.com:80/rtmp/YOUR_STREAM_KEY;


        }
    }
}


Lets explain whats happening in the code above

  • The Live Application (myapp) will import your stream from your streaming software (OBS, XSplit, Wirecast) using ffmpeg.
  • The myapp, will run the stream thru FFMPEG without conversion, using the x264 or x265 encoder, while copying the stream into a .FLV video format file.
  • The .flv file is then sent to the liveout application all in real-time. (liveout),
  • The liveout application (liveout) will receive a copy of your stream, and then pushed / sends your stream to any platform you listed to push too.

That's it. 
ENJOY STREAMING WITH NGINX AND FFMPEG!

  • Thanks 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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..

  • Guilded_Logomark_Wordmark_Color.png

    Check out M1GC on Guilded

  • 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.

  • M1GC

About Us

M1GC it's a community based on PC and Console Gaming.

Social Links

M1GC Facebook Group Join
M1GC Steam Group Join
M1GC Discord Server Join
×
×
  • Create New...

Important Information

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