
RTMP Streaming Server
- streaming
- RTMP
- videostream
- video
- broadcast
- OBS-Client
- Multistreaming
RTMP Overview
The popularity of live video streaming is steadily rising on the Internet, and platforms like Twitch or YouTube offer the framework to indulge in countless hours of live and recorded content. Although these platforms offer a rudimentary free solution, their content is frequently accompanied by advertisements unless a paid subscription is in place.
For those seeking complete authority over their content, the availability of open-source solutions makes configuring a personal live streaming server a straightforward process. This server can be set up to utilize the RTMP protocol, granting you the freedom to control your content without restrictions.
We recommend you follow this tutorial using a Production-Optimized Instance.
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have an account and are logged into the Scaleway console
- You have configured your SSH key
- You have a virtual cloud server running on Ubuntu Bionic Beaver (18.04)
Setting up the server
-
Log into the Instance via SSH
-
Update the apt sources lists and upgrade the software already installed on the instance:
apt update && apt upgrade -y -
All required packages for the basic server configuration are available via APT. Install
nginx
and the required packages:apt install build-essential libpcre3 libpcre3-dev libssl-dev nginx libnginx-mod-rtmp ffmpeg -y -
Open the Nginx configuration file
/etc/nginx/nginx.conf
in a text editor:nano /etc/nginx/nginx.confAnd add the following lines at the end of the configuration file:
rtmp {server {listen 1935;chunk_size 4096;notify_method get;application live {on_publish http://localhost/auth;live on;#Set this to "record off" if you don't want to save a copy of your broadcastsrecord all;# The directory in which the recordings will be storedrecord_path /var/www/html/recordings;record_unique on;}}}This sets up the live streaming server as well as recording of the streams. These will be stored in the directory
/var/www/html/recordings
of the instance. -
Create the directory for recordings and make it writeable to the web server software:
mkdir -p /var/www/html/recordingschown -R www-data:www-data /var/www/html/recordings/ -
Open the file
/etc/nginx/sites-enabled/default
in a text editor and add alocation
block to the server configuration:nano /etc/nginx/sites-enabled/defaultlibnginx-mod-rtmp
does not support authentication by default. To avoid your media being broadcasted by someone with access to the stream key, copy and paste the following content into the server configuration block, under theserver_name
block, to set up a basic authentication mechanism. It will ask for a password when streaming. If the password is not correct, the user will see a401 - Unauthorized
message:location /auth {if ($arg_pwd = 'a_secret_password') {return 200;}return 401;}Replace
a_secret_password
with a secret password of your choice which authenticates against the server for broadcasting streams. -
Restart the Nginx web server:
systemctl restart nginx.service
Configuring the OBS client
To broadcast a stream from a local computer to the streaming server, a broadcast system is required. Download OBS Studio, an open source broadcasting solution, which is available for Linux, macOS and Windows.
-
In the Controls section of the Interface, click Settings to enter the OBS configuration interface:
-
Enter the Stream tab and enter the Information about your streaming instance:
Server:
- Service: Custom
- Server:
rtmp://<instance_ip>/live
- Stream Key: your_stream?pwd=a_secret_password (replace your_stream with a custom name of your stream and a_secret_password with the password you have set in the Nginx configuration)
Save the configuration and set up your scene within OBS Studio.
-
When ready, start broadcasting to your instance by clicking on Start Streaming in the Controls section of OBS.
Connecting to the stream
The stream can be viewed in your favorite media player, for example VLC media player.
-
Start VLC and click Open Media
-
Click the Network tab and enter the URL of your Stream:
- URL:
rtmp://<instance_ip>/live/<your_stream>
- URL:
-
Click Open and your stream will be visible in the media player.
Setting up multi-streaming
It is also possible to rebroadcast a stream to platforms like YouTube, Facebook or Twitch to stream on multiple platforms at the same time.
-
Open the Nginx configuration file
/etc/nginx/nginx.conf
in a text editor:nano /etc/nginx/nginx.conf -
Edit the file as required for the different streaming services that you want to use:
rtmp {server {listen 1935;chunk_size 4096;notify_method get;application live {on_publish http://localhost/auth;live on;record all;record_path /var/www/html/recordings;record_unique on;# Define the applications to which the stream will be pushed, comment them out to disable the ones not needed:push rtmp://localhost/twitch;push rtmp://localhost/facebook;}# Twitch Stream Applicationapplication twitch {live on;record off;# Only allow localhost to publishallow publish 127.0.0.1;deny publish all;# Push URL with the Twitch stream keypush rtmp://live-cdg.twitch.tv/app/<twitch_stream_key>;}# Facebook Stream Applicationapplication facebook {live on;record off;#Only allow localhost to publishallow publish 127.0.0.1;deny publish all;# Push URL with the Facebook stream keypush rtmps://live-api-s.facebook.com:443/rtmp/<facebook_stream_key>;}}}It is possible to add additional applications in the same way as the examples above.
-
Restart Nginx to activate the new configuration:
systemctl restart nginx.service -
Start broadcasting from OBS. You can now either view your stream via a media player like VLC, but also from broadcasting platforms like twitch: