Nginx RTMP module on Ubuntu 18.04 with RTMPS support for Facebook live streaming
1 Introduction
This how-to is for converting a unencrypted RTMP video stream to a encrypted RTMPS video stream for use on Facebook.
1.1 Background
Hardware and Software live-streaming encoders have typically used the RTMP streaming protocol. With the Facebook enforcement of the RTMPS encrypted live-streams, some older hardware and software encoders can no longer work. By using the method below we can convert RTMP to RTMPS using a Nginx on Ubuntu server 18.04 via a cheap Raspberry pi.
2 Nginx
2.1 Configuration
Install Nginx and RTMP module (On Ubuntu server 18.04)
This configuration assumes that nginx and stunnel is installed on the same machine.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx -y
sudo apt-get install libnginx-mod-rtmp -y
Edit nginx.conf
sudo nano /etc/nginx/nginx.conf
Add to the end of nginx config
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
push rtmp://127.0.0.1:1936/rtmp/<<Facebook persistent stream key>>;
}
}
}
restart nginx
sudo systemctl restart nginx
If any errors occur at this stage recheck your configuration.
2.2 Nginx and RTMP module setup test (Optional)
Before moving onto the Stunnel configuration its wise to first check Nginx and RTMP module are working correctly
2.2.1 Test tools
To test setup use OBS to send video and VLC Player to play video.
OBS >> Ngnix >> VLC Player
2.2.2 OBS Stream configuration
>> Settings >> Stream
Service: Custom
Server: rtmp://<<ngnix server IP address>>/live
Stream Key: test
2.2.3 VLC Configuration
>>Open Network Stream>>Network
Please enter a network URL: rtmp://<<ngnix server IP address>>/live/test
3 Stunnel
3.1 Configuration
sudo apt-get install stunnel4 -y
Edit stunnel auto boot configuration
sudo nano /etc/default/stunnel4
Change ENABLE from 0 to 1
ENABLE=1
Edit stunnel configuration
sudo nano /etc/stunnel/stunnel.conf
pid = /var/run/stunnel4/stunnel.pid
output = /var/log/stunnel4/stunnel.log
setuid = stunnel4
setgid = stunnel4
# https://www.stunnel.org/faq.html
socket = r:TCP_NODELAY=1
socket = l:TCP_NODELAY=1
debug = 4
[fb-live]
client = yes
accept = 1936
connect = live-api-s.facebook.com:443
verifyChain = no
3.1.1 Enable enable after boot
sudo systemctl enable stunnel4.service
3.1.2 restart stunnel
sudo systemctl restart stunnel4.service
4 Final Comments
Any errors at this stage maybe due to error in the config. Double check Ports. ngnix an stunnel need to be on different ports when used on the same machine.
4.1 Facebook Setup
For those who are having problems make sure you (in this order)
Setup the Facebook live stream page www.facebook.com/live/producer/ (See picture below)
Start the stream via OBS, Hardware encoder or other device
After about 30 seconds or so the Facebook live stream page will acknowledge a video steam. (See picture below)
On the same page click "Go Live"
From my understand unless you are using a "paired encoder" it is not possible to go live without the extra steps with every new stream.