Streaming Via RTMP Using Nginx
Streaming Via RTMP Using Nginx
On the other hand, Nginx (pronounced in English 'engine X') is a lightweight web server/reverse proxy.
high performance and a proxy for email protocols (IMAP/POP3).
It is free software and open source, licensed under the simplified BSD License; it also exists
a commercial version distributed under the name of nginx plus. It is cross-platform, so it runs
on Unix-like systems (GNU/Linux, BSD, Solaris, Mac OS X, etc.) and Windows.
Nginx is used for a long list of sites web known,
such as: WordPress, Netflix, Hulu, GitHub, Ohloh, SourceForge, TorrentReactor and parts of Facebook
(like the server for downloading heavy zip files). The following graph shows the high
percentage of use of this web server worldwide on the internet (January 2018):
In this practice we will set up a media server using the Nginx web server with
RTMP on Ubuntu Linux.
This will take some time. With this line we install the necessary tools to be able to carry out the
compilation of the source code and the creation of the corresponding packages.
The next step is to obtain the source code of Nginx. In this practice, we will use version
1.8.1. For more recent versions, the procedure is similar.
1
Then we will do:
cd nginx
wget[Link]
Now we will need the source code for the Nginx-RTMP module, which we will download.
with the following orders:
wget [Link]
module/archive/[Link]
unzip [Link]
At this point, we will have a directory called nginx-1.8.1 that contains the source code.
from Nginx, and another directory called nginx-rtmp-module-master that contains the code
source of the Nginx-RTMP module. The next step is to reconfigure the source code of Nginx
to be compiled together with the Nginx-RTMP module, by means of:
cd nginx-1.8.1
When executing the command, a certain amount of text will scroll on the screen. Once it finishes,
the compilation and installation of Nginx is carried out with these two command lines:
make
sudo /usr/local/nginx/sbin/nginx
If the installation has been successful, the Nginx test page can be accessed if we use
a web browser and we connect to the IP of the Ubuntu server where we have done the
installation.
2
Service configuration.
The next step is to write the necessary lines in the [Link] file to configure the
RTMP module, which we will open with the text editor of our choice, in this case nano:
We go to the end of the file and copy the following lines, finally saving the
file once we have copied them:
rtmp {
server {
listen 1935;
chunk_size 8192;
application vod {
play /usr/local/nginx/rtmp;
With the lines written, what we have established in the configuration is that Nginx listens to the
streaming requests for port 1935, which is the default port for the protocol
RTMP.
We have also established the size of the audio or video transmission packets to
8192 bits each, which is a suitable standard size.
As the directory where the video files to be transmitted are located, we have specified the
Folder /usr/local/nginx/rtmp This folder does not exist, so it needs to be created and the ...
video files corresponding, which can only have the .mp4 formats
.flv, which are the only formats served by the Nginx-RTMP module:
The following is to restart the Nginx service, so that it acquires the configuration that
we have changed:
sudo /usr/local/nginx/sbin/nginx
3
Test.
To test the operation, we run the VLC media player and select the
Open network location, by entering the URL of the video to stream using
streaming.
The URL will start with rtmp:// to inform VLC which streaming protocol to use,
followed by the domain name or IP address of the Ubuntu server, then the name of the
"application" and finally the name of the video file to be transmitted. For example:
rtmp://ipdelservidor/vod/test.mp4
rtmp://ipdelservidor/vod/[Link]