How to Setup a NGINX RTMP Server for Streaming

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

A lot of streaming services require you to use an RTMP server, but what’s the difference between a RTMP and HTTP?

The “nginx-rtmp hls live streaming” is a tutorial on how to setup a NGINX RTMP server for streaming. The tutorial also includes the “Must Have” text.

How to Setup a NGINX RTMP Server for Streaming

Is your live stream often crashing? If that’s the case, you’ll need to locate a trustworthy means to host your stream. But don’t worry if you can’t afford the more costly alternatives. NGINX RTMP will come to the rescue. NGINX RTMP is a dependable open-source module, which means it’s completely free!

You’ll learn how to set up an NGINX RTMP server in this guide so you can create a stable live stream with your website.

Ready? Continue reading to learn how to set up a live broadcast.

Prerequisites

This will be a hands-on presentation in this course. If you want to follow along, make sure you have the following items on hand:

  • A Linux server — This demonstration utilizes Ubuntu 20.04 LTS, however NGINX may run on any Linux distribution.

Related: [Step-by-Step] How to Install Ubuntu 20.04

  • On the Linux server, NGINX is installed.
  • A user with sudo rights who isn’t root.
  • 2 GB RAM, 2 CPU Cores, and a 20 GB HDD are the minimum requirements for running a live stream server.

These are only recommendations. The precise figures are determined by your specific traffic requirements. You’ll need more powerful servers to host and broadcast your live video if you have a lot of visitors. An NGINX RTMP server with two CPUs and two gigabytes of RAM is adequate for testing in a development environment.

Setting up an RTMP Server

After you’ve completed the requirements, you may begin installing and configuring your RTMP server. To transform your NGINX server into an RTMP server, first install an NGINX module, then modify the NGINX configuration file to allow users to watch live broadcasts.

1. To update all of your packages, open your terminal and type apt update. This command synchronizes your package database with Ubuntu’s most recent database.

All of your packages need to be updated.All of your packages need to be updated.

2. Then, on your Linux server, use the following command to install an RTMP server.

NGINX’s libnginx-mod-rtmp module changes your NGINX server into an RTMP server. This module allows NGINX to interface with Adobe Flash Player, allowing you to stream live video or audio. It is officially supported by the Adobe Flash Player development team.

install libnginx-mod-rtmp -y sudo apt install libnginx-mod-rtmp -y

 setting up an RTMP server setting up an RTMP server

3. In your preferred editor, open the /etc/nginx/nginx.conf file to setup your RTMP live application. NGINX configuration file nginx.conf includes various directives or blocks that determine the behavior of the NGINX service.

4. Finally, add the following code to the nginx.conf file, save the modifications, and quit the editor.

The code below directs NGINX to operate as an RTMP server, allowing your users to watch live broadcasts.

# This section of code instructs NGINX to function as an RTMP server. # Specifies the port on which the server will listen. listen 1935; # The size of each data chunk that will be transmitted. If the chunk is too tiny, Flash Player may freeze, perhaps causing a buffer overflow. # The IP addresses are authorized to publish material to the server with a chunk size of 4096. # Only allow content to be published on NGINX RTMP from the localhost. allow 127.0.0.1 to be published; # Make it impossible for anybody else to post. refuse to publish everything; # Creates a named application called “live” application live # Tells NGINX to allow users to watch live feeds. continue to exist; This line instructs NGINX to turn off recording. If you don’t add this line, NGINX will keep recording and saving your stream to your disk indefinitely. mute; mute; mute; mute; mute; mute;

Setting up a Firewall to Protect Your Network

You’ve already set up your NGINX RTMP server, but now you must encrypt your network and manage traffic flow. How? By configuring the Uncomplicated Firewall (UFW), which is Ubuntu’s default firewall.

How to Configure the UFW Firewall on Linux

If your NGINX RTMP server is behind a firewall, you must grant access to the NGINX RTMP server port. Because your NGINX RTMP server is set to listen on port 1935, you’ll need to allow this port via your firewall.

1. Add a firewall rule to your firewall that opens port 1935 using the following command. This firewall rule enables all incoming and outgoing requests to reach your NGINX RTMP server on port 1935.

Using your firewall, open Port 1935.Using your firewall, open Port 1935.

2. Then, to deactivate and re-enable your firewall, use the command below. This command essentially resets the firewall, allowing any modifications to take effect.

sudo ufw disable && sudo ufw enable

3. Finally, execute the command below to check your firewall’s status and see whether port 1935 is available from all IP addresses (Anywhere).

Checking whether Port 1935 is reachable from any locationChecking whether Port 1935 is reachable from any location

Using FFmpeg to Stream Video

Now that your NFINX RTMP server is up and running, it’s time to build an example video using FFmpeg and stream it via your NGINX RTMP server. FFmpeg is a comprehensive tool for recording, converting, and streaming music and video in a variety of applications, including VLC, OMXPlayer, and VobSub.

You’ll be testing video streaming on your server, and any video with a minimal file size will suffice.

1. Use the apt install command to install the dependencies needed for FFmpeg to function correctly.

The following is installed using the command below:

  • libpcre3 — A regex library for parsing and compiling regular expressions that is utilized by the ffmpeg toolkit.
  • libpcre3-dev — This package provides the libpcre3 package’s development headers.
  • libssl-dev — This is the OpenSSL cryptographic library that your RTMP server uses to make SSL/TLS connections.
  • zlib1g-dev: The zlib library is a compression and decompression library that facilitates the transmission of audio and video files over the Internet.

sudo apt install libpcre3 libpcre3-dev libssl-dev zlib1g-dev libpcre3-dev libssl-dev zlib1g-dev

Installing Dependencies That Are RequiredInstalling Dependencies That Are Required

2. After that, use the command below to install ffmpeg on your server.

ffmpeg -y sudo apt install

FFmpeg installationFFmpeg installation

3. Finally, use the ffmpeg command to establish a new live stream by doing the following:

  • Read input (re) at the original framerate from the source file I Make careful to substitute video.mp4 with the directory and filename of your movie.
  • Copy the video format (c:v copy) and encode the audio using the AAC codec (c:a aac).
  • Set the sample rate of the audio to 44100 Hz (ar 44100). If the sample rate of your video is less than this figure (44100 Hz), FFmpeg uses interpolation to boost it.
  • Set the audio channels to one (mono) (ac 1) and the video format to be streamed by FFmpeg (-f flv).
  • Set your RTMP live program (rtmp://localhost/live/streamname.flv) that you configured in the “Setting up an RTMP Server” section (step four). You can change streamname.flv to any name you prefer.

ffmpeg -re -i “video.mp4” ffmpeg -re -i “video.mp4” -c:v copy -c:a aac -ar 44100 -ac 1 -f flv rtmp:/139.180.203.6:1935/live/streamname.flv rtmp:/139.180.203.6:1935/live/streamname.flv

The ffmpeg command displays out the frame per second it detects, the bitrate, and the frames per second of the freshly produced RTMP live stream, as seen below.

Data from an RTMP Live Stream may be seen.Data from an RTMP Live Stream may be seen.

Conclusion

You learnt how to configure your NGINX RTMP server and allow live streaming on your server by altering the NGINX configuration file in this article. You’ve also mentioned utilizing the FFmpeg tool to create a video live stream using your NGINX RTMP server.

You’ve just realized that setting up a live stream doesn’t have to cost you every penny. At this point, why not integrate your stream into your web page using the HTML5 <video> element. Or set up an OBS Studio for your RTMP stream?

The “nginx rtmp server on windows in 5 minutes” is a tutorial that will help you setup a NGINX RTMP server for streaming. The tutorial includes detailed step-by-step instructions, and it is meant for Windows users.

Frequently Asked Questions

Related Tags

  • rtmp server free
  • nginx rtmp server windows
  • nginx rtmp windows 10
  • nginx rtmp module install
  • nginx rtmp multiple streams

Table of Content