Using your DSLR as a webcam in Gentoo Linux


If you're like me, and have a DSLR camera and video meetings for school/work, you should probably put that DSLR to use.

A good DSLR will completely smash the video quality of even a pretty expensive webcam, color accuracy and so on.

So, let's get started! Thanks to crackedthecode for the base of this article.


Installing gphoto2, ffmpeg and v4l2loopback

ffmpeg

Emerge ffmpeg with the v4l USE flag enabled. That will add support for the v4l2 format.

You can either add it to your make.conf, or add it just for ffmpeg with /etc/portage/package.use.

gphoto2

Nothing special here, but I would recommend adding the CAMERAS="" variable to make.conf.

This way, gphoto2 won't compile in support for cameras you don't have. In my case, it's CAMERAS="canon".

v4l2loopback

If you're running a slimmed down kernel like me, you should make sure it has support for V4L2.

This can be done with one command: $> grep "V4L2" /usr/src/linux/.config

If you get some text in the output, you have support for V4L2. If not, go into your kernel configuration and enable CONFIG_VIDEO_V4L2.

Now, follow the instructions on installing the v4l2loopback kernel module here.


Usage

Before inserting the v4l2loopback module, check if you already have any video devices present.

Already present video devices

Now that you know what you already have, insert the v4l2loopback module.

After that, list all of your video devices again, and you should see a new one. Remember its name (videoX).

Modprobing and new video device

Now we can make gphoto2 write to that new device with ffmpeg. Of course, replace videoX with the new v4l2loopback device.

$> gphoto2 --stdout --capture-movie | ffmpeg -stream_loop 1 -re -i - -f v4l2 -vcodec rawvideo -pix_fmt yuv420p /dev/videoX

If all went well and it started recording, you're done! Now you can test it out on something like https://webcamtests.com.

DSLR webcam demonstration

Thanks for reading! If you have any questions or suggestions, add me on Discord.