1 August 2020

Unraid Capture, Encoding, and Streaming Server

Guide for creating a lightweight container for a Twitch streaming and capture server with Unraid.

[Editor's Note: In this guide, your Unraid server will be set up to encode and transmit your streaming game to a single service: Open Broadcaster Software. For setting up a multi-streaming server with client side encoding where the gaming machine encodes and then Unraid sends the stream to multiple web servers, please see this blog.]

This Guest Blog is by Stefano Partida of SPX Labs

This guide is for creating a lightweight container for a Twitch streaming and capture Unraid server. You could use a VM for this, but, I wanted to be mindful of system resources and this was also a personal challenge that I wanted to undertake using Unraid. Lastly, special thanks to Reddit user u/Darqfallen for helping unlock the last secrets of getting this to work. Hint: It’s always DNS! Blame DNS!

Software Versions

Unraid: 6.8.3

Community Apps: 2020.05.16

Basic Diagram

Here is what the basic setup looks like. You will need to add the NDI Plugin to OBS Project on your target system. In my use case, I want to capture my Gaming Computer's game play. Once you enable NDI on your gaming computer, it will automatically broadcast anything you are capturing to your local network. The docker-obs-ndi container you will be setting up will then capture that NDI output, encode it, and send it off to Twitch.

Corrected

Installation

In Community Apps (CA) search for “bandi13 docker-obs”. You will need to “Click Here to Get More Results from DockerHub”:

Screen Shot2020 05 22at3 55 08 PM
  1. Download and install the Docker Obs container by bandi13
  2. In the Docker tab edit “docker-obs”
    1. Set the Network type to custom: br0
    2. Assign it a useful IP
    3. Click the Advanced View button in the top right corner
    4. In the WebUI: section add http://[IP]:[PORT:5901]
    5. Add the port 5901 and connection type of tcp
    6. Click Done
Screen Shot2020 05 23at1 49 41 PM

Configuring OBS Studio Container

  1. The app should start right up. Now connect to it with VNC
  2. The password is: 123456
  3. You should now be looking at the Ubuntu Desktop
  4. Right Click and in the pop up window navigate to DockerCustom > Xterm
Screen Shot2020 05 22at10 59 17 AM

When Xterm opens, type the following commands:

      apt update

and then:

     apt upgrade -y

Now, go grab a beer and patiently wait for it to finish updating...

Next, type in the following commands and hit enter one after another:

     apt-get install -y wget 

     apt-get install -y avahi-daemon 

     /etc/init.d/dbus start 

     /etc/init.d/avahi-daemon start

Note: the following is subject to change due to updates by the NDI developers.

Next, enter the following commands:

     wget https://github.com/Palakis/obs-ndi/releases/download/4.9.1/libndi4_4.5.1-1_amd64.deb

     wget https://github.com/Palakis/obs-ndi/releases/download/4.9.1/obs-ndi_4.9.1-1_amd64.deb

     dpkg -i libndi4_4.5.1-1_amd64.deb

     dpkg -i obs-ndi_4.9.1-1_amd64.deb

Now you will want to verify that OBS has NDI available.

Warning: After making all of these changes you must commit them to a new container image or else you will lose all of your work if the container is edited/stopped/started/restarted/rebooted/shutdown/etc.

Screen Shot2020 05 22at8 35 00 AM

Committing Changes to a New Container

Now, we have to commit our changes to a new container because our changes will not be retained if the container is restarted. If you wish to add additional software or packages, I recommend doing so before this point. Basically, this is if you want to install anything you think you may need for troubleshooting or graphics.

We will be using the Web Terminal provided within the Unraid WebUI. >_

In the Terminal, enter:

     docker ps -a

Either Copy or write down the CONTAINER ID for bandi13/docker-obs, as we will need this for step 2.

Next, enter:

      docker commit <CONTAINER ID> docker-obs-ndi

Example command: docker commit 7c8dca4783a4 docker-obs-ndi

Finally, enter:

     docker images

Verify our new container named docker-obs-ndi was created with the command, docker images:

Commit Docker

Adding the Container to the Docker Tab

Unfortunately, there will not be a template or an available repository available right away so we will be adding the container and filling in all of the requirements for our newly created container. After following all the steps below, you will then have a template for your new container that you can use in the future.

  • Click Add Container
  • Skip past Template
Screen Shot2020 05 22at8 43 24 AM
  • Enter docker-obs-ndi into the Name field (you can give it a custom name if you wish)
  • Enter docker-obs-ndi into the Repository field
  • Network Type: Custom : br0
  • Fixed IP Address (optional): whatever IP you want
  • Click the “Add another Path, Port, Variable, Label or Device” link
    • Add Port
    • Name: VNC Port
    • Host Port: 5901
    • Container Port: 5901
  1. Click the Advanced View icon
    • WebUI: http://[IP]:[PORT:5901]
  2. Apply! Now you will see docker-obs-ndi listed under Applications in the Docker Containers pane.
Screen Shot2020 05 23at2 09 35 PM
  • The container should start automatically but you will be unable to connect with VNC
  • Left Click on the docker-obs-ndi in the pop up window select Console
Console Access
  • A new Web Terminal will pop up. Type the following command:

          rm -Rf /tmp/.X*

  • Close the Web Terminal
  • Restart docker-obs-ndi
  • You should now be able to access the container through VNC (the password is still 123456).
  • Congratulations, you are now dead.

I kid....

Command Line

Performance Testing

My Unraid server has a ton of spare resources, see here for more details. [Editor's Note: Nice humblebrag]

For the parts list, they are:

Server Specs (PNAS)

Gaming Computer Specs (Truncator)

Unraid Statistics During a Stream

Here is a short 60 second gif of Unraid stats during the stream. If you want to see a longer version here is a YouTube link.

Quality of the Stream

Here is what the stream looked like, I was averaging about 52 FPS using CPU(x264) encoding only.

OBS Settings

Below are the settings that I set inside of the Docker-OBS-NDI container. These are not optimized settings just settings I used for testing purposes. You should optimize your settings in accordance with your hardware.

Advanced User Course

So, you want to tinker around more? Maybe you want to record locally instead of streaming to Twitch or your favorite service? Maybe you want a custom designed docker container logo? Well look no further, instructions are below!

Can I Record Locally?

Yes of course, the set up is pretty basic and looks something like this. Feel free to adjust directories as needed.

  • In your OBS Container, change the Recording Path to /video
  • In Unraid make sure to add a Path for the container and host. My Container Path is /video and Host Path is /mnt/user/appdata/docker-obs-ndi/video. It can be any path you want this is just what I did for ease.
Screen Shot2020 05 22at10 48 03 AM

Can I Upload a Custom Logo?

You bet! While editing your container, with advanced view enabled. You can add a URL path to any icon you like or a directory path to one on your flash drive. I downloaded the OBS Icon from Wikipedia and placed it in /boot/config/plugins/dockerMan/images/obsLogo.png.

Alternatively I could have just plugged in this URL for the Icon:

https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/OBS_Studio_Logo.svg/1200px-OBS_Studio_Logo.svg.png

Bugs

The only bug I experienced from time to time, is failing to connect with VNC to the container. In the section “Adding the Container to the Docker Tab” steps 11 and 12 will fix the connection issue. I will update this if I ever find a permanent fix.

  • Use the Docker Terminal “Console” and type the command: rm -Rf /tmp/.X*
  • Then restart the container and you should be able to enter the password and connect

During the first install of bandi13/docker-obs do not include —shm-size=256mb -it in the Extra Parameters section during the initial install. The container will fail to execute.

  • According the creator; ”The shm-size argument is to make sure that the webclient does not run out of shared memory and crash.”
  • You may want to consider adding this later if your container crashes.

Troubleshooting

Iptables, firewall, and selinux are not configured in this container and thus any issues you may have are probably DNS related.

You can try some of the following things if you continue to experience issues with NDI Sources not appearing in your container.

Usually restarting both of these services fixes the issue immediately

  • /etc/init.d/dbus restart
  • /etc/init.d/avahi-daemon restart

If that doesn’t work consider doing the following.

  • yum install -y iputils-ping (just for troubleshooting basics)
  • yum install -y vim (to edit the configuration files inside the container)
  • Add your local DNS server to the /etc/resolv.conf
    • nameserver 192.168.1.7
  • Build out the /etc/hosts table, add a hostname and associated IP address of your gaming computer or other devices
    • truncator 192.168.1.69

Failing to Connect to the Container with VNC

  • You may need to delete the .X11 files if you fail to connect to the container after a restart or configuration change, see section “Adding the Container to the Docker Tab” the second set of steps 11 and 12. (rm -Rf /tmp/.X*)

Verify OBS and NDI Plugin are on compatible versions

This will require you to look at NDI’s website and do some reading. Sorry. General information can be found here.

Third Party Applications

Here is a List of 3rd party applications this setup does not work with. I may add more based off comments or other findings in the future.

  • NDI HX Camera - most likely a NDI compatibility issue.
  • SLOBS - To my knowledge SLOBS only receives NDI Output, as in, you can only add an incoming source not broadcast. Also, as far as I know SLOBS is not linux compatible. Such a shame. Please note I have not tested the following and it is mere speculation on my part.
    • You could get “crazy” with your set up and do OBS -> docker-obs-ndi -> nginx-rtmp-docker -> SLOBS VM -> Twitch/YouTube/Mixer/etc
    • Or maybe even OBS -> docker-obs-ndi -> SLOBS VM -> Twitch/Youtube/Mixer/etc

Would you like to know more?

Here is a video of me playing around with the setup but from a gaming laptop to the server.

Do you have questions on setting up an Unraid Capture, Encoding, and Streaming Server?

Are you a twitch streamer who uses Unraid?