Coder Social home page Coder Social logo

dudoleitor / docker-nginx-rtmps Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 4.0 33 KB

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

License: MIT License

Dockerfile 68.58% Shell 31.42%
docker docker-container rtmp rtmp-server rtmps stunnel live livestream restream restreamer

docker-nginx-rtmps's Introduction

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.

docker-nginx-rtmps's People

Contributors

dudoleitor avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.