Using a Photo Camera as Webcam in Linux
Install dependencies:
sudo pacman -Syu ghoto2 v4l2loopback-dkms
gPhoto2: A digital camera download and access program.
v4l2loopback: A kernel module to create V4L2 loopback devices.
Connect the camera to the computer. Verify that the camera is detected with:
gphoto2 --auto-detect
To view the details of the camera:
gphoto2 --summary
To capture a test image with the camera:
gphoto2 --capture-image-and-download
To view the available live view sizes:
gphoto2 --get-config liveviewsize
TipIf any of the commands above output the error message “Could not claim the USB device”, try:
gio mount -s gphoto2
Load the v4l2loopback kernel module:
sudo modprobe v4l2loopback video_nr=9 card_label="Photo camera" exclusive_caps=1
video_nr=9: Create a loopback video device at /dev/video9. Adjust when needed.
card_label="Photo camera": Set the name of the video device to Photo camera. Adjust when needed.
exclusive_caps=1: Enable exclusive_caps mode that only reports CAPTURE/OUTPUT capabilities exclusively. Necessary for some Chromium/WebRTC based applications.
TipTo unload the kernel module, use:
sudo modprobe -r v4l2loopback
Verify that the loopback video device is created successfully:
v4l2-ctl --list-devices
Capture the video stream from the camera, and pass it to the loopback video device. Adjust liveviewsize and /dev/video9 to match the actual desired values:
gphoto2 --stdout --set-config liveviewsize=0 --capture-movie | ffmpeg -i - -vf format=yuv420p -f v4l2 /dev/video9
Verify that the loopback video device is working as intended with:
ffplay /dev/video9
If a window showing the live footage captured by the camera appears, the camera is now ready to be used as a webcam.
TipIf other applications fail to find the loopback video device, or fail to read the video stream, try restarting WirePlumber:
systemctl --user restart wireplumber
References
https://wiki.archlinux.org/title/V4l2loopback#Using_a_photo_camera_as_webcam_with_gPhoto
https://wiki.archlinux.org/title/GPhoto
https://wiki.archlinux.org/title/GPhoto#Claimed_device
https://askubuntu.com/questions/993876/gphoto2-could-not-claim-the-usb-device
https://www.youtube.com/watch?v=s_Fva7T3l4I
https://github.com/v4l2loopback/v4l2loopback#options
https://bugzilla.mozilla.org/show_bug.cgi?id=2007675
ChatGPT