Jump to content
  • Announcement

    Welcome to M1GC

  • M1GC

NGINX/RTMP/FFMPEG live-streaming server


M1GC

Recommended Posts

 

Creating Your own Private NGINX/RTMP/FFMPEG server for streaming

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 to create a machine but may be costly
or you can use M1-Serverz VPS which is a bit more affordable.
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 -y install ffmpeg

Next, verify the installation with the following terminal command:

ffmpeg -version

Screenshot_90.png

If you wish to compile FFMPEG from source to use the latest version, follow this FFMPEG Compilation Guide. 

Compiling FFMPEG from Source (Ubuntu 22.04.4 LTS )
These are packages required for compiling, but you can remove them when you are done if you prefer:

apt update -qq && apt -y install \
  autoconf \
  automake \
  build-essential \
  cmake \
  git-core \
  libass-dev \
  libfreetype6-dev \
  libgnutls28-dev \
  libmp3lame-dev \
  libsdl2-dev \
  libtool \
  libva-dev \
  libvdpau-dev \
  libvorbis-dev \
  libxcb1-dev \
  libxcb-shm0-dev \
  libxcb-xfixes0-dev \
  meson \
  ninja-build \
  pkg-config \
  texinfo \
  wget \
  yasm \
  zlib1g-dev \
  nasm \
  libx264-dev \
  libx265-dev \
  libnuma-dev \
  libvpx-dev \
  libfdk-aac-dev \
  libopus-dev \
  libunistring-dev \
  libaom-dev \
  libdav1d-dev

Create a directory for Compilation files / binaries of FFMPEG

mkdir -p ~/ffmpeg_sources ~/bin

Begin Compiling and Installing FFMPEG

cd ~/ffmpeg_sources && \
wget -O ffmpeg-6.1.1.tar.bz2 https://ffmpeg.org/releases/ffmpeg-6.1.1.tar.bz2 && \
tar xjvf ffmpeg-6.1.1.tar.bz2 && \
cd ffmpeg-6.1.1 && \
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs="-lpthread -lm" \
  --ld="g++" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-gnutls \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --extra-libs="-lpthread" \
  --enable-nonfree && \
PATH="$HOME/bin:$PATH" make && \
make -j4 install && \
hash -r

Be patient and grab a coffee as this process may take a few mins to complete.

Next, Change to your ffmpeg bin directory

cd ~/bin

Then, Copy FFMPEG to its default locations on Linux

cp ffmpeg /usr/bin/ffmpeg
cp ffmpeg /usr/share/ffmpeg
cp ffmpeg /usr/local/bin/ffmpeg

Optional: Copy FFPLAY to its default locations on Linux

FFplay is a very simple and portable media player using the FFmpeg libraries and the SDL library.
It is mostly used as a testbed for the various FFmpeg APIs.

cp ffplay /usr/bin/ffmpeg
cp ffplay /usr/share/ffmpeg
cp ffplay /usr/local/bin/ffmpeg 

Optional: Copy FFPROBE to it's default location on Linux.

ffprobe gathers information from multimedia streams and prints it in human- and machine-readable fashion.
For example it can be used to check the format of the container used by a multimedia stream
and the format and type of each media stream contained in it.

cp ffprobe /usr/bin/ffmpeg
cp ffprobe /usr/share/ffmpeg
cp ffprobe /usr/local/bin/ffmpeg  

Next, verify the installation with the following terminal command:

ffmpeg -version

Screenshot_90.png
FFMPEG IS NOW COMPILED AND READY FOR USE
Lets cleanup and remove its install directories & binaries
Change directory to ~

cd ~

Next, lets remove the FFMPEG Compilation Directories.

rm -r bin  ffmpeg_build  ffmpeg_sources

Then exit out of the home directory and to the root directory

cd .. 

or

cd /

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.25.4.tar.gz

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

tar -xvf nginx-1.25.4.tar.gz

unzip master.zip

cd nginx-1.25.4

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:

#    ____ _____ __  __ ____    __  __ _____ ____ ___    _      ____ _____ ____  _____    _    __  __ ___ _   _  ____   ____  _____ ______     _______ ____
#   |  _ \_   _|  \/  |  _ \  |  \/  | ____|  _ \_ _|  / \    / ___|_   _|  _ \| ____|  / \  |  \/  |_ _| \ | |/ ___| / ___|| ____|  _ \ \   / / ____|  _ \
#   | |_) || | | |\/| | |_) | | |\/| |  _| | | | | |  / _ \   \___ \ | | | |_) |  _|   / _ \ | |\/| || ||  \| | |  _  \___ \|  _| | |_) \ \ / /|  _| | |_) |
#   |  _ < | | | |  | |  __/  | |  | | |___| |_| | | / ___ \   ___) || | |  _ <| |___ / ___ \| |  | || || |\  | |_| |  ___) | |___|  _ < \ V / | |___|  _ <
#   |_| \_\|_| |_|  |_|_|     |_|  |_|_____|____/___/_/   \_\ |____/ |_| |_| \_\_____/_/   \_\_|  |_|___|_| \_|\____| |____/|_____|_| \_\ \_/  |_____|_| \_\
#
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.

#    ____ _____ __  __ ____    __  __ _____ ____ ___    _      ____ _____ ____  _____    _    __  __ ___ _   _  ____   ____  _____ ______     _______ ____
#   |  _ \_   _|  \/  |  _ \  |  \/  | ____|  _ \_ _|  / \    / ___|_   _|  _ \| ____|  / \  |  \/  |_ _| \ | |/ ___| / ___|| ____|  _ \ \   / / ____|  _ \
#   | |_) || | | |\/| | |_) | | |\/| |  _| | | | | |  / _ \   \___ \ | | | |_) |  _|   / _ \ | |\/| || ||  \| | |  _  \___ \|  _| | |_) \ \ / /|  _| | |_) |
#   |  _ < | | | |  | |  __/  | |  | | |___| |_| | | / ___ \   ___) || | |  _ <| |___ / ___ \| |  | || || |\  | |_| |  ___) | |___|  _ < \ V / | |___|  _ <
#   |_| \_\|_| |_|  |_|_|     |_|  |_|_____|____/___/_/   \_\ |____/ |_| |_| \_\_____/_/   \_\_|  |_|___|_| \_|\____| |____/|_____|_| \_\ \_/  |_____|_| \_\
#
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.25.4 nginx-rtmp-module-master nginx-1.25.4.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 / streaming 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 changed the title to NGINX/RTMP/FFMPEG live-streaming server
  • M1GC featured this topic
  • M1GC locked this topic
  • M1GC unlocked this topic
Guest
This topic is now closed to further replies.
  • 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.

MuRdeR1 GaMinG CReW

We are a community of mature gamers who value character, honor, and professionalism

We are one of the newest active teams in online gaming.

We are diverse and open, with members from all across the world in multiple games.

M1GC Crew Gamers

We are organized and stable, with opportunities for both competitive and casual.
We accept players of all skill levels and help members grow at their own pace.

M1GC Crew Websites

×
×
  • Create New...

Important Information

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