YouTube live-streaming made easy

Looking to share your day, event, or the observations of your nature box live on the internet via a Raspberry Pi? Then look no further, for Alex Ellis has all you need to get started with YouTube live-streaming from your Pi.

YouTube live-streaming Docker Raspberry Pi

The YouTube live dashboard. Image c/o Alex Ellis

If you spend any time on social media, be it Facebook, Instagram, YouTube, or Twitter, chances are you’ve been notified of someone ‘going live’.

Live-streaming video on social platforms has become almost ubiquitous, whether it’s content by brands, celebrities, or your cousin or nan – everyone is doing it.

Even us!

YouTube live-streaming with Alex Ellis and Docker

In his tutorial, Alex demonstrates an easy, straightforward approach to live-streaming via a Raspberry Pi with the help of a Docker image of FFmpeg he has built. He says that with the image, instead of “having to go through lots of manual steps, we can type in a handful of commands and get started immediately.”

Why is the Docker image so helpful?

As Alex explains on his blog, if you want to manually configure your Raspberry Pi Zero for YouTube live-streaming, you need to dedicate more than a few hours of your day.

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.

Get anything wrong (like Alex did the first time) and you have to face another nine hours of compilation time before you’re ready to start streaming – not ideal if your project is time-sensitive.

Using the Docker image

In his tutorial, Alex uses a Raspberry Pi Zero and advises that the project will work with either Raspbian Jessie Lite or PIXEL. Once you’ve installed Docker, you can pull the FFmpeg image he has created directly to your Pi from the Docker Hub. (We advise that while doing so, you should feel grateful to Alex for making the image available and saving you so much time.)

It goes without saying that you’ll need a YouTube account in order to live-stream to YouTube; go to the YouTube live streaming dashboard to obtain a streaming key.

For a comprehensive breakdown of how to stream to YouTube via a Raspberry Pi, head to Alex’s blog. You’ll also find plenty of other Raspberry Pi projects there to try out.

Why live-stream from a Raspberry Pi?

We see more and more of our community members build Raspberry Pi projects that involve video capture. The minute dimensions of the Raspberry Pi Zero and Zero W make them ideal for fitting into robots, nature boxes, dash cams, and more. What better way to get people excited about your video than to share it with them live?

If you have used a Raspberry Pi to capture or stream footage, make sure to link to your project in the comments below. And if you give Alex’s Docker image a go, do let us know how you get on.

19 comments

Avatar

I’ve done the ffmpeg a few times, and yes it takes forever! More like 23 hours on an early Pi.

I used it to stream my last balloon launch and landing over a 3G connection. The “landing” was more a “treeing” so it had a good view until I managed to get the thing cut down :-)

Avatar

this is very cool for streaming mp3s and audio with animated gifs playing in the background https://github.com/torch2424/piStreamRadio pre-compiled for the Pi

Avatar

Can’t help but think about starting a “nature” or “hummingbird” channel on YouTube. Either restarting a stream every hour for continuous streaming or use a motion sensor to start streaming when movement is detected.

Avatar

Our local library internet has youtube blocked, so before doing this at a venue it is a good idea to find out what is / isn’t blocked so you know what you can stream for example.

Avatar

Good to see people starting to use Docker on Raspberry Pis to.

Avatar

Have you guys never tried to cross-compile your code? I do this for building custom kernels for my Pi’s on a x86_64 machine and it takes only a few minutes. I’m sure one could do the same for ffmpeg.

Avatar

It is possible to cross-compile ffmpeg for the Raspberry Pi on a more powerful Desktop PC which will be finished in under ten minutes on a modern x86_64 CPU. There are instructions on how to accomplish this on the ffmpeg website (https://trac.ffmpeg.org/wiki/CompilationGuide/RaspberryPi), so there is / was no need for a long compile session on the Pi itself.

Avatar

You’re assuming that people are comfortable with cross-compiling and also that they own a Linux desktop. Using this method you get the hit once — on the device, but it’s much easier than alternatives.

Avatar

After the reboot in step 1 I cannot ssh into my Zero anymore, VNC connection is also refused….

Avatar

We’ve been using our Raspberry Pi 3 to transport IP cameras for YouTube live streaming. Our wireless network isn’t very robust and errors drop the connection from time to time, so we made the script restart itself after it errors out. In testing we discovered that we could support 10 VGA cameras and maybe 5 HD cameras streaming off one Pi3. The limit seems to be with the available RAM. The RTSP Transport with FFMPEG works really well. Though the hardest part is figuring out the path on your network camera where the h264 stream occurs. iSpy Connect has a great online resource to help you find out if your camera is supported though. :)

SCRIPT WE USED:
———-
#!/bin/bash

while true

do

ffmpeg -v verbose -stimeout 1200000000 -rtsp_transport tcp -i rtsp://username:password@##.##.##.##/h264path:portnum -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -vcodec copy -preset ultrafast -r 15 -g 30 -crf 20 -maxrate 550k -minrate 400k -bufsize 500k -acodec aac -ab 128k -f flv -muxdelay 0.1 “rtmp://a.rtmp.youtube.com/live2/your-youtube-key-here”

done
———-

We’re not professionals, so if anyone knows how to clean this script up that would probably help the entire Raspberry Pi community for RTSP to RTMP transport :)

Avatar

why not simply provide the ffmpeg deb package instead of a docker container? seems like using docker for fanboism/buzzword-love

Avatar

Don’t think so; for classic distribution you’ll need to set up a repo that users need to add, and thrn maintain thr whole shebang. With container, you can use a more flexible packaging infrastructure that shields your container from the host to some extent. Putting it the hypr aside, there are quite some real benefits, I can tell first hand from a recent project.

Avatar

The raspbian team already have their own repos added to the raspbian image.

I have often wondered why such a wildly known tool isn’t available directly from the Debian repos. I have hear people recommend http://www.deb-multimedia.org/ for a repo where it is included.

Avatar

Ffmpeg used to be in repository. Somehow, it’s not there anymore. Why not? It’s a very useful program to have, especially for multimedia projects. Any thoughts on including it back to the repository?

Avatar

Why not using Gstreamer with omx? I use it for Facebook live stream on a zero and works perfect and gstreamer is installable via apt :)

Avatar

I’ve updated the post with more Q&A and a link to a Gist for additional Docker information.. should help with some of the comments above.

Avatar

It’s not something I’m likely to use, at least not as far as I can see, however a huge “thank you” to Alex for his hard work and 18 hours (?) Of compilation time on ffmpeg.

Anyone doing this and then providing it to others should always be thanked, in my opinion,to which you are all entitled! :-)

Thanks very much Alex.

Cheers,
Norm.

Avatar

thanks for the post. I have a raspberry but i never think on this.

I use now for download youtube videos to my hard drive, but no to live streaming.

Avatar

I live streamed a Robin nest to YouTube this year using ffmpeg. The source was a motion jpeg stream from a separate RasPi:

ffmpeg -f mjpeg -i ‘http://XXX.XXX.X.XX:8080/?action=stream’ -an -vcodec h264 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 128k -g 50 -vf ‘scale=720:-1, vflip,hflip’ -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/XXXX-XXXX-XXXX-XXXX

I didn’t bother compiling ffmpeg having done it a while ago and finding it took ages (since wiped that card), but got a pre-compiled version from here: https://www.johnvansickle.com/ffmpeg/

Brief detail at the end of this post:
http://nestboxtech.blogspot.co.uk/2017/04/unexpected-robin-nest.html

Leave a Comment

Comments are closed