RTMP is great for serving live content. When RTMP is paired with FFmpeg, streams can be converted into various qualities. Streaming-Servers.com is great for these applications as they provide fast and dedicated CPU performance. Streaming-Servers.com global network also ensures that you can deliver high quality live content with minimal delay.
Lets get started!
1. Connect with putty to your Server with preinstalled Ubuntu 14.04.x LTS 64 Bit
2. Enter following commands in your Shell (exclude the lines with #)
3. Once the installation is, lets configure Nginx-RTMP and FFmpeg
Open the Nginx configuration file.
Append the following
After you've added the above, you can customize settings such a video bitrate, audio bitrate and resolution. These changes will only be applied to the lower quality stream. To add more qualities, copy and paste the exec ffmpeg line and change the settings. You'll also need to create a new application. You can do this by copying and pasting the live720 example that has been included. Don't forget to update the exec ffmpeg line with the address of the new application. You can do this by changing the final RTMP address in the exec ffmpeg line.
Save the file by pressing Control and X together. Restart Nginx.
Note: For best performance, each stream being converted should have its own CPU core. For example two qualities, 360P and 480P are being created from a 720P stream. A Streaming-Servers.com instance with at least two CPU cores should be used.
Security Note
If you're using a firewall, you'll need to make sure TCP 1935 is allowed.
The current configuartion allows anyone to stream to your server. We can fix this by only allowing certain IP addresses the publish permission. Open the Nginx configuration.
Look for the following lines
Add the following to each set of the above lines. Change 0.0.0.0 to your IP address.
The configuration should now look something like this
Save the file by pressing Control and X together. Restart Nginx.
Configuring Software to Work with Nginx-RTMP
Streaming applications typically have two fields for connection information. The first field is usually for the server information and the second field is usually for the stream name or key. The information that you should place into each field is listed. The stream name or key can be set to anything.
To view streams open the following links in a player (for example VLC Player) supporting RTMP.
Setting up a player to display live video on a website is beyond the scope of this guide.
Lets get started!
1. Connect with putty to your Server with preinstalled Ubuntu 14.04.x LTS 64 Bit
2. Enter following commands in your Shell (exclude the lines with #)
Bash:
apt-get install build-essential libpcre3 libpcre3-dev libssl-dev unzip software-properties-common
mkdir /usr/build
#Download the Nginx and Nginx-RTMP source.
wget http://nginx.org/download/nginx-1.7.8.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
#Extract the Nginx and Nginx-RTMP source.
tar -zxvf nginx-1.7.8.tar.gz
unzip master.zip
#Switch to the Nginx directory.
cd nginx-1.7.8
#Add modules that Nginx will be compiled with. Nginx-RTMP is included.
./configure --with-http_ssl_module --with-http_stub_status_module --with-http_secure_link_module --with-http_flv_module --with-http_mp4_module --add-module=../nginx-rtmp-module-master
#Compile and install Nginx with Nginx-RTMP
make
make install
#Install the Nginx init scripts.
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 nginx defaults
#Start and stop Nginx to generate configuration files.
service nginx start
service nginx stop
#Add the FFmpeg PPA and Installing FFmpeg
apt-add-repository ppa:jon-severinsson/ffmpeg
apt-get update
apt-get install ffmpeg
3. Once the installation is, lets configure Nginx-RTMP and FFmpeg
Open the Nginx configuration file.
Bash:
nano /usr/local/nginx/conf/nginx.conf
Append the following
Bash:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 1200K -s 720x576 -f flv -c:a aac -ac 1 -strict -2 -b:a 128k rtmp://localhost/live720p/$name;
}
application live720p {
live on;
record off;
}
}
}
After you've added the above, you can customize settings such a video bitrate, audio bitrate and resolution. These changes will only be applied to the lower quality stream. To add more qualities, copy and paste the exec ffmpeg line and change the settings. You'll also need to create a new application. You can do this by copying and pasting the live720 example that has been included. Don't forget to update the exec ffmpeg line with the address of the new application. You can do this by changing the final RTMP address in the exec ffmpeg line.
Note: Changing the value after -b:v will change the video bitrate. This is measured in kilobits per second. Changing the value after -b:a will change the audio bitrate. This is measured in kilobits per second. Changing the value after -s will change the resolution.
Save the file by pressing Control and X together. Restart Nginx.
Bash:
service nginx restart
Note: For best performance, each stream being converted should have its own CPU core. For example two qualities, 360P and 480P are being created from a 720P stream. A Streaming-Servers.com instance with at least two CPU cores should be used.
Security Note
If you're using a firewall, you'll need to make sure TCP 1935 is allowed.
The current configuartion allows anyone to stream to your server. We can fix this by only allowing certain IP addresses the publish permission. Open the Nginx configuration.
Bash:
nano /usr/local/nginx/conf/nginx.conf
Look for the following lines
Bash:
live on;
record off;
Add the following to each set of the above lines. Change 0.0.0.0 to your IP address.
Bash:
allow publish 127.0.0.1;
allow publish 0.0.0.0;
deny publish all;
The configuration should now look something like this
Bash:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
allow publish 127.0.0.1;
allow publish 0.0.0.0;
deny publish all;
exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 1200K -s 720x576 -f flv -c:a aac -ac 1 -strict -2 -b:a 128k rtmp://localhost/live720p/$name;
}
application live720p {
live on;
record off;
allow publish 127.0.0.1;
allow publish 0.0.0.0;
deny publish all;
}
}
}
Save the file by pressing Control and X together. Restart Nginx.
Bash:
service nginx restart
Configuring Software to Work with Nginx-RTMP
Streaming applications typically have two fields for connection information. The first field is usually for the server information and the second field is usually for the stream name or key. The information that you should place into each field is listed. The stream name or key can be set to anything.
Bash:
Field 1: rtmp://your.server.ip/live/
Field 2: stream-key-you-set
To view streams open the following links in a player (for example VLC Player) supporting RTMP.
Bash:
rtmp://your.server.ip/live/stream-key-you-set
rtmp://your.server.ip/live720p/stream-key-you-set
Setting up a player to display live video on a website is beyond the scope of this guide.
Last edited: