Skip to content

Instantly share code, notes, and snippets.

@amitkhare
Last active November 22, 2023 02:29
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amitkhare/55155f9ae97013c45eff84eef84ab244 to your computer and use it in GitHub Desktop.
Save amitkhare/55155f9ae97013c45eff84eef84ab244 to your computer and use it in GitHub Desktop.
Nginx RTMP module on Ubuntu 18.04 with RTMPS support for Facebook live streaming Hardware and Software live-streaming encoders have typically used the RTMP streaming protocol. With the Facebook enforcement of the RTMPS encrypted live-stream some older hardware and software encoders can no longer work. By using the method below we can convert RTM…

update

sudo apt-get update
sudo apt-get upgrade

install nginx

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.

Test Setup

To test setup use OBS to send video and VLC Player to play video.

OBS >> Ngnix >> VLC Player

OBS Stream configuration

Settings>>Stream

Service: Custom Server: rtmp://<>/live Stream Key: test VLC Configuration

Open Network Stream>>Network

Please enter a network URL: rtmp://<>/live/test

Stunnel

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

Enable enable after boot

sudo systemctl enable stunnel4.service

restart stunnel

sudo systemctl restart stunnel4.service

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.

@natzakaria
Copy link

Hi Can you post the codes to enable HLS?

@Ahmedbadereldin
Copy link

what about linkedin ?
how can we solve it

@therealmrnerd
Copy link

"libnginx-mod-rtmp : Depends: nginx-common (= 1.14.0-0ubuntu1.10) but 1.22.0-1ppastableubuntu18.04.1 is to be installed"

Any idea how to get this installed on a 1.22 install?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment