Skip to content

This docker container receives a single rtmp stream and pushes the feed to YouTube and Facebook live using rtmps.

License

Notifications You must be signed in to change notification settings

Dudoleitor/docker-nginx-rtmps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

docker-nginx-rtmps

Using this container you can stream simultaneously to multiple rtmps destinations, for the time being it pushes the feed to YouTube and Facebook live.

Description

Use cases

A lot of streaming software (such as the popular OBS) is capable of streaming to a single destination only and you may have the need to publish your live to more than just one social network at the same time. Sure you can install a plugin to accomplish this, but you are increasing the load on the same hardware that is already under stress. In addition to this, you can use a docker container to split the stream coming from dedicated video switchers that may not support multiple destinations (for example the ATEM Mini by Blackmagic).

What does the container do

Inside the docker container runs nginx, a popular web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The webserver receives the stream coming from your device and is capable of pushing it back to multiple destinations. The rtmp engine sends the feed (using the rtmp protocol) to an stunnel daemon which encrypts it so that it can be sent out as rtmps. Stunnel is specifically designed to add TLS encryption functionality without any changes in the programs' code so works perfectly after nginx.

How to use

  1. First of all, open Youtube and Facebook live
  2. Paste your streaming keys into the proper configuration file: download nginx.conf (wget https://raw.githubusercontent.com/Dudoleitor/docker-nginx-rtmps/main/nginx.conf) and open it with your favourite text editor (nano nginx.conf)
  • Replace YouTube_key_here and Facebook_key_here accordingly (without the / at the end!)
  1. Now start the container mouting the file you just edited and forwarding the input port 1935 tcp:
  docker run -d -p 1935:1935 -v /path/to/edited/file/nginx.conf:/usr/local/nginx/conf/nginx.conf:ro dudoleitor/nginx-rtmps
  1. Configure your streaming software and start the live feed:
  - Server: rtmp://yourIP:1935/live
  - Streaming key: (leave blank)
  • yourIP should be the address your container is listening on, be sure to properly configure port-forwarding on your firewall to allow connections on port 1935 TCP.
  1. Done! Both YouTube and Facebook should now be receveing your feed.

Security note!

Please be aware that any connection to rtmp://yourip/live will be accepted by nginx, this means anyone can connect to your stream without proper security measures. You could edit the configuration file to set up a custom input streaming key or configure the firewall to allow only trusted IPs.

Troubleshooting

If you need to open a shell inside the container while it's running, first get the instance name using docker ps and then run

docker exec -it containerID bash

Advanced notes

The container is pushing the feed to rtmps://a.rtmps.youtube.com:443/live2 and to rtmps://live-api-s.facebook.com:443/rtmp/.

If you need to change the default behaviour, follow this steps:

  1. Download and edit the stunnel.conf file, you can change the destination servers and/or add another service
  2. Edit the nginx configuration, you need a push directive for each destination (use ports 1935x for the local sockets, matching the stunnel configuration); if you do not want to use rtmps (defaulting to rtmp) skip the stunnel part and configure the final url directly in the nginx.conf file
  3. Download the Dockerfile and the docker-start.sh file, build your custom image with docker build -t yourImageName /path/to/Dockerfile, be sure to have the stunnel.conf and docker-start.sh files in your working directory
  4. Start the container replacing dudoleitor/nginx-rtmps with your custom image name.

Similar projects and guides

Why this project is (a little) different from the others online

On the internet there are a lot of examples and guides to help you split a video stream but the majority of them does not support rtmps. Please note that Facebook live recently blocked non-encrypted traffic (rtmp) allowing only rtmps. Because of this this, I decided to develop a docker container capable of dealing with multple streams and rtmps. Why a docker container? In this case, because it's very easy to start it, just have a few lines of configuration and it can be up and running within minutes.

Useful links

I was inspired by this project from Sebastián Ramírez @tiangolo; this guide on the official nginx blog helped me install and configure nginx. If you need to understand how the link between nginx and stunnel work, I suggest you to check out this article on dev.to.

License

This project is licensed under the terms of the MIT License.

About

This docker container receives a single rtmp stream and pushes the feed to YouTube and Facebook live using rtmps.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published