For a long time, I wanted to have a decent webcam. (Although I did not want to spend a lot of money on it.) So I tried a couple of things,
I bought an HP w200, which is not bad but it does not suit my purpose. The room where I work does not have great lighting coditions for this webcam to work properly. I had a hard time setting up and using HP w200.
I Used my mobile Nokia 6.1 Plus as a webcam. This works beautifully even with the terrible lighting conditions in the room where I work. The problem with this though is that, since the video goes throught the network before actually redirected to the virtual camera device created with v4l2loopback, there is a significant delay in the video feed.
Coincidentally I am learning photography and recently I bought canon 200D mark II, Which is an entry level DSLR camera from canon. I wanted to try if I could use it as a webcam. It worked well.
Canon provides a lot of software tools for using this camera on mac and windows. Unfortunately this is not the case with linux. Although it is not officially supported, there is a way to use this camera as a webcam on linux.
gphoto2 and ffmpeg along with v4l2loopback can be used to achieve this.
I’m using Fedora while writing this post and follwoing are the steps for using this DSLR camera as a webcam on Fedora
To install the two libraries run
sudo dnf install gphoto2 v4l2loopback
Once this is installed, create a virtual camera device using
sudo modprobe v4l2loopback
Now let’s plug in the usb cable from the camera into the computer, then turn on the camera. To check if the machine is able to detect the camera, run
gphoto2 --auto-detect
The output will be something like
$ gphoto2 --auto-detect
Model Port
----------------------------------------------------------
Canon EOS 250D usb:003,007
and you will see the camera device detecete by the computer.
In some countries Canon EOS 200D mark II
is also called as Canon EOS 250D
.
To check the what all you can do with the camera device, run
gphoto2 --abilities
the output will be something like
$ gphoto2 --abilities
Abilities for camera : Canon EOS 250D
Serial port support : no
USB support : yes
Capture choices :
: Image
: Preview
: Trigger Capture
Configuration support : yes
Delete selected files on camera : yes
Delete all files on camera : no
File preview (thumbnail) support : yes
File upload support : yes
To read the frames from camera, run
gphoto --stdout --capture-movie
This will read the video frames from the camera and dump the raw data to stdout
.
If you are able to see the data being dumped on the standerd out, use ffmpeg
to redirect it to the virtual camera device.
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video2
In this case with ffmpeg, we are reading the raw video data from stdin
encoding it with rawvideo
, setting the pixel format to yuv420p
and outputting it to /dev/video2
which is the virtual device created by v4l2loopback
.
After all of this is done, you can use ffplay
or vlc
for checking the output you are getting from the camera.
vlc /dev/video2
or
ffplay /dev/video2
In conclusion, my experience with this device so far has been very good. I will be recording few videos about linux in the near future using this device. Also if you are interested here is the link for my 500px profile: