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:

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

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


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