Streaming RTSP to YouTube Live
I have wanted to stream the camera feeds from the cameras overlooking Picton and Waikawa since I installed them. At the time there was no easy way to do this without paying for a streaming service that would convert and host the stream for you. Now we have YouTube Live. A free host for RTMP streams. There are a few challenges that I had to overcome related to my system. For example:
The cameras provide RTSP streams
Reduce bandwidth usage because of data cap
I will quickly start with the easy ones.
Reducing Bandwidth
I reduce the bandwidth and data usage over the course of a day in three different ways:
Reduced resolution from 1080p to 720p
Reduce 30FPS to 6FPS
Run cameras from 7AM to 7PM
The resolution and FPS I configured on the camera to reduce traffic within my network.
Converting RTSP to RTMP with FFMPEG
To create compatible stream formats we capture the RTSP stream and convert it into RTMP with the help of a (in my case Windows) server running ffmpeg. The following example is the command I use for my cameras. You might have to check how to capture your RTSP stream.
ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -i rtsp://<username>:<password>@<ip address>/h264/ch1/main/av_stream -tune zerolatency -vcodec libx264 -t 12:00:00 -pix_fmt + -c:v copy -c:a aac -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<YouTubeStreamKey>
A few notes:
In this example it's missing a valid camera username, password, IP address and Youtube stream key. I will explain how to get your Youtube stream key further on.
In this example you will find the extra argument "-t 12:00:00" This tells it to run for a duration of 12 hours. Remove if you want to stream continuously.
Setting up YouTube Live
Follow the instructions here. After you're done, set up a live stream, giving it a title and a description and near the bottom of the page under "ENCODER SETUP", copy the "Stream name/key" and paste it in the ffmpeg command.
Optional - Schedule Automatic Start Time
As stated before I only stream between certain hours. As you have seen earlier in the blog post I give a duration that the stream is going to be online for. But we also need a way to start it. Because I run it on a Windows server I create a .bat file and use "Task Scheduler" to run it.
The bat file only contains the following three lines:
ECHO OFF
cd C:\Users\XXXXX\Documents\ffmpeg\bin
ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -i rtsp://<username>:<password>@<ip address>/h264/ch1/main/av_stream -tune zerolatency -vcodec libx264 -t 12:00:00 -pix_fmt + -c:v copy -c:a aac -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<YouTubeStreamKey>
Actually I have a "PAUSE" commented out in case you want to debug.
To create an automated task use windows search to find "Task Scheduler".
Click tab "Action" -> "Create a Basic Task".
Give it a name and description. -> :"Next"
Trigger "Daily" -> Next
Set Start date and Time -> "Next"
Select "Start a program" -> "Next"
Browse and select your .bat file -> "Next"
Click "Finish"
Double click your newly created task..
Under tap "General" enable "Run Whether user is logged on or not"
Summary
This is missing some information but since everybody their equipment is most likely slightly different and so will be there requirements I decided to give enough info to get you started. You might have to do some research on which changes to make to make it work for you. Off course you want to see some examples. Here you go. Remember the streams are only online between 7AM and 7PM (UTC +12).
FFPLAY IP CAMERA - Aug 11, 2016 2:33:4 AM