18

I want to use an IP camera with webrtc. However webrtc seems to support only webcams. So I try to convert the IP camera's stream to a virtual webcam.

I found software like IP Camera Adapter, but they don't work well (2-3 frames per second and delay of 2 seconds) and they work only on Windows, I prefer use Linux (if possible).

I try ffmpeg/avconv:

  • firstly, I created a virtual device with v4l2loopback (the command was: sudo modprobe v4l2loopback). The virtual device is detected and can be feed with a video (.avi) with a command like: ffmpeg -re -i testsrc.avi -f v4l2 /dev/video1

  • the stream from the IP camera is available with: rtsp://IP/play2.sdp for a Dlink DCS-5222L camera. This stream can be captured by ffmpeg.

My problem is to make the link between these two steps (receive the rstp stream and write it to the virtual webcam). I tried ffmpeg -re -i rtsp://192.168.1.16/play2.sdp -f video4linux2 -input_format mjpeg -i /dev/video0 but there is an error with v4l2 (v4l2 not found).

Does anyones has an idea how to use an IP camera with webRTC?

mpromonet
  • 8,785
  • 40
  • 48
  • 80
Minz
  • 301
  • 1
  • 2
  • 6

5 Answers5

7

Short answer is, no. RTSP is not mentioned in the IETF standard for WebRTC and no browser currently has plans to support it. Link to Chrome discussion.

Longer answer is that if you are truly sold out on this idea, you will have to build a webrtc gateway/breaker utilizing the native WebRTC API.

  1. Start a WebRTC session between you browser and your breaker
  2. Grab the IP Camera feed with your gateway/breaker
  3. Encrypt and push the rtp stream to your WebRTC session from your RTSP stream gathered by the breaker through the WebRTC API.

This is how others have done it and how it will have to be done.

UPDATE 7/30/2014:

I have experimented with the janus-gateway and I believe the streaming plugin does EXACTLY this as it can grab an rtp stream and push it to an webrtc peer. For RTSP, you could probably create RTSP client(possibly using a library like gstreamer), then push the RTP and RTCP from the connection to the WebRTC peer.

Benjamin Trent
  • 6,494
  • 3
  • 31
  • 40
  • This is not Quality capture, please make sure Lipsync, Latency is respected while answering. I have done your method but it has huge delay. Please ask WebRTC team to implemented native RTSP capture built in. –  Apr 14 '15 at 09:26
  • NPAPI is also removed in Chrome/Canary, then how one can use RTSP capture which is real-time, fast, no latency and delay were introduced? –  Apr 14 '15 at 09:29
  • @YumYumYum, RTSP is beyond the scope of what webrtc is trying to accomplish. If it is supported in the future, I will be very surprised. Lipsync and latency are issues but you can correct them by handling RTCP appropriately within your application. Gstreamer and janus are not last words and janus is a very new project that has tons of issues itself. Honestly, you could probably very easily use the native webrtc API and provide an RTSP stream through it – Benjamin Trent Apr 14 '15 at 12:57
  • @BenjaminTrent Can you please take a look at this question if you might be able to give me a few leads from the logs posted? https://stackoverflow.com/questions/46412464/ip-cam-in-combination-with-uv4l-and-janus-gateway-webrtc – OlaB Oct 02 '17 at 17:15
7

I have created a simple example transforming a RTSP or HTTP video feed into a WebRTC stream. This example is based on Kurento Media Server (KMS) and requires having it installed for the example to work.

Install KMS and enjoy ...

https://github.com/lulop-k/kurento-rtsp2webrtc

UPDATE 22-09-2015. Check this post for a technical explanation on why transcoding is just part of the solution to this problem.

mpromonet
  • 8,785
  • 40
  • 48
  • 80
lulop
  • 907
  • 8
  • 7
5

Janus-gateway recently added a simple RTSP support (based on libcurl) to its streaming plugins since this commit

Then it is possible to configure the gateway to negotiate RTSP with the camera and relay the RTP thought WebRTC adding in the streaming plugins configuration <prefix>/etc/janus/janus.plugin.streaming.cfg

[camera]
type = rtsp
id = 99
description = Dlink DCS-5222L camera
audio = no
video = yes
url=rtsp://192.168.1.16/play2.sdp

Next you will be able to access to the WebRTC stream using the streaming demo page http://..../demos/streamingtest.html

mpromonet
  • 8,785
  • 40
  • 48
  • 80
  • Thanks for the intelligent answer, but how do i push such a stream into firefox or chromium so the webrtc app can pick it up? Right now it just grabs the camera feed on IP:port but no video shows in the app conferences. – OlaB Sep 21 '17 at 11:01
  • 1
    @OlaB the video is available from [Streaming](https://janus.conf.meetecho.com/streamingtest.html), not from [VideoRoom](https://janus.conf.meetecho.com/videoroomtest.html). You can try also a project on which I am working that makes a gateway RTSP->WebRTC https://webrtc-streamer.herokuapp.com/ – mpromonet Sep 21 '17 at 11:07
  • Ok thank you sir, I would check it out now and maybe it can shed some more light on what you termed streaming, for example I am trying to run the jitsi video bridge but my source is an IP cam – OlaB Sep 21 '17 at 11:12
  • Wow! your project is awesome, just glanced through it and am really impressed – OlaB Sep 21 '17 at 11:15
  • the fact I am using an armv7l makes it so much sweeter :), but one quick question can I embed a video room in a custom java app I am writing? I just need a conference with video, but I see you have java script here – OlaB Sep 21 '17 at 11:16
  • for example the jitsi plug in or openfire offmeet provides its service through a url and I see you have some sort of provisioning for such services "Embed in a HTML page" am I correct in this assumption sir? – OlaB Sep 21 '17 at 11:19
  • 1
    With Jitsi, it needs a piece of code to send XMPP request, janus use simple HTTP request, there is a sample to publish RTSP url to a Janus video room https://webrtc-streamer.herokuapp.com/janusvideoroom.html. – mpromonet Sep 21 '17 at 11:23
  • sweet thank you sir! Do you like have a donation page or something to contribute to your project? – OlaB Sep 21 '17 at 11:25
  • and also can the janus video room be operated on a LAN?, we dont use the internet – OlaB Sep 21 '17 at 11:27
  • https://stackoverflow.com/questions/46412464/ip-cam-in-combination-with-uv4l-and-janus-gateway Can you please take a look at this question if you might be able to give me a few leads? – OlaB Sep 25 '17 at 19:15
4

If you have video4linux installed, the following command will create a virtual webcam from an rtsp stream:

  gst-launch rtspsrc location=rtsp://192.168.2.18/play.spd ! decodebin ! v4l2sink device=/dev/video1

You were on the right track, the "decodebin" was the missing link.

Dominic Cerisano
  • 2,789
  • 25
  • 41
2

For those who would like to get their hands dirty with some native-WebRTC, read on...

You could try streaming an IP camera’s RTSP stream through a simple ffmpeg-webrtc wrapper: https://github.com/TekuConcept/WebRTCExamples .

It uses the VideoCaptureModule and AudioDeviceModule abstract classes to inject raw media. Under the hood, these abstract classes are extended for all platform-specific hardware like video4linux or alsa-audio.

The wrapper uses the ffmpeg CLI tools, but I don’t feel it should be too difficult to use the ffmpeg C-libraries themself. (The wrapper relies on transcoding, or decoding the source media, and then letting WebRTC re-encode with respect to the ICE connections’ requirements. Still working out pre-encoded media pass-through.)

TekuConcept
  • 1,119
  • 10
  • 16