I was unsatisfied with the poor image quality of my webcam so I have started an attempt to use my Fujifilm X-T2 photo camera as a webcam on Linux. Fujifilm does offer a software called “Fujifilm X Webcam” which allows Fujifilm X-Series cameras (DSLM) to operate as webcams but it works only on Windows and OSX.
For Linux one can use gphoto2.
Prerequisites
- Fujifilm X-T2 (or any other camera supported by gPhoto, with Liveview capabilities)
- Micro USB3.0 type B connector
- Ubuntu 20.04 (or any other Linux distribution that recognizes the camera as “USB PTP Camera”)
Setup
On Fujifilm X-T2 Menu:
Setup->Connection Setting->PC Connection Mode: USB AUTO
◎ PC Connection Mode: USB Auto
Install the required packages
sudo apt-get install gphoto2 v4l2loopback-utils v4l2loopback-dkms ffmpeg
sudo modprobe v4l2loopback exclusive_caps=1 max_buffers=2
add dslm-webcam
as a new line at the end of /etc/modules
:
$ sudo vim /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
dslm-webcam
create a new file sudo vim /etc/modprobe.d/dslm-webcam.conf
with the following content:
# Module options for Video4Linux, needed for our DSLR Webcam
alias dslr-webcam v4l2loopback
options v4l2loopback exclusive_caps=1 max_buffers=2
Check the number of the added device
ll /dev/video*
Check the information of the added device: v4l2-ctl --device=/dev/video0 --info
List auto-detected cameras and the ports to which they are connected: gphoto2 --auto-detect
Summary of camera status: gphoto2 --summary
Display the camera and driver abilities specified in the libgphoto2 database: gphoto2 --abilities
Start recording:
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video0
Integrated Webcam eg. Notebooks
Disable the Integrated Webcam: Temporarily disable the integrated webcam by blocking it at runtime:
sudo modprobe -r uvcvideo
Ensure the correct kernel modules are loaded:
sudo modprobe v4l2loopback
ll /dev/video*
To re-enable the webcam later: sudo modprobe uvcvideo
check whether dslm is found: gphoto2 --auto-detect
check whether the /usr/libexec/gvfs-gphoto2-volume-monitor process is blocking it:
ps -aux | grep gphoto
Start recording:
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuyv422 -color_range jpeg -f v4l2 /dev/video4
Some caveats
- I noticed after 1.5 hours of using the X-T2 as a webcam the video starts to show artifacts (due to overheating I guess).
- Sometimes I have to restart my PC to start recording
FAQ
check if a process is blocking: ps aux | grep gphoto
and kill all blocking processes with sudo kill -9 <pid>
References:
https://www.crackedthecode.co/how-to-use-your-dslr-as-a-webcam-in-linux/