How to setup a YouTube live video stream using FFMPEG

How to setup a YouTube live video stream using FFMPEG

My wife Jen recently noticed that we had a bird’s nest in our DirecTV satellite dish. The Momma bird recently laid some eggs in it and we’ve been curious about them so I thought it would be fun to set up a webcam so we can keep tabs on what’s going on up there without disturbing the nest.

I used to run a live webcam when I was a kid

As you can see above we have a 24/7 webcam running (as of March 24th 2015) streaming what is going on in the bird’s nest. Back in the day I use to run a webcam and every 30 seconds or so it would take a picture of me sitting at my desk. It wasn’t the most popular thing for obvious reasons but it was a cool concept to have the webcam take a picture, FTP it to my server, rename the existing current.jpg to the date and then name the new file to current.jpg. From there I could refer to current.jpg in my html and you could see the recent image. With some scripting you could show the archives and such. It was super basic but fun none the less. As with most things I do it starts out as something fun and then I end up referencing it for a client. Fast forward a few years, we have bandwidth to spare, webcams all over the place and the know how to push and pull video as needed.

How to stream to YouTube

My YouTube account allows me to set up a live event, my account is verified, in good standing and I enabled the live events feature in my Account Features page. I think now days most accounts have this ability with the advent of Let’s Plays and watching people play games on YouTube. If you load up the video manager and go to Live Events you can set up a new live event. You could also use a Google Hangout on Air to do the streaming too. Once you setup your live event you can stream to it. There are a few ways to do this: WireCast for YouTube, Flash Media Live Encode and Google Hangout on Air or use any service that supports pushing video using RTMP.

How I setup my birds nest camera setup

A few years back I got a Logitech Alert b700i IP Camera for review, I live in an apartment and I don’t want to be that weirdo that has cameras pointing outside his apartment recording the common areas. I’ve used this camera for a number of events at my work and thought the hatching of some bird eggs would be a good use for it at home this go around.

I positioned the IP Camera using the pole that was provided and a metal clip to clip it to the side of the DirecTV satellite dish the bird laid its nest in. I then ran a cat 6 cable from that camera over to the nearest network drop and plugged it in. This camera uses PoE or Power over Ethernet to power it so I have a power injector between the camera and the network drop to give it some power. After that I did some searching on my network looking for a device with port 554 open the port that RTSP runs on.

Acronym Soup

“I thought you said you were using RTMP?” Ah, good eye. RTSP (Real Time Streaming Protocol – wikipedia) is the standard that most IP cameras use, RTMP (Real Time Messaging Protocol – wikipedia)  is the standard that YouTube uses for getting a video stream from us over to YouTube. Since my camera lets me stream using RTSP and YouTube supports RTMP I figured I could make something happen by transcoding and bridging the gap between my camera and YouTube.

Let’s get digging

The first thing I do when trying to solve a crazy problem like this is to see if anyone else has done this in the past. I googled “RTMP RTSP YouTube” and noticed in the search results people talking about FFMPEG so I added that in too “RTMP RTSP YouTube FFMPEG” which showed me there is hope. Ditching Google and did a search on GitHub hoping someone had a sample bash script to make this all work and sure enough they did.

What this code does is lets you specify your IP Camera source webcam url to pull from and the YouTube URL, YouTube Camera Key to push to. If you go to your Live Event and then edit the event and click on Ingestion you’ll see a screen like this:



The area in the code where you are setting the value for the “key” is where you’ll paste in the value from the “Stream Name” above. The Primary Server URL is the value you’ll use for “YOUTUBE_URL” in the bash script. For “SOURCE” in the script I set mine to:


But this depends on the rtsp url your webcam uses and the IP address your camera has. If you do a few google searched for the camera model number and rtsp you are bound to find something.

Starting the stream

I kicked off the stream in the terminal by issuing the command “./” and ffmpeg connected to the IP camera and started pushing the video over to YouTube. If you go to your event page and edit the event and click on Live Control Room you can click on the Start Preview button to make sure your video is streaming to YouTube. If it is you can follow the step to preview the stream and then go live.

What are you thinking about streaming? Leave your comments below.