June 1, 2020

Convert ip cam to web cam in Linux for Jitsi, Zoom, etc.

by Oleg Dzhimiev

Basically, one need to direct the ip cam stream (mjpeg or rtsp) to a virtual v4l2 device which acts like a web cam and is automatically picked up by a web browser or a web cam application. This can be easily done by gstreamer or ffmpeg.

Quick setup

Install and create a virtual webcam

~$ sudo apt install v4l2loopback-dkms
~$ sudo modprobe v4l2loopback devices=1

Direct the stream

The options below are for gstreamer/ffmpeg and rtsp/mjpeg streams:

gstreamer:
# rtsp stream
~$ sudo gst-launch-1.0 rtspsrc location=rtsp://192.168.0.9:554 ! rtpjpegdepay ! jpegdec ! videoconvert ! tee ! v4l2sink device=/dev/video0 sync=false
# mjpeg stream
~$ sudo gst-launch-1.0 souphttpsrc is-live=true location=http://192.168.0.9:2323/mimg ! jpegdec ! videoconvert ! tee ! v4l2sink device=/dev/video0

ffmpeg:
# rtsp stream
~$ sudo ffmpeg -i rtsp://192.168.0.9:554 -fflags nobuffer -pix_fmt yuv420p -f v4l2 /dev/video0
# mjpeg stream
~$ sudo ffmpeg -i http://192.168.0.9:2323/mimg -fflags nobuffer -pix_fmt yuv420p -r 30 -f v4l2 /dev/video0

Finally

Start a video conference application, select the webcam from the menu (/dev/video0).
Test link: meet.jit.si

Details

Requirements

  • ffmpeg (2.8.15) or gstreamer (1.8.3)
  • IP camera capable of streaming mjpeg or rtsp – in this case it’s Elphel NC393

IP camera setup

  • rtsp stream ports for Elphel NC393 cameras: 554, 556, 558, 560
  • mjpeg stream ports for Elphel NC393 cameras: 2323, 2324, 2325, 2326
  • stream resolution/fps: 1920×1080, 30fps
  • ffmpeg for mjpeg stream – “-r 30” sets fps – the default ffmpeg setting is 25 fps

Useful commands

Print web cam settings:
v4l2-ctl -d 0 --all
Gstreamer play mjpeg:
gst-launch-1.0 souphttpsrc is-live=true location=http://192.168.0.9:2323/mimg ! jpegdec ! autovideosink
Gstreamer play rtsp:
gst-launch-1.0 -v playbin uri=rtsp://192.168.0.9:554 uridecodebin0::source::latency=0
Test stream for web cam:
sudo gst-launch-1.0 videotestsrc ! tee ! v4l2sink device=/dev/video0

Comments

  • Gstreamer 1.8.3 didn’t work without tees in the pipeline.
  • modprobe v4l2loopback can create multiple devices

Leave a Reply

Your email address will not be published. Required fields are marked *


6 × = forty eight