How to build a multi-streaming server for Microsoft Live Events with a Raspberry Pi

John Moore
4 min readDec 5, 2020

This guide will take you through the steps needed to configure a Raspberry Pi to act as an RTMP server so that you can stream directly to the Pi and then have it multi-stream to other destinations! There are many other guides about NGINX with RTMP on a Raspberry Pi, but they unfortunately don’t cover what you need to integrate with Microsoft Stream.

My hope is this will fill the Microsoft knowledge gap and help you avoid a monthly expense for a restreaming service. This guide is provided without warranty or any expectation that I would have the capacity to help support your own setup. Let’s get started!

I recently went through all of these steps in a livestream on my YouTube channel. If you’d like to follow along with that to get even more context, please watch below:

Credit where credit is due

I learned this process from several other guides and am pulling what I learned together to share what worked for me. Please check out these other guides for other great content about live video:

How to make an RTMP Streaming Server and Player with a Raspberry Pi
— By Aaron Parecki

Raspberry Pi Broadcast Configurations Google Doc
— By AdamLightUK

The magic piece needed for getting NGINX to work with Microsoft Stream
— By hovee

Scaleway’s Guide To RTMP Streaming Servers
— By Scaleway

Parts List

Set up the Raspberry Pi

  1. Assemble the Pi into the case
  2. Flash the OS to the MicroSD Card using the Raspberry Pi Imager. I chose to install Raspbery Pi OS (other) > Raspberry Pi OS Lite (32-bit)
  3. Insert the MicroSD card, plug in the monitor, keyboard, and power on the Pi
  4. Log in using the default username pi and password raspberry

Initial Setup

  1. In the command line, enter:
sudo raspi-config

2. Select the first option and set a new password for the pi user.

3. Select Network Options and then Hostname. Set a hostname. I chose to name mine “multi-streamer”.

4. Select Interfacing Options and enable SSH so you can remotely log into the pi from another computer.

5. Select Finish to exit raspi-config.

5. Set a static ip address.

sudo nano /etc/dhcpcd.conf

add the following to the bottom of the dhcpcd.conf file:

interface eth0
static ip_address=[whatever IP address you pick]/24
static routers=[your router's IP address]
static domain_name_servers=[your router's IP address]

Press CTRL+X and then Y and press Enter

6. Get updates, install updates, and Reboot the Pi.

sudo apt-get update
sudo apt-get upgrade
reboot

7. After the Pi reboots, you can now SSH to the Pi from another computer using Putty on Windows or Terminal on macOS.

ssh pi@[hostname of your pi].local

Install NGINX and the RTMP module

  1. Install NGINX.
sudo apt install nginx

2. Install the RTMP module for NGINX.

sudo apt-get install libnginx-mod-rtmp

Configure the RTMP server

  1. Open the NGINX.conf file.
sudo nano /etc/nginx/nginx.conf

2. Scroll to the very bottom of the text file and enter rtmp config info below. This is where Microsoft Stream is a bit special. For ingest URL’s that are provided by Microsoft Stream, there are two unique codes in the URL. This very long URL must be split into two parts. You will find that the middle of the URL contains ‘channel.media.azure.net:1935/live/[uniquecode]’. What you’ll need to do is paste this URL into the conf file and then split the URL just after the ‘1935’ and enter a space and then ‘app=live/[uniquecode]’. Be careful to look at the example in the code block to understand the format.

rtmp {     server {          listen 1935;          chunk_size 4096;          notify_method get;          application live {               live on;               record off;               push rtmp://localhost/microsoftstream;               push rtmp://localhost/youtube;          }          application microsoftstream {               live on;               record off;               allow publish 127.0.0.1;               deny publish all;               push [First half of Stream URL Here] app=[Second Half of Stream URL Here];          }          application youtube {                live on;                record off;                allow publish 127.0.0.1;                deny publish all;                push rtmp://a.rtmp.youtube.com/live2/[YouTube Stream Key Here];          }     }}

3. Press CRTL+X then enter Y then hit Enter to save conf file.

4. Restart NGINX.

sudo systemctl restart nginx 

Configure your encoder

  1. Enter “rtmp://[Hostname of the Pi]:1935/live/“ for the server and anything you want for the key. You must enter a key for Microsoft Stream to work.
  2. Be sure to set your encoder’s output to 30fps and Keyframe=2 for it to work properly with Microsoft Stream.

Test it out

  1. Set up a Microsoft Stream Live Event and start Setup in Stream.
  2. Add the ingest URL to the conf file in the proper application section where the [] are found.
  3. Get your YouTube stream key and add that to the conf file.
  4. Save the conf file and start sending data from the encoder and see if both start receiving data.

Some helpful commands to know

SSH to your Pi

ssh pi@<hostname>.local and enter password

Edit RTMP Settings

sudo nano /etc/nginx/nginx.conf

Test your NGINX config file

sudo nginx -t

Restart NGINX

sudo systemctl restart nginx

Reload your NGINX Config

sudo nginx -s reload

--

--