Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

jessarcher commented Aug 24, 2020

Just an update - these days I'm using ffmpeg instead of gstreamer. I have the following alias set up:

alias dslr-webcam="gphoto2 --set-config-value whitebalance="Auto" && gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0"

Loading

@dustinleblanc
Copy link

dustinleblanc commented Oct 27, 2020

Just wanted to say, this is working great on Pop OS 20.10 using the same Canon 70D. Thank you so much @jessarcher for posting this, I never would have thought I could get this rolling otherwise!

Loading

@Briketellen
Copy link

Briketellen commented Dec 29, 2020

Hi there, can I ask if this instruction will be suitable for all cameras? I wanna buy a new one and also use it as a webcam on Linux.
I have read many mirrorless cameras under 1000 review and wanna choose one of it, but don`t know if I can use it for this purpose. By the way, maybe someone of you has such mirrorless cameras? Maybe you can take advice on how to choose it? Thanks!

Loading

@jessarcher
Copy link
Author

jessarcher commented Dec 29, 2020

Hi @Briketellen, you'll need a camera that is supported by gphoto2, specifically the "Liveview" feature I think. They have a list of over 2700 models at http://gphoto.org/proj/libgphoto2/support.php along with what features are supported. I have heard some people find a bit of lag with the liveview feed so you may want to see if you can find a model that others are using successfully as a webcam.

Hope that helps!

Loading

@stanleyjzheng
Copy link

stanleyjzheng commented Jun 10, 2021

Many thanks! Didn't even know my 40d had the ability to take video. May I ask how bad your frame latency is? Mine is over 800ms, which feels rather laggy.

Loading

@jessarcher
Copy link
Author

jessarcher commented Jun 10, 2021

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.

Loading

@stanleyjzheng
Copy link

stanleyjzheng commented Jun 10, 2021

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.

Loading

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