2 Simple Ways to make IP Camera WebRTC (Web) Compatible

ahmet oğuz mermerkaya
4 min readMay 22, 2019

--

The incompatibility between RTSP IP Camera and Web Browsers is a headache. We need to use some third-party plugins for web browsers or use some native applications to watch the IP Camera. It absolutely doesn’t feel comfortable. Luckily, Ant Media provides 2 ways to make RTSP IP Camera WebRTC (Web browser) compatible. The first one is for IP Camera User and the second one is for IP Camera Manufacturers.

Let me describe these two solutions.

1. Make IP Camera WebRTC Compatible for IP Camera Users

As known, WebRTC is supported by Web Browsers(Safari, Edge, Chrome, Firefox, Opera) natively. If we change the RTSP stream to WebRTC then RTSP IP Camera can playable on Web Browser. This magic happens inside of the Ant Media Server.

Let’s explain how Ant Media Server do this magic.

  • Ant Media Server can pull streams from RTSP, RTMP servers. IP Cameras are RTSP servers at the same time so that Ant Media Server can pull IP Camera’s stream via its RTSP URL.
  • Ant Media Server can convert RTSP stream to WebRTC stream internally and IP Camera stream can be watchable via WebRTC on Web Browser.

RTSP IP Camera to Web Browsers (One-to-Many)

  • Watching RTSP IP camera is also scalable which means Ant Media Server can pull stream from IP Camera once and provide many viewers to watch it. In other words, Ant Media Server just multiplexes the IP Camera’s RTSP stream to WebRTC Stream

How to Add RTSP IP Camera to Ant Media Server

Ant Media Server provides two way for adding IP Camera.

First way is adding the RTSP IP Camera to the Ant Media Server through Web Panel or addStreamSource REST Method. Let me show the simpler way, login to web panel, switch to your app and Click “New Live Stream > Stream Source” as shown below.

Just type the RTSP URL to the form and Click “Create” button

Ant Media Server Connect to RTSP URL automatically and fetch the stream. Keep in mind that if you need Ultra Low Latency, use WebRTCAppEE for adding RTSP URL

Second way to add IP Camera to Ant Media Server is through ONVIF URL. You can check this blog post for learning how to add IP Camera via ONVIF URL

2. Embedded WebRTC SDK for IP Camera Manufacturers

This solution is for IP Camera manufacturers. If you just want to use Peer to Peer connection between IP Camera and Web Browser, Ant Media can provide a solution for this case as well.

Embedded WebRTC SDK can run both on ARM and x86 processors. So let me explain what this Embedded WebRTC SDK does.

  • IP Cameras generally has a built-in RTSP URL. You can embed Native WebRTC SDK into your IP Camera and SDK let you fetch the RTSP stream internally and can forward the RTSP stream to the other Peer via WebRTC.
  • Native SDK does not transcode the RTSP stream, it just fetches the stream and forward it to the WebRTC stack. So that it does not need much CPU resources as its normal WebRTC stack needs. In addition it does not cause any latency.

WebRTC IP Camera and Browser (P2P)

  • Signaling of WebRTC SDK is compatible with Ant Media Server. So that you need to use Ant Media Server as a signaling server in order to have peer to peer connection between web browser and your IP Camera.

How to Use Embedded WebRTC SDK

We’ve deliver source code, documentation and support for using Embedded WebRTC SDK. There is only one method you need to call in your ARM application. Here is the sample code

int main(int argc, char* argv[]) {
rtc::InitializeSSL();

signalingThread = rtc::Thread::Current();

startWebSocket(“ws://Your_Ant_Media_Server_Address:5080/WebRTCAppEE/websocket”,
“rtsp://127.0.0.1:6554/stream1”, “stream1”);

rtc::CleanupSSL();
return 0;
}

As you see, critical method is startWebSocket method which has three parameters

  • The first parameter is the WebSocket URL of the Ant Media Server
  • The Second parameter is the internal RTSP URL of the IP Camera
  • Third parameter is the stream id that will be published

After you run this application, please visit the http://Your_Ant_Media_Server_Address:5080/WebRTCAppEE/peer.html and write stream id that you’ve used in your code(It’s stream1 in the sample code) and click the JoinButton. You will watch the IP Camera stream on your browser.

I hope this brief introduction would help you in getting started. To access Embedded WebRTC SDK or any question please keep in touch

Original blog post is on antmedia.io

--

--