In this guide we'll set up our Raspberry Pi so that we can stream live video to YouTube to either a public, unlisted or private stream.
Using a pre-built Docker image means we know exactly what we're getting and instead of having to go through lots of manual steps we can type in a handful of commands and get started immediately.
The YouTube live dashboard show my Raspberry Pi cluster and Pimoroni LED blinkt! boards.
Acknowledgements: thanks to Richard Gee for giving me the idea to live stream with a Raspberry Pi.
The old way of doing things
Normally this would have involved typing in many manual CLI commands and waiting up to 9 hours for some video encoding software (
ffmpeg) to compile itself. If you got anything wrong you'd have to add on another 9 hours of compilation time (on a PiZero). In fact while compiling this tutorial I left my Pi running over night and it ran out of disk space meaning I had to start all over again.
Also enable SSH via
raspi-config and login remotely so you can save yourself some typing.
This guide work with Raspbian Jessie Lite as well as the full Pixel desktop.
Step 1. Install Docker
Installing Docker on the Pi is a one-line script:
$ curl -sSL get.docker.com | sh $ sudo usermod pi -aG docker $ reboot
Step 2. Test the camera
To make sure your camera is plugged in properly fire off a test shot. This will also help us gauge whether the orientation is correct:
$ sudo raspistill -o tester.jpg
You can then use
sftp to copy the file back to your Mac, Linux or Windows machine.
As a Windows user you may want to install Git bash which provides all the common UNIX-like utilities used with a Linux system.
Step 3. Pull the image down
The Docker image I produced took almost 9 hours to build, so you have two options now - either rebuild it yourself (over 9 hours) or pull it down from the Docker Hub. It's a 640MB download which will expand to 1.3GB in disk space:
$ docker pull alexellis2/streaming:17-5-2017
Step 4. Get your secret streaming key
Now head over to your Youtube live streaming dashboard. Make sure you've filled in all the details and click Reveal to see your key:
Now copy and paste your key (i.e.
xxxx-xxxx-xxxx-xxxx( into the Raspberry Pi's terminal like this:
$ docker run --privileged --name cam -ti alexellis2/streaming:17-5-2017 xxxx-xxxx-xxxx-xxxx
You'll now be streaming live to the Internet, so pick wisely whether you want to keep that stream private, unlisted or public.
To cancel the stream just hit
Control + C or shutdown the Pi.
This is me doing some late night testing for the blog.
Share your URL!
You can now share your URL with your audience and check out your statistics in real-time. There may be a delay of a few seconds - this is entirely normal and you can tweak lots of settings on the dashboard.
Step 5. Tweaks
Running in the background
To run in the background just swap out the
-ti flag for
$ docker run --privileged --name cam -d alexellis2/streaming:17-5-2017 xxxx-xxxx-xxxx-xxxx
Run on boot-up
To automatically stream every time you power up, then just add the flag
--restart=always to the
docker run command line.
Add effects to the video
By default the command-line we used won't be transmitting audio, for that we'd have to recompile ffmpeg using the Dockerfile and some additional options.
In our entry.sh script we set an empty audio channel since YouTube requires us to stream some audio, even if it's empty.
Positioning your camera
If you'd like to set your camera up on a window then there are two products I'd recommend which come with mini suction cups.