So you have your webcam or IP camera all hooked up and ready to begin streaming video. Now you just need to figure out how people can watch it. Ideally, it should be simple and universally available; like an internet browser.
Unfortunately, most IP cameras are RTSP based which is not natively supported in internet browsers. So how do you use an IP camera for live streaming?
One solution is to connect to the RTSP stream and view it in VLC Media Player. However, that requires additional configurations and is not convenient. It would be much easier if you could just view the video in a standard web browser. Plus what if you need to support thousands or millions of viewers?
Fortunately, WebRTC is a protocol widely accepted by internet browsers. All you need to do is convert the RTSP feed coming from your IP camera to WebRTC. This post will explain how that can be done with Red5 Pro.
How Do I Convert RTSP to WebRTC?
The simple answer is to use Red5 Pro. We’ve built that logic into our Restreamer Plugin so all that work is done automatically once it’s configured. We also have failover support for RTMP and HLS for the few clients that don’t support WebRTC.
However, I’m sure that some of you reading this are wondering about the specific process we use to convert RTSP to WebRTC. Read on, my inquisitive friends and we will cover that in more detail.
In order to integrate an IP camera (or general RTSP stream) with WebRTC, you first need to achieve media interoperability (a fancy term for making them work together). The media stream sent out by the camera needs to be made compatible with formats supported by browsers and the WebRTC codecs.
What is RTSP used for?
RTSP is a streaming control protocol that is used to control the streaming server, kind of like how a remote control works with a TV (enabling play, pause, etc.). It does not actually transport the stream, rather it defines how the data in the stream should be packaged for delivery. It also defines how both ends of the connection should behave to prepare a pathway for transportation.
This process is also known as signaling. WebRTC uses a different method to handle signaling typically involving WebSockets.
RTP is used for the actual transportation of the data/video stream. Since RTP is a transport protocol it could be said that it is like a runway and flight path between two airports while RTSP is the air traffic controller that makes sure the runway is open and the flightpath is clear of any obstacles. The actual video codecs (covered in more detail below) used to encode the video data would be the airplane itself.
How Do RTSP and WebRTC Work Together?
As WebRTC also uses RTP for its transport protocol, they are very compatible together. The complication comes from how IP cameras behave.
IP cameras directly produce an RTSP stream, acting more like a server. Normally in the case of webcam or cell phone videos, the Red5 Pro (origin) server takes in the broadcasting stream from those clients. In this way, there is a challenge in connecting a Red5 Pro server, to an IP camera that is also acting as a server. You need a client implementation in the mix, in this case an RTSP client to consume the stream from the IP camera. Just like an electrical socket, you can’t join two of the same types of connections: the female wall outlet will only take a male plug. Female to female can’t link to each other and you can’t connect servers. You need a converter.
To perform the conversions role, Red5 Pro created a Restreamer Plugin to pull the RTSP stream as a client and re-stream it out over WebRTC. The stream can then be delivered over WebRTC to the browser clients.
In Red5 Pro, our primary ingest codecs are H.264 for video and AAC for audio. Normally, the IP cameras use either RTSP or MPEG-TS (the latter not using RTP) to encode media while WebRTC defaults to VP8 (video) and Opus (audio) in most applications. Since most modern browsers accept H.264 it is faster for Red5 Pro to simply pass the H.264 codec straight through WebRTC while transcoding the AAC codec to Opus. Finally, it routes to WebRTC clients using the WebRTC protocol stack.
However, in some use cases older systems might not be able to handle H.264. In those rare cases Red5 Pro converts H.264 to VP8.
Though this post does not focus on MPEG-TS, it bears mentioning that Red5 Pro supports both MPEG-TS and RTSP. MPEG-TS is either multicast or unicast ingest whereas RTSP would be unicast. Both support H.264 video and AAC audio codecs.
So That’s How it All Works
Fortunately, as we covered earlier, Red5 Pro has already done all this work for you. Find out more by visiting our website and documentation pages. Send any questions you have to firstname.lastname@example.org or schedule a call with us.