Live Stream Your Pets with Linux and YouTube!

Anyone who reads Linux Journal knows about my fascination with birdwatching. I've created my own weatherproof video cameras with a Raspberry Pi. I've posted instructions on how to create your own automatically updating camera image page with JavaScript. Heck, I even learned CSS so I could make a mobile-friendly version of BirdCam that filled the screen in landscape mode.

Recently, however, I've finally been able to create an automated system that streams my BirdCam live over YouTube. It starts when the sun comes up and stops when the sun goes down. And thanks to some powerful open-source software, I never have to touch the system!

Some of the tools I describe here have been covered in other articles, but this is the first time I've been able to create a stream that anyone can see utilizing bandwidth Google pays for!

Figure 1. Birds are always camera-shy. If you watch long enough, however, they come and steal peanuts!

My List of Ingredients

First off, I want to be clear about what sort of hardware and software is required in order to accomplish something similar to what I'm doing:

  • A Linux computer: if you plan to use USB cameras, this needs to be a physical computer. If your video source is network-based, this can be a virtual machine on your network. A Raspberry Pi isn't really powerful enough for the video work that has to be done, unless maybe it's low-resolution. I have an old i5 CPU running at 1.6GHz, and it's more than enough.

  • A video source: this can be pretty much any video source you have at hand. If you plan to use a USB webcam, you'll need to be sure you are using a physical Linux computer as noted above. I've used USB, MJPEG over http (see my old BirdCam articles), cheap wireless security cameras that have an RTSP stream, and most recently, I started using UniFi video cameras. In fact, if you are considering purchasing outdoor video cameras for a project like this, I can't recommend UniFi cameras enough. They are PoE, HD and the free software handles recording and provides RTSP streams that have both HD video and top-notch audio.

  • A YouTube account with Live Streaming enabled: you'll need to verify your account, and then enable live streaming here. It's not a difficult process, but without following those steps, you won't be able to use the free service.

  • Open Broadcaster Software: I've tried multiple ways to use a CLI solution to stream directly to YouTube with FFmpeg or mencoder, but I've never been able to make it work consistently. I was hesitant to use OBS, because it's a GUI solution and doesn't have a CLI interface, but I worked around that problem, and I'm actually happy to have the GUI now.

  • A web server to host your embedded channel: you could just share the URL to your YouTube channel, but embedding is much cooler, because you can integrate it into your own site.

  • Enough upstream bandwidth to support 1.5–2mbps while streaming: since YouTube is going to redistribute, the local bandwidth requirements don't change regardless of how many people are watching your stream. For some folks (like me, unfortunately), sacrificing that much bandwidth is difficult and sometimes causes issues. Just know that it takes a small, but not insignificant amount of constant upstream bandwidth to stream live video. That should be obvious, but it's something to consider.

  • A few other utilities like crontab and sunwait: the latter is only if you want to time your streams with sunrise and sunset. And, crontab is needed only if you want to automate the starting and stopping. Those touches really make a difference for me though, so I encourage you to consider it.

______________________

Shawn Powers is a Linux Journal Associate Editor. You might find him on IRC, Twitter, or training IT pros at CBT Nuggets.