Use a IP-camera as a virtual camera

7

5

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 convert a stream from an IP-camera to a virtual camera?

Minz

Posted 2014-05-09T09:49:06.303

Reputation: 71

Did you find any solution? – Royi – 2014-08-11T17:08:19.907

Answers

3

FFMpeg can receive video from your IP Camera and forward it to the virtual camera device. For this you need to specify first all the parameters of your IP camera, as follows I guess:

-f video4linux2 -input_format mjpeg -i rtsp://192.168.1.16/play2.sdp

then all your output parameters, as you used in your example:

-f v4l2 /dev/video1

So try this command:

ffmpeg -f video4linux2 -input_format mjpeg -i rtsp://192.168.1.16/play2.sdp -f v4l2 /dev/video1

Denis Krivitski

Posted 2014-05-09T09:49:06.303

Reputation: 131

2

You can also use gstreamer, since ffmpeg and avconv may have problems with the v4l2 format. Please note the use of decodebin in the pipeline.

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

Dominic Cerisano

Posted 2014-05-09T09:49:06.303

Reputation: 131

2

You were pretty close on your first attempt, actually. The input format is specified before the -i argument, like this: -f mjpeg -i rtsp://192.168.1.16/play2.sdp, and you might have to specify a pixel format like yuv420p to make the conversion to v4l2 possible (-pix_fmt yuv420p). That leaves us with something like this:

$ ffmpeg -f mjpeg -i rtsp://192.168.1.16/play2.sdp -pix_fmt yuv420p -f v4l2 /dev/video0

You can check that your ffmpeg installation supports v4l2 by running

$ ffmpeg -formats 2>/dev/null | grep v4l2

If this returns a non-zero exit code (and doesn't print a result), then you'll have to either compile ffmpeg yourself, or find a version with v4l2 enabled. More on that on the ffmpeg site.

Lastly, there's a very related question on StackOverflow, but it hasn't got an answer to your specific question (about using IP cams as webcams).

xieve

Posted 2014-05-09T09:49:06.303

Reputation: 21