62°F

Aaron Parecki

  • Articles
  • Notes
  • Photos
  • How to make an RTMP Streaming Server and Player with a Raspberry Pi

    September 7, 2020

    In this tutorial we'll use a Raspberry Pi to build an RTMP server that plays out any video stream it receives over the Raspberry Pi's HDMI port automatically. This effectively turns a Raspberry Pi into a Blackmagic Streaming Bridge.

    You can use this to stream from OBS or an ATEM Mini across your local network or the internet, and convert that to an HDMI signal in your studio to mix with other HDMI sources locally.

    UPDATE: The latest version of the Raspberry Pi OS removes omxplayer which is a key component of this tutorial! Until I can update these instructions for the latest Raspberry Pi OS, you can still download the previous version here.

    Parts

    Here's a list of all the parts you'll need for this.

    Of course, you'll need a Raspberry Pi. It doesn't need a ton of RAM, I got one with 4GB but it would probably work fine with 2GB as well. I prefer to buy the parts individually rather than the full kits, but either way is fine. If you get the bare Raspberry Pi you'll need to make sure to get a good quality power supply like this one.

    I have tested this on a Raspberry Pi 3, and it does work, but there's much more of a delay, so I definitely recommend doing this with a Raspberry Pi 4 instead.

    Get a good quality SD card for the Pi. We won't be doing anything super disk intensive, but it will generally perform a lot better with an SD Card with an "A1" or "A2" rating. You don't need much disk space, 16gb, 32gb or 64gb cards are all good options. The "A1" or "A2" ratings mean the card is optimized for running applications rather than storing photos or videos. I like the Sandisk cards, either the 32gb A1 or the slightly faster 64gb A2.

    You'll need a case for the Pi as well. I like this one which is also a giant heat sink so that it's completely silent.

    The Raspberry Pi 4 has a Micro HDMI port rather than a full size, so you'll need a cable to plug that in to a regular size HDMI port like this one.

    Make sure you have your Raspberry Pi and whatever device you're streaming from connected via a wired network. While this will probably work over wifi, I wouldn't count on wifi to be reliable or fast for this.

    Prepare the Raspberry Pi SD Card

    First, head over to raspberrypi.org/downloads to download the Raspberry Pi Imager app. This app makes it super easy to create an SD card with the Raspberry Pi OS.

    imager app

    When you choose the operating system to install, select "Other"

    Other OS

    then choose "Lite"

    Lite

    We don't need a desktop environment for this so it will be easier to use the command line.

    Go ahead and write this to the SD card, then take out the SD card and put it into the Raspberry Pi.

    Configure the OS

    The first time you boot it up it will take a few seconds and then it will prompt you to log in.

    login

    Log in using the default username and password. Enter the username "pi", and then type the password "raspberry". You won't see the password as you're typing it.

    It's a good idea to change the password to something else, so go ahead and do that now. Type:

    sudo raspi-config
    

    and choose the first option in the menu by pressing "Enter". When you type the new password, you won't see it on the screen, but it will ask you to type it twice to confirm. Press "tab" twice to select "Finish" to close out of this menu.

    change password

    Next we need to configure the video mode so we know what kind of signal the Raspberry Pi will be sending on the HDMI port. You'll need to edit a text file to make these changes.

    sudo nano /boot/config.txt
    

    This will launch a text editor to edit this file. We need to change the following things in the file. These may be commented out with a # so you can delete that character to uncomment the line and make the necessary changes. These options are documented here.

    # Make sure the image fits the whole screen
    disable_overscan=1
    
    # Set HDMI output mode to Consumer Electronics Association mode
    hdmi_group=1
    
    # Enable audio over HDMI
    hdmi_drive=2
    
    # Set the output resolution and frame rate to your desired option
    
    # 1920x1080 60fps
    hdmi_mode=16 
    
    # 1920x1080 25fps
    hdmi_mode=33
    
    # 1920x1080 30fps
    hdmi_mode=34
    

    To save your changes, press Ctrl+X and then "Y" to confirm, then "Enter". At this point we need to reboot to make the changes take effect, so type:

    sudo reboot
    

    and wait a few seconds for it to reboot.

    Install and Configure Software

    We'll be using nginx with the RTMP module as the RTMP server, and then connect omxplayer to play out the stream over the HDMI port.

    Install the necessary software by typing:

    sudo apt update
    sudo apt install omxplayer nginx libnginx-mod-rtmp
    

    We need to give nginx permission to use the video port, so do that with the following command:

    sudo usermod -aG video www-data
    

    Now we need to set up an RTMP server in nginx. Edit the main nginx config file:

    sudo nano /etc/nginx/nginx.conf
    

    Scroll all the way to the bottom and copy the below text into the config file:

    rtmp {
      server {
        listen 1935;
    
        application live {
          # Enable livestreaming
          live on;
    
          # Disable recording
          record off;
    
          # Allow only this machine to play back the stream
          allow play 127.0.0.1;
          deny play all;
    
          # Start omxplayer and play the stream out over HDMI
          exec omxplayer -o hdmi rtmp://127.0.0.1:1935/live/$name;
        }
      }
    }
    

    The magic sauce here is the exec line that starts omxplayer. omxplayer is an application that can play an RTMP stream out over the Raspberry Pi's HDMI port. The exec line will run this command whenever a new RTMP stream is received. The stream key will be set to the $name variable. Note that this means any stream key will work, there is no access control the way we have it configured here. You can read up on the RTMP module if you'd like to learn how to lock down access to only specific stream keys or if you want to enable recording the stream.

    Save this file by pressing ctrl+X, then Y, then enter.

    To test the config file for errors, type:

    sudo nginx -t
    

    If that worked, you can reload nginx to make your changes take effect:

    sudo nginx -s reload
    

    At this point the Raspberry Pi is ready! You can now stream to this box and it will output the received stream over HDMI! Any stream key will work, and you can stream using any sort of device or software like OBS. You'll need to find the IP address of the Raspberry Pi which you can do by typing

    hostname -I
    

    To stream to the Raspberry Pi, use the RTMP URL: rtmp://YOUR_IP_ADDRESS/live and anything as the stream key.

    Setting up the ATEM Mini

    We'll now walk through setting up an ATEM Mini Pro to stream to the Raspberry Pi.

    If you're familiar with customizing your ATEM Software's Streaming.xml file, you can add a new entry with the Raspberry Pi's IP address. But there is another way which I like better, which is to create a custom streaming file that you can send to a remote guest and they can add it in their Software Control app without needing to edit any XML.

    Create a new XML file with the following contents. This is the contents of one of the <service> blocks from the Streaming.xml file, wrapped with a <streaming> element.

    <streaming>
        <service>
            <name>Raspberry Pi</name>
            <servers>
                <server>
                    <name>Primary</name>
                    <url>rtmp://RASPBERRY_PI_IP/live</url>
                </server>
            </servers>
            <profiles>
                <profile>
                    <name>Streaming High</name>
                    <config resolution="1080p" fps="60">
                        <bitrate>9000000</bitrate>
                        <audio-bitrate>128000</audio-bitrate>
                        <keyframe-interval>2</keyframe-interval>
                    </config>
                    <config resolution="1080p" fps="30">
                        <bitrate>6000000</bitrate>
                        <audio-bitrate>128000</audio-bitrate>
                        <keyframe-interval>2</keyframe-interval>
                    </config>
                </profile>
                <profile>
                    <name>Streaming Low</name>
                    <config resolution="1080p" fps="60">
                        <bitrate>4500000</bitrate>
                        <audio-bitrate>128000</audio-bitrate>
                        <keyframe-interval>2</keyframe-interval>
                    </config>
                    <config resolution="1080p" fps="30">
                        <bitrate>3000000</bitrate>
                        <audio-bitrate>128000</audio-bitrate>
                        <keyframe-interval>2</keyframe-interval>
                    </config>
                </profile>
            </profiles>
        </service>      
    </streaming>
    

    Replace the IP address with your own, and you can customize the <name> as well which will show up in the ATEM Software Control. Save this file with an .xml extension.

    In the ATEM Software Control app, click "Stream" from the menu bar, choose "Load Streaming Settings", and select the XML file you created.

    load streaming settings

    This will create a new option in the "Live Stream" section where you can stream to the Raspberry Pi instead of YouTube!

    streaming options

    Go ahead and enter a streaming key now, it doesn't matter what you enter since there is no access control on the Raspberry Pi. Click "On Air" and in a few seconds you should see the image pop up on the Raspberry Pi!

    Mon, Sep 7, 2020 2:00pm -07:00 #raspberrypi #streaming #video #livestream #rtmp #atem #atem-mini
    2 likes 1 bookmark 4 mentions
    • Malcolm Blaney
    • Marty McGuire
    • fluffy

    Other Mentions

    • Aaron Parecki aaronparecki.com
      🔴 Two years of LIVE Q&A!! NAB recap, which ATEM Constellation did I buy?
      Sun, May 1, 2022 12:43pm -07:00
    • Aldo twitter.com/aldogoliath
      aaronparecki.com/2020/09/07/7/r…
      Sun, Oct 10, 2021 9:40pm +00:00 (via brid.gy)
    • じてんしゃっぷ twitter.com/jitenshap
      同じことしてる人おった omxplayerってのがあるのね。よさげ。 aaronparecki.com/2020/09/07/7/r…
      Thu, Oct 8, 2020 1:19pm +00:00 (via brid-gy.appspot.com)
    • Aaron Parecki aaronparecki.com
      How to make a DIY Streaming Bridge with a Raspberry Pi for the ATEM Mini and OBS
      Tue, Sep 8, 2020 6:00am -07:00
Posted in /articles using quill.p3k.io

Hi, I'm Aaron Parecki, Director of Identity Standards at Okta, and co-founder of IndieWebCamp. I maintain oauth.net, write and consult about OAuth, and participate in the OAuth Working Group at the IETF. I also help people learn about video production and livestreaming. (detailed bio)

I've been tracking my location since 2008 and I wrote 100 songs in 100 days. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel. Read more.

  • Director of Identity Standards at Okta
  • IndieWebCamp Founder
  • OAuth WG Editor
  • OpenID Board Member

  • 🎥 YouTube Tutorials and Reviews
  • 🏠 We're building a triplex!
  • ⭐️ Life Stack
  • ⚙️ Home Automation
  • All
  • Articles
  • Bookmarks
  • Notes
  • Photos
  • Replies
  • Reviews
  • Trips
  • Videos
  • Contact
© 1999-2025 by Aaron Parecki. Powered by p3k. This site supports Webmention.
Except where otherwise noted, text content on this site is licensed under a Creative Commons Attribution 3.0 License.
IndieWebCamp Microformats Webmention W3C HTML5 Creative Commons
WeChat ID
aaronpk_tv