Tabular array of Contents

If y'all want a more professional looking image when video conferencing, it turns out that yous can use a DSLR camera as your webcam. Using a DSLR provides a number of benefits over an off-the-shelf webcam, about notably higher image quality, ability to finely adapt the frame of an image (zoom, wide angle), and adjust the depth of field. The depth of field aligning is what allows for a squeamish, smooth, blurred background.

It's straightforward to get setup within Linux, this is the guide for how information technology'due south done.

Laptop webcam image and DSLR webcam image.

Hardware Needed

  • A camera supported by gPhoto, with Liveview capabilities
  • Ability to connect your camera to your Linux-based PC through a USB cable
  • Ideally some way to power your photographic camera through a power supply. You tin can run from your photographic camera'south battery, but run fourth dimension will be express

Software Needed

  • gPhoto
  • v4l2loopback
  • ffmpeg
  • VLC (Optional, used for testing)

Before Getting Started

The configuration as detailed here works very well for most people. There are however a few important limitations to be aware of before yous become started

  1. Yous volition not capture the full resolution of your photographic camera's image sensor.

    This guide uses the gPhoto2 application and associated libraries, which enables you to control your photographic camera through concluding commands. gPhoto2's movie capture way captures a series of preview frames from your camera and outputs them as a motion JPEG video format. The resolution of the preview frames captured from your photographic camera varies, but will likely be less than 720p (1280x720).

    It would be dandy to capture an HD quality prototype from a large, sophisticated and expensive photographic camera, but in my feel the resolution doesn't affair equally much as you lot might retrieve. The greatly enhanced optics, large image sensor, and depth of field provided by a DSLR photographic camera contribute to a much ameliorate looking prototype.

  2. Video capture and encoding is CPU intensive and your organization may have operation issues.

    I developed this guide on an AMD Ryzen 7 workstation which had the processing ability to ingest and transcode the video stream from my camera with no issues. Brand no mistake though, video transcoding (as nosotros're doing here) is CPU intensive, and some lower-powered computers will have performance issues. It's difficult to say what the minimum specs are for this guide, but an Intel i7 class processor is close to the minimum needed to use this effectively.

Software Setup

Installing the required software can be accomplished through your distro's parcel director:

Debian/Ubuntu

            sudo apt-get install gphoto2 v4l2loopback-utils v4l2loopback-dkms ffmpeg                      

Arch Linux

            pacman -Due south gphoto2 v4l-utils v4l2loopback-dkms ffmpeg                      

Fedora

            sudo dnf install gphoto2 v4l2loopback ffmpeg                      

Video4Linux Configuration

Once you've installed the required packages, connect your camera to your PC via USB and power on the photographic camera. Yous can safely ignore whatsoever Bone popup message which may appear.

Open your Last awarding, and enter the post-obit control:

            sudo modprobe v4l2loopback exclusive_caps=              i              max_buffers=              2                      

Loading this kernel module manually (through modprobe) ways y'all will have to remember to modprobe every time you reboot. To ensure this module is enabled when your organisation is booted, you need to edit one config file /etc/modules, and create a new module config file /etc/modprobe.d/dslr-webcam.conf:

  • /etc/modules:
    • Add dslr-webcam as a new line at the end of /etc/modules. If yous have nothing but comments in this file, just add together dslr-webcam as the final line in this file.
                                      $ sudo half-dozen /etc/modules                  # /etc/modules: kernel modules to load at boot fourth dimension.                  #                  # This file contains the names of kernel modules that should exist loaded                  # at kicking time, i per line. Lines beginning with "#" are ignored.                  dslr-webcam                              
  • Using sudo create a new file /etc/modprobe.d/dslr-webcam.conf
    • Add the following content to this file, and save
                                      # Module options for Video4Linux, needed for our DSLR Webcam                  alias dslr-webcam v4l2loopback options v4l2loopback exclusive_caps=                  one                  max_buffers=                  ii                              

Note

Nosotros're using the allonym functionality of modprobe.d to provide an alternate and more than descriptive name (dslr-webcam) for our Video4Linux kernel module.

gPhoto2 DSLR Testing

At this signal, you should have everything configured to start testing. Still within your concluding, validate that gPhoto can run across and interact with your camera:

  • gphoto2 --auto-detect
    • List auto-detected cameras and the ports to which they are continued.
  • gphoto2 --summary
    • Summary of camera condition.
  • gphoto2 --abilities
    • Display the camera and driver abilities specified in the libgphoto2 database. Use --summary to query an overview of the camera.

You lot should now see the right photographic camera and gPhoto is able to report on it's capabilities:

Terminal output from gphoto2 --auto-detect
Output from gPhoto2

Output from gPhoto2

DSLR Webcam Video Testing

Still within the concluding permit's offset with something simple, capturing a single photograph. This command will take a single photograph using the settings defined on your camera, and save it to your PC:

            gphoto2 --capture-image-and-download                      
Apple //e Image Captured through gPhoto
Apple //e Paradigm Captured through gPhoto

Apple //e Prototype Captured through gPhoto

Bold that was successful, permit'due south try to stream video from the photographic camera:

            gphoto2 --stdout --capture-motion picture | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads              0              -f v4l2 /dev/video0                      

With this command, nosotros're:

  • Capturing date from the camera'south image sensor with gphoto2
  • Piping that data into ffmpeg, which is taking the mjpeg stream from ghoto2 and exposing it to the Video4Linux loopback device

Note

If you lot take a build of ffmpeg which supports GPU-based encoding, you tin can offload the decoding of the gphoto output to your GPU to reduce the CPU load associated with this process.

Y'all tin can verify if yous have capability for GPU offload by running ffmpeg -hide_banner -decoders |grep mjpeg_cuvid. If this control returns V..... mjpeg_cuvid Nvidia CUVID MJPEG decoder (codec mjpeg) (or something similar), you're all set.

For GPU-based decoding you'll want to pass -hwaccel nvdec -c:v mjpeg_cuvid info your ffmpeg command:

              gphoto2 --stdout --capture-movie | ffmpeg                \                                -hwaccel nvdec                \                                -c:5 mjpeg_cuvid                \                                -i -                \                                -vcodec rawvideo                \                                -pix_fmt yuv420p                \                                -threads                0                \                                -f v4l2 /dev/video0                          

You should see the verbose output from ffmpeg, with the last line providing detail on encoding status:

Encoding status output from ffmpeg
ffmpeg Encoding Status

ffmpeg Encoding Condition

Now, open the VLC application, select the Media Carte -> Capture Device (Ctrl+c). Enter /dev/video0 as the "Video Device Name", and click the "Play" push button.

Testing a DSLR capture device in VLC
Capture Device in VLC

Capture Device in VLC

You should now encounter a alive stream from your DSLR photographic camera!

Video output from a DSLR webcam in Linux
DSLR Webcam In Linux!

DSLR Webcam In Linux!

Video Conferencing with a DSLR Webcam

Yous now have all the components working together, assuasive your DSLR to be used as a webcam in Linux. Ensure that you accept the gphoto2 --stdout --capture-flick control running before starting your video conferencing awarding. Google Meet, Zoom, Microsoft Teams, WebEx, BlueJeans all work well with this setup.

Using Google Meet with a Linux DSLR Webcam
Google Meet with a Linux DSLR Webcam

Google Meet with a Linux DSLR Webcam

Effectively using gPhoto

The capabilities of gPhoto are impressive — providing a unified interface to programmatically control hundreds of unlike concrete cameras. With this broad capability comes some complexity — only once yous sympathize the basics it'due south not near as intimidating.

Three gPhoto Commands you lot demand to know

  1. gphoto2 --list-config

    • --list-config will produce a listing of all configuration entries specific to and bachelor for your camera.
  2. gphoto2 --get-config [config]

    • --get-config volition list the type, the current value and the available options of a configuration value. As an example:
            $ gphoto2 --go-config whitebalance                                     Label: WhiteBalance     Readonly:              0              Type: RADIO     Current: Auto     Choice:              0              Auto     Pick:              1              Daylight     Option:              2              Shadow     Choice:              3              Cloudy     Choice:              four              Tungsten     Choice:              5              Fluorescent     Selection:              half-dozen              Flash     Choice:              seven              Manual                      
  1. gphoto2 --set-config-value [config]

    • --ready-config-value will set the specified configuration entry past specifying its new value. The output of — get-config will provide the values which are possible to fix. Another example:
            gphoto2 --set-config-value whitebalance=              "Daylight"                      

You tin also chain multiple --set-config-value commands, to get the exact setup you're looking for:

            gphoto2 --set-config-value whitebalance=              "Daylight"              --gear up-config-value discontinuity=              "3.v"                      

gPhoto Crush

gPhoto also provides an interactive shell, which is very useful for testing out various configurations:

            $ gphoto2 --shell gphoto2:              {/habitation/ben}              /> get-config whitebalance Label: WhiteBalance Readonly:              0              Type: RADIO Electric current: Auto Choice:              0              Motorcar Choice:              1              Daylight Option:              two              Shadow Option:              iii              Cloudy Choice:              4              Tungsten Option:              5              Fluorescent Option:              6              Flash Choice:              7              Manual End gphoto2:              {/abode/ben}              /> set-config whitebalance=              4