RTCwebcam is a python application that can make use of a camera on other device(client) in the local area network as a virtual video device(webcam) on a linux computer(server). The application use the WebRTC API to send video stream of a client to the server, and use v4l2loopback to emulate video devices on the server.
- openssl
- On ubuntu-based linux distribution, it can be installed with the following command:
sudo apt install openssl
- On ubuntu-based linux distribution, it can be installed with the following command:
- v4l2loopback
- On ubuntu-based linux distribution, it can be installed with the following command:
sudo apt install v4l2loopback-dkms
- On ubuntu-based linux distribution, it can be installed with the following command:
- python packages
- list in
requirements.txt - can install all packages with the following command:
pip install -r requirements.txt
- list in
-
First Execute
run.shchmod +x run.sh ./run.sh
-
Then open the browser on an Android, IOS devices,or other devices with cameras, and go to
https://<server-ip>:8080.- You can reference the script output to know the possible server IP address.
- Since a webpage can only request for camera permissions under secure connection mode, you need to use a
https://link to access the webpage. - However, because the ssl certificate is self-signed, you will see a warning message when you open the webpage.
- You can ignore the warning message and continue to use the webpage.
- A popup window will appear to ask you to allow the application to access your camera. If not, please ensure that the browser has camera permission.
-
On the webpage, you can see the following options:
Source: Select the camera you want to use. Useful in case you have multiple cameras.Target: Select the target device on the server you want to use.Streaming: Start streaming.Stop: Stop streaming.
-
After start streaming, you can see the preview of the camera on the bottom of the page. On the server-side, you can now open webpages or applications that need to use the camera, like Google Meet, OBS, etc. And you will see the video device labeled
RTCwebcam Device #in the devices menu.
- The application is capable of inserting plugins to process each frame of the video stream.
- A plugin class needs to have
processmethod that takes aframe, which is anumpy arrayin RGB format and have shape(height, width, 3), as input and returns aframein the same format as output. - Please refer to
modules/Plugin.pyfor more information. - Currently, there are two simple plugins avaliable
FlipPlugin: Flip the video stream horizontally.PortraitPaddingPlugin: Padding the video stream into landscape mode. Useful for applications that will force crop the video stream in potrait mode, ex. Google Meet.
- To add and activate a plugin, you need to add to add the plugin into
global_pluginslist inserver.py,PortraitPaddingPluginis enabled by default.
- OBS will load
v4l2loopbackand create a virtual camera device at/dev/video0(if not found) when its virtual webcam starts. v4l2loopback-ctlshould have ability to add more virtual camera devices. However, I cannot let it work in my computer for now.- Therefore, I chose to create more than one device while loading
v4l2loopbackmodule, and only use devices withid>=1to avoid corrupting, so one should start the application before starting OBS virtual camera, and make sure to let the script reloadv4l2loopbackmoudle. - After RTCwebcam starts, one can add it as a source of an OBS Scene by selecting
Video Capture Device (V4L2)in theSourcesmenu.
- For now, IOS devices will stream videos in
yuvj420pformat, and recent versionffmpegwill produce warnings while decoding such format. As a result, the color will be somewhat different at the server-side, but still usable. - To avoid show tones of warnings, I chose to let python log to
stdout, and redirectstderrto/dev/nullby default. - If there is any problem with the application, please use
./run.sh --debugto show the error logs and open an issue.
- The application is only works on Linux for now.
- The resolution and framerate is force to be
640x360and30fpsfor now. Though you can change the resolution and framerate in the first few lines instatic/client.js, but it might not work as expected.
- KDE neon with ubuntu 20.04
- python 3.8
This project is modified from the following projects and links:
- Add more plugins and make them be able to select from the front-end.
- Make use of akvirtualcamera to emulate cameras on Windows and MacOS.
- Improve performance and add more resolution support.
- Make use of
v4l2loopback-ctlto dynamically add or remove virtual camera devices.


