Skip to content

Docker compose nginx rtmp(s). Uses environment variables for stream keys. WIP.

License

Notifications You must be signed in to change notification settings

stemcc/compose-nginx-rtmps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

compose-nginx-rtmps

This is a loose fork of nginx-rtmp-docker and nginx-rtmps which is itself a fork of nginx-rtmp. The purpose of this repository is primarily for testing various nginx streaming setups using docker compose.

It uses stunnel4 inside the same container running nginx (using the same container right now for the sake of simplicity, in future versions it should probably be seperated into its own service, or better yet, removed entirely in lieu of using nginx's stream directive).

How to use

  • Add your stream keys to the example environment file .nginx.env and uncomment the lines with keys.
  • Once you have added your keys, rename .nginx.env to .nginx.
  • Change the allowed publish IPs in .nginx.conf and nginx.conf.template to the IP addresses you're broadcasting from
  • Then run docker compose like normal, for example:
docker-compose up --build

How it works

source RTMP | nginx | rtmp public endpoints
                    | rtmp local endpoints | stunnel | rtmps public endpoints


References

https://github.com/peterhavener/nginx-rtmp-stunnel-docker

https://github.com/thiagoeolima/nginx-rtmps

https://dev.to/lax/rtmps-relay-with-stunnel-12d3

https://serverfault.com/questions/1019317/receiving-rtmps-stream-on-nginx-rtmp

arut/nginx-rtmp-module#457 (comment)

https://sites.google.com/view/facebook-rtmp-to-rtmps/home

https://charlesreid1.com/wiki/Stunnel/Docker#Set_up_client

nginx-rtmp

Docker image with Nginx using the nginx-rtmp-module module for live multimedia (video) streaming.

Description

This Docker image can be used to create an RTMP server for multimedia / video streaming using Nginx and nginx-rtmp-module, built from the current latest sources (Nginx 1.15.0 and nginx-rtmp-module 1.2.1).

This was inspired by other similar previous images from dvdgiessen, jasonrivers, aevumdecessus and by an OBS Studio post.

The main purpose (and test case) to build it was to allow streaming from OBS Studio to different clients at the same time.

GitHub repo: https://github.com/tiangolo/nginx-rtmp-docker

Docker Hub image: https://hub.docker.com/r/tiangolo/nginx-rtmp/

Details

How to test with OBS Studio and VLC

  • Run a container with the command above

  • Open OBS Studio

  • Click the "Settings" button

  • Go to the "Stream" section

  • In "Stream Type" select "Custom Streaming Server"

  • In the "URL" enter the rtmp://<ip_of_host>/live replacing <ip_of_host> with the IP of the host in which the container is running. For example: rtmp://192.168.0.30/live

  • In the "Stream key" use a "key" that will be used later in the client URL to display that specific stream. For example: test

  • Click the "OK" button

  • In the section "Sources" click de "Add" button (+) and select a source (for example "Screen Capture") and configure it as you need

  • Click the "Start Streaming" button

  • Open a VLC player (it also works in Raspberry Pi using omxplayer)

  • Click in the "Media" menu

  • Click in "Open Network Stream"

  • Enter the URL from above as rtmp://<ip_of_host>/live/<key> replacing <ip_of_host> with the IP of the host in which the container is running and <key> with the key you created in OBS Studio. For example: rtmp://192.168.0.30/live/test

  • Click "Play"

  • Now VLC should start playing whatever you are transmitting from OBS Studio

Debugging

If something is not working you can check the logs of the container with:

docker logs nginx-rtmp

Extending

If you need to modify the configurations you can create a file nginx.conf and replace the one in this image using a Dockerfile that is based on the image, for example:

FROM tiangolo/nginx-rtmp

COPY nginx.conf /etc/nginx/nginx.conf

The current nginx.conf contains:

worker_processes auto;
rtmp_auto_push on;
events {}
rtmp {
    server {
        listen 1935;
        listen [::]:1935 ipv6only=on;

        application live {
            live on;
            record off;
        }
    }
}

You can start from it and modify it as you need. Here's the documentation related to nginx-rtmp-module.

Technical details

  • This image is built from the same base official images that most of the other official images, as Python, Node, Postgres, Nginx itself, etc. Specifically, buildpack-deps which is in turn based on debian. So, if you have any other image locally you probably have the base image layers already downloaded.

  • It is built from the official sources of Nginx and nginx-rtmp-module without adding anything else. (Surprisingly, most of the available images that include nginx-rtmp-module are made from different sources, old versions or add several other components).

  • It has a simple default configuration that should allow you to send one or more streams to it and have several clients receiving multiple copies of those streams simultaneously. (It includes rtmp_auto_push and an automatic number of worker processes).

Latest Changes

  • Add compose file, periscope and twitch variables to environment files

License

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

About

Docker compose nginx rtmp(s). Uses environment variables for stream keys. WIP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published