1
0
mirror of https://github.com/tiyn/wiki.git synced 2025-10-09 17:38:14 +02:00
Files
wiki/wiki/linux/v4l2.md
2025-09-22 02:05:29 +02:00

3.6 KiB

V4L2

V4L2 is the second version of Video4Linux. It functions as a driver for webcams and tv tuner cards and other devices.

v4l2loopback

The following section is based on a gist by ioquatix.

v4l2loopback is a utility to create a virtual video device. One use of it is in OBS Virtual Camera.

Setup

To use v4l2loopback an according package needs to be installed. Some distributions have a package named v4l2loopback-dkms in the package manager, making the manual installation process unnecessary. Make sure that both dkms and linux-headers packages are installed aswell.

Usage

This section focusses on various use-cases for the v4l2loopback software.

Create Temporary V4L2 Devices

v4l2loopback can be manually started by running:

modprobe v4l2loopback card_label='V4L2 Loopback' video_nr=7 exclusive_caps=1

video_nr=7 states the device path to use with v4l2loopback - in this case /dev/video7. This can be changed according to the needs. It is important that the device is not already in use by another application.

To create more than one device more labels or numbers can be appended. An example command with 2 V4L2 video devices will look like the following command.

modprobe v4l2loopback card_label='OBS Virtual Camera','IP Webcam' video_nr=7,8 exclusive_caps=1

Create Permanent V4L2 Devices

For an automatic start at boot via SystemD a service can be created - as described in the SystemD entry. For v4l2loopback create the file /etc/systemd/system/v4l2loopback.service containing the following lines:

[Unit]
Description=V4L2 Loopback

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/bin/modprobe v4l2loopback card_label='OBS Virtual Camera' video_nr=7 exclusive_caps=1
ExecStop=/bin/rmmod v4l2loopback

[Install]
WantedBy=default.target

Note the line starting with ExecStart=/bin/ is the same line described in the above section. Make sure to change it if needed.

Afterwards enable the service to start at every boot process aswell as running it by using the following command:

sudo systemctl enable v4l2loopback
sudo systemctl start v4l2loopback

Troubleshooting

This section focusses on various errors that can appear in the v4l2loopback software.

Failed to start streaming on '/dev/video2' (Invalid argument)

This error does occur most of the time when trying to start OBS' virtual camera. This section is based on an OBS Forum entry by rebelduck To fix it downgrade the packages v4l2loopback-dkms and v4l2loopback-utils to the last working version. For Arch Linux this can be achieved by using Downgrade.

Error! Bad return status for module build on kernel

When updating the v4l2loopback package this error can occur after the creation of the initramfs. This may point to an incompatibility of the package and kernel version which can only but easily and temporarily be fixed by downgrading the package as described in the corresponding package manager section.