22

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?

1
  • Did you find any solution?
    – Royi
    Aug 11, 2014 at 17:08

4 Answers 4

8

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).

7

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
3

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
0

it took me forever to figure out, but the command i use to get my v380 to work on my linux box (ubuntu 20.04) is:

ffmpeg -re -rtsp_transport tcp -i rtsp://192.168.1.29:554/ch00_1 -f v4l2 /dev/video0

works great, but can't get the thing to return me to my prompt - ffmpeg program shows it's recording...and recording, and never returns me to my prompt. i have to ctrl-c the thing, but that ... isn't what i want or need.

how do i make it so i don't have to type that command everytime? i want the cam available even after a reboot, but don't know how to make that happen. google searches fall flat, because google wants to assume what i want instead of listening, either that, or ... i don't know how to ask google questions.

please help, i'm so close, just need ffmpeg to return me to my prompt, but keep the cam connected to /dev/video0 and have it survive reboots.

edit: i pressed ctrl-c and returned to my prompt. restarted "motion" service, and ... the camera is working. so confused. still won't survive reboots, and lord knows i can't memorize that ffmpeg command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .