michaelkamprath / multi-service-rtmp-broadcaster

A dockerized livestream rebroadcaster
GNU General Public License v3.0
136 stars 25 forks source link
docker-image live-stream live-streaming obs obs-studio rtmp rtmp-broadcaster stream-rebroadcaster

Docker Image CI

Multi-Service RTMP Broadcaster

The goal of this project is to create a Docker-deployed service that will allow you to easily broadcast a live stream to multiple services (YouTube, Twitch, Facebook, etc) at the same time. This stream rebroadcaster is designed to be used by a single source / user.

Usage

The instructions here assume you are running on Linux. With some modification of the commands, you can make this Docker build work on Windows and Mac OS too.

The first step is to build the docker file. After you clone this repository, cd into and and issue:

docker build -t multistreaming-server ./multistreaming-server/

Once built, start the docker image on a host that has sufficient bandwidth to handle all the rebroadcasting you will do:

docker run -it -p 80:80 -p 1935:1935 \
  --env MULTISTREAMING_PASSWORD=__made_up_password__ \
  -v /path/to/my-rtmp-config.json:/rtmp-configuration.json \
  multistreaming-server:latest

If this is a host than where you built the docker image, you will need to push the docker image to that host (or build it there). Alternatively, you could use the DockerHub build of this image by pulling and using the kamprath/multistreaming-server:latest Docker image. Also, if you plan on doing any transcoding when rebroadcasting a stream, you need to ensure that your docker host's CPU is sufficient for the job. It is recommend that the host CPU has at least four cores for each distinct transcoding the multi-streaming server will do. If the host CPU is not sufficient, bit rates on the transcoded streams will suffer.

Note that some environment variables should be set when running the Docker image:

You must also create and JSON file with the RTMP rebroadcasting configuration you desire. This file should get mapped from your local file system to the /rtmp-configuration.json file path within the Docker container. The JSON file has the following elements:

Here is an example of the JSON configuration file:

{
  "endpoint": "live",
  "transcodeProfiles": {
    "720_60fps": {
      "pixels": "1280x720",
      "videoBitRate": "4500k",
      "videoFrameRate": 60
    }
  },
  "rebroadcastList": [
    {
      "name": "linkedin-via-restream",
      "platform": "restream",
      "streamKey": "whatever",
      "transcode": {
        "pixels": "1920x1080",
        "videoBitRate": "3500k",
        "videoKeyFrameSecs": 2,
        "audioBitRate": "160k",
        "audioSampleRate": 44100
      }
    },  
    {
      "name": "youtube",
      "platform": "youtube",
      "streamKey": "abc123"
    },
    {
      "name": "facebook-1",
      "platform": "facebook",
      "streamKey": "def456",
      "transcodeProfile": "720_60fps"
    },
    {
      "name": "facebook-2",
      "platform": "facebook",
      "streamKey": "ghi789",
      "transcodeProfile": "720_60fps"
    },
    {
      "name": "periscope",
      "platform": "periscope",
      "regionCode": "ca",
      "streamKey": "jkl012",
      "transcode": {
        "pixels": "1280x720",
        "videoBitRate": "3500k",
        "videoKeyFrameSecs": 3,
        "audioBitRate": "128k",
        "audioSampleRate": 44100
      }
    }
  ]
}

Note that as long as the name elements are different, you can have more than one destination pushing to the same platform, each with different streamKey values.

If you would like to capture a recording of the stream sent to the ingest endpoint, bind a local directory on your host to the /var/www/html/recordings/ file path within the Docker image when launching the Docker container. You can also see statistics about the various streams this server is pushing by visiting this web page: http://__docker_host_IP_address__/stat. You can optionally disable recording by setting the env var CONFIG_DISABLE_RECORD to a non-empty value.

Once the Docker image is running, set up your stream software with the following parameters:

In OBS, you would set the above parameters for a "Custom..." Service in the Stream settings.

The next thing to do is start your stream!

Development

In order to develop on this repository, you must have a python 3.7 environment and Pipenv installed.

Future work

Goals for future improvements to this project include:

Pull requests are welcome!

Acknowledgements

This work was heavily influenced by the following articles: