Skip to content

Instantly share code, notes, and snippets.

@njames
Forked from jessarcher/dslr-webcam.md
Created January 18, 2023 05:18
Show Gist options
  • Save njames/2a83d955c4a3a72e2d5cf799491e3d25 to your computer and use it in GitHub Desktop.
Save njames/2a83d955c4a3a72e2d5cf799491e3d25 to your computer and use it in GitHub Desktop.
Using my Canon 70D DSLR camera as a web cam on Linux

You'll need:

  1. Video 4 Linux loopback device kernel module (v4l2loopback) - Source: https://github.com/umlaeute/v4l2loopback (You might find builds in your distro's repos - I'm using Fedora so had to build it myself using https://github.com/danielkza/v4l2loopback-fedora/)
  2. gPhoto2 - this is what allows you to access your cameras live feed over USB - this was available in Fedora's repos.
  3. GStreamer or ffmpeg - this is what lets you stream the output from gPhoto2 into the loopback device.

It's been a little while since I set it all up so I can't remember all of the installation details, which will probably be different for your distro anyway unless you're using Fedora. Apologies if I have forgotten something as wel.

Running the stream

  1. Connect your camera, ensuring that if the camera is automatically mounted by your operating system that you unmount it, otherwise you will get "device busy" errors.
  2. Make sure the loopback kernel module is loaded:
    sudo modprobe v4l2loopback
    This should create a new video device in /dev, the device name will depend on what other video devices are already present (E.g. built-in laptop webcam). You can see all the devices by running the following:
    ls /dev/video*
    Your new loopback device should be the one with the highest number.
  3. Stream the output from your camera to the virtual video device
    Using GStreamer:
    gphoto2 --stdout --capture-movie | gst-launch-0.10 fdsrc ! decodebin2 name=dec ! queue ! ffmpegcolorspace ! v4l2sink device=/dev/video0
    Using ffmpeg:
    gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
    (Ensure that the binary names and device names match what is on your system)

You should now be able to select the Dummy Video Device in your video capturing software of choice (E.g. Zoom, Hangouts, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment