We recommend you follow this tutorial using a Production-Optimized Instance.
Setting up a RTMP streaming server on a Scaleway Instance
- streaming
- RTMP
- broadcast
- OBS-Client
- Multistreaming
The Internet’s fascination with live video streaming continues to soar, with platforms such as Twitch and YouTube providing easy access to engage with live and recorded content.
However, while these platforms offer basic free options, users often encounter interruptions in the form of advertisements unless they opt for a paid subscription.
For individuals craving absolute control over their content, open-source solutions offer a compelling alternative. By configuring a personal live-streaming server, users can gain complete autonomy over their broadcasts. Using the open-source RTMP protocol on self-hosted streaming servers, users gain autonomy to manage their content free from external constraints and interruptions.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- An SSH key
- An Instance 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 the 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:nano /etc/nginx/sites-enabled/default -
Add a
location
block to the server configuration under theserver_name
block, and replacea_secret_password
with a password of your choice, which authenticates against the server for broadcasting streams:location /auth {if ($arg_pwd = 'a_secret_password') {return 200;}return 401;}Notelibnginx-mod-rtmp
does not support authentication by default. To avoid your media being broadcasted by someone with access to the stream key, adding the location block sets 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. -
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>;}}}TipYou can 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, and also from broadcasting platforms like Twitch: