Skip to content

Instantly share code, notes, and snippets.

@jessarcher
Last active March 10, 2024 17:25
Show Gist options
  • Save jessarcher/39fbabd9864077a0a1349c24c8277af5 to your computer and use it in GitHub Desktop.
Save jessarcher/39fbabd9864077a0a1349c24c8277af5 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.)

@jessarcher
Copy link
Author

Hey @stanleyjzheng, glad to be able to help!

I'm not sure how to measure the latency, however it feels almost instantaneous.

My Canon 70D motherboard ended up dying though - apparently a common problem when used for video for extended periods. These days I'm on a Sony A6400 which is also very snappy, and supposedly can handle long term video use.

@stanleyjzheng
Copy link

Oh wow, I see! Thanks for your reply, I'll be sure to use this more sparingly. Thanks again for the awesome and easy to follow guide.

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