Live Stream Your Pets with Linux and YouTube!

Gather Your Info


In order to live stream, you'll need a few bits of information. As I mentioned above, you'll need to verify your account to turn on streaming. Then you'll need to get your streaming key (Figure 2). It's important that you not share the streaming key, because it acts like your authentication. If others get your key, they can stream to your channel, even without your user name.

Figure 2. That's not my real streaming key, just FYI.

The other bit of information you'll need from YouTube is your channel ID. It's not easy to find the channel ID, but if you want to embed your video, you'll need it later. Head to this page, and find the line that looks like, "YouTube Channel ID: UCbUTB3bVg3cmeyJUtUC9DPA" (your channel ID will be different from mine). The long string of text is your channel ID, copy that somewhere easy to find.

Video Camera Feeds:

I can really give you only hints about what to look for here. You need to find the streaming video feed coming from your camera. Make sure you don't use the web page that has the stream embedded (most cameras have a rudimentary web server that embeds the stream). You need the raw feed itself. Google or the user's manual will be your best bet for figuring out the raw stream URL.

I have an Onvif-compatible video camera that has an MJPEG stream URL that looks like this:

One of my Foscam cameras requires a user name and password in the URL in order to get the stream. It looks like this:

And my new UniFi cameras actually use an RTSP URL that comes from the UniFi server instead of from the cameras directly. It looks like this: rtsp://

The point I'm trying to make is that finding your video camera's streaming URL often is challenging. If you do it before you start, it can save hours of frustration. An easy way to test if you've found the correct URL is to try opening it in VLC. I haven't found a video camera that VLC can't view, so if it complains about an invalid video source, you probably don't have the correct URL. Google, along with your camera's model number, is probably the best way to figure it out.

The Software

There are many scripts online claiming to stream from a camera source to YouTube using FFmpeg. I'm sure they work for someone, but I've never gotten them to work, no matter how many settings I tweak. In fact, I gave up for quite a while because I didn't want to rely on a GUI interface to stream. I wanted my server to do the dirty work and do it without my interaction. One day recently, however, I discovered that Open Broadcaster Software (OBS) supports command-line flags for starting streaming. That means I could have the server start streaming without the need to "click" anything.

One problem I had to overcome was the lack of the X Window System on my BirdCam server. There's no monitor connected to the server, but in order for OBS to work, it has to have a logged-in GUI desktop. I hooked up a monitor long enough to get a GUI installed and then set the system to log in automatically. I also disabled all power-saving features for the monitor, because I wouldn't have one logged in anyway. Once it was set up, I installed TeamViewer so I could control the system remotely if I needed to. There have been some issues with TeamViewer's security recently, so it might not be the software you choose for controlling the server, but it's what I have installed, and it works. Figure 3 shows my "server" controlled remotely via TeamViewer.

Figure 3. I don't normally have the security camera to my cat's litter cave on my live stream, but I wanted to show multiple cameras.

Installing OBS is simple. Head over to the OBS site and download the latest version, or simply install their PPA if you're using Ubuntu. The software has matured since I last mentioned it, and I didn't have any problems with dependencies, even when connecting over a remote session.

OBS also has the great feature of saving your last-used session. That means once you set up your cameras, you don't have to worry about readjusting them on the next launch. OBS just uses the same settings you had before. If you look back at Figure 3, you'll see there are multiple cameras added to the preview window. Without the need to save a layout, OBS just remembers from launch to launch how you had the cameras positioned.

In order to get the best results, you need to tweak a few OBS settings. Click the settings button, and then head over to the Video tab (Figure 4). This is a little confusing, but you have two different resolutions to set. The "canvas" is how big you want OBS to show on your preview window. The "output" resolution is what it scales your video to for streaming and recording. I just set them both to 720p, because I figure scaling takes CPU. You also set the frames per second (FPS) for the output video. I use 10FPS with the 720p size. You can adjust this if you want 1080p, or down if you don't have bandwidth.

Figure 4. The resolutions are flexible, but I like to keep it simple.


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