YouTube Live Stream from CCTV IP Camera

IP Camera RTSP Stream to Youtube Live 

IP Camera Stream on Youtube Live

Do you wish you to embed your IP camera's video stream on website? There are many paid video stream service which can convert and store your video stream, however, you may want to use the free service such as Youtube Live. After I searched for a while on Internet, I found the method to stream the camera feed on Youtube Live from my Windows 10 computer.

1# Install the ffmpeg software on PC

Youtube Live supports RTMP video stream protocol, the first step we need to convert the RTSP to RTMP on our computer. Here we use the open-source and free ffmpeg software, it can turn your computer to a media stream server, hence converts your RTSP video stream to RTMP, it's a cross platform solution can be run on Windows, Linux, Mac OS.
Step 1: Download the ffmpeg software: http://ffmpeg.zeranoe.com/builds/
Step 2: Unzip the compressed file, and move the folders to your PC's drive.
ffmpeg files
Unzip the files to your PC
Step 3: Open "bin" folder, create a txt document in this folder.
Create a txt document in BIN folder
Create a txt file in BIN folder
Step 4: Open the created txt file, input "CMD" in the content, save it and rename it to Command.bat
Edit the txt file
Edit the txt file
Rename it to Command.bat
Rename it to Command.bat
Step 5: After rename the file, double click the file to run, now you will see Windows Command Window.
Windows Command
Windows Command

2# Find IP Camera's RTSP URL

After we successfully installed the ffmpeg software on the PC, and now we can enter the commands to use the software. Then, we need to find the rtsp url of the IP camera. Different brand of IP cameras have different rtsp url. Here we take the Yoosee Wi-Fi cameras as an example. The RTSP URL of Yoosee Camera is as below:
rtsp://IPaddress:554/onvif1
rtsp://IPaddress:554/onvif2
Before using the above RTSP URL, you need to change the IP address to your camera's IP address e.g. 192.168.1.3; Yoosee Wi-Fi cameras offer two separate RTSP streams for its main stream and sub-stream. Onvif1 is the main stream which delivers 1280x720p HD video, while the onvif2 is the sub-stream delivers 640x320 resolution video. Depends on your network environment, if your Internet speed is moderate not fast, you may use the sub-stream, instead of using the main stream.
Please running the VLC media player to verify if you can play the camera's RTSP video stream on your computer.

3# Create Live Streaming on Youtube

Go to youtube channel, click [Get started] on the right column of upload page to create the live streaming on Youtube. Giving it a title and description, then choose encoder, now it will show a encoder setup, you can find the server url rtmp://a.rtmp.youtube.com/live2  and stream name/key information. We will use these two information for the video streaming.
Windows Command
Windows Command

4# Convert RTSP stream to RTMP by ffmpeg

We know the camera's rtsp URL and Youtube Live Stream server url and the stream name/key. All things are ready, now we need to run the ffmpeg to convert the RTSP stream to RTMP, then automatically upload it to Youtube Live server by command as below:
ffmpeg -f lavfi -i anullsrc -rtsp_transport udp -i rtsp://192.168.1.3:554/onvif1 -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/stream name
Please note before running the above command, you need to change the rtsp URL and RTMP server url to yours. In this example, we use the UDP connection, rather than TCP, because we failed to use the tcp port in our test, if you encounter error, you may try the TCP port by simply replace the udp with tcp.
FFMPEG Command
FFMPEG Command
After running the above command, the ffmpeg software will detect the rtsp codec information, then start to upload video stream to Youtube RTMP server.
FFMPEG Command
FFMPEG Command
Followed the above tutorial, we managed to do Youtube Live streaming by using the Yoosee Wi-Fi cameras. However, when we initially run the ffmpeg command, we encountered error, after thought for a while, we reckoned that the software could not connect the Youtube server because Youtube was blocked in China. After we used the VPN connection, we successfully achieved the Youtube Live streaming, As the VPN connection is too slow, thus the image quality of the live stream is extremely poor.