Jump to content

  • M1-Gaming Crew


[M1GC] M1-Gaming Crew

Private RTMP server live-streaming x2 PC Setup

Recommended Posts

Normally i stream with NVENC encoding on OBS. 
I found that the quality wasn’t that great when streaming...

Since i have several servers, i figured lets utilize one for streaming...

Streaming Server

Ubuntu Server 18.04 LTS x64 or x86
NGINX-RTMP and FFMPEG.

Main computer

OBS Studio with NVENC encoding.

Settings for the main computer

In OBS, I use NVENC encoding @ 6Mpbs to 50 Mbps bit rate and I use my monitor’s native resolution (1080p). 

Settings for the streaming server

If you do not have a 2nd PC / Server, You can run a 2nd PC on your main computer using VMWare Workstation (Paid) or VirtualBox (Free) by installing Ubuntu Server to either VMWare Workstation or VirtualBox

If you do not know how to install Ubuntu Server to VMWare Workstation or VirtualBox, Check the links below:

Installing FFmpeg

Notice: ffmpeg is back in Ubuntu. Therefore, you only need to run the “sudo apt-get install ffmpeg -y” to install it.

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

Compiling and installing NGINX with the RTMP module

You need to install the prerequisite libraries

Login to your Ubuntu Server System & install the Prerequisite Libraries

sudo apt-get install unzip build-essential libpcre3 libpcre3-dev libssl-dev

Now you need to download the latest NGINX and the RTMP Module and unpack them
 

wget http://nginx.org/download/nginx-1.15.8.tar.gz

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

tar -xvf nginx-1.15.8.tar.gz

unzip master.zip

cd nginx-1.15.8

Build NGINX with the NGINX-RTMP Module

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

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

Edit the 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:

#user  nobody;
worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

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

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;

        # sample handlers
        #location /on_play {
        #    if ($arg_pageUrl ~* localhost) {
        #        return 201;
        #    }
        #    return 202;
        #}
        #location /on_publish {
        #    return 201;
        #}

        #location /vod {
        #    alias /var/myvideos;
        #}

        # rtmp stat
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            # you can move stat.xsl to a different location
            root /usr/build/nginx-rtmp-module;
        }

        # rtmp control
        location /control {
            rtmp_control all;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

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

        application myapp {
            live on;

            # sample play/publish handlers
            #on_play http://localhost:8080/on_play;
            #on_publish http://localhost:8080/on_publish;

            # sample recorder
            #recorder rec1 {
            #    record all;
            #    record_interval 30s;
            #    record_path /tmp;
            #    record_unique on;
            #}

            # sample HLS
            #hls on;
            #hls_path /tmp/hls;
            #hls_sync 100ms;
        }

        # Video on demand
        #application vod {
        #    play /var/Videos;
        #}

        # Video on demand over HTTP
        #application vod_http {
        #    play http://localhost:8080/vod/;
        #}
    }
}

Publishing with ffmpeg

The easiest way to publish live video stream is 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.

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

Publishing to Restream.io & Facebook

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;

        exec ffmpeg -re -i "rtmp://127.0.0.1/live/YOURSTREAMKEY" -c:v libx264 -crf 0 -c copy -f flv "rtmp://127.0.0.1/liveout/YOURSTREAMKEY";

        }

        application liveout {
            live on;
            record off;

#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 above.
 

The Live Application (live) will import your stream from your streaming software (OBS, XSplit, Wirecast) using ffmpeg.

The live app will run the stream thru ffmpeg without conversion using the x264 encoder while coping the stream to a .FLV video format to the liveout application (liveout). 

Since the liveout application (liveout) now has a copy of your stream, you can push your stream to any platform.

BANDWIDTH USED WHEN STREAMING & PUSHING

When steaming & pushing your stream to streaming platforms,
please note whatever bandwidth you set on your streaming software you must accommodate for your push.


For example, if i set OBS Studio to 6000k / 6mbs for a 720p 60fps stream, and im pushing to x2 platforms (Facebook / Restream)
then 12000k / 12mbps will be used to stream to both platforms for a stable quality stream.


If i set OBS Studio to 8000k / 8mbs for a 1080p 60fps stream, and im pushing to x2 platforms (Facebook / Restream)
then 16000k / 16mbps will be used to stream to both platforms for a stable quality stream.

If you don't have enough bandwidth your will experience issues with your stream..

Running the server

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

sudo /usr/local/nginx/sbin/nginx

Setting up the main computer

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

The Streaming URL will be something like rtmp://192.168.1.2/liveout (Use your own server’s IP).

Your Stream Key needs to be the same you used in your nginx configuration.

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

My Low to Max bit rate is set anywhere from 2500Kb/s to 50000Kb/s

(Since it’s only going to communicate on my local network you can go higher than over the internet).

You may need to adjust your max bit rate according to your needs and capabilities.

As for Audio encoding, I use the AAC codec, 160 bit rate and a Format of 48 Khz.

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


  • M1-Gaming Crew


  • Welcome to M1-Gaming Crew

    M1-Gaming-BG1.png

     

     

  •  
    16602581_1412125855465766_65241381705800
    M1-Gaming - Gaming Group
    Facebook Group · 728 members
    app_fb_32_fig_white.png Join Group
    We accept players of all skill levels and help members grow at their own pace. We are respectful, determined, and proud to be [M1] members.. Feel Free...
     
  • M1GC-Guilded_Logomark_Wordmark_Color.png

    Check out M1-Gaming Crew 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.

×