Setting Up a DSLR Camera Webcam on Linux
Tags: miscellaneous, dslr, linux, webcam
Published: 2021-09-26 14:28:56

---
title: Setting Up a DSLR Camera Webcam on Linux
published: true
date: 2021-09-26 03:50:11 UTC
tags: Miscellaneous,dslr,linux,webcam
canonical_url: https://austingil.com/dslr-webcam-linux/
cover_image: https://austingil.com/wp-content/uploads/Misc-Blog-Cover.png
---

I finally set up my DSLR camera as a webcam, and it’s pretty cool. I wanted to share this post because I couldn’t find good, complete resources about it and I thought it might be useful for folks out there (and because future me will probably want it). Here’s everything I learned.

Here’s what I’m working with. Your setup may be different:

- Camera: Canon EOS 60D
- Operating System: Ubuntu 20.10

## Prerequisites

Before we get started, this may be a non-issue for a lot of folks as it’s common for camera manufacturers to create software for this. Canon, for example, make their [EOS Webcam Utility](https://www.usa.canon.com/internet/portal/us/home/support/self-help-center/eos-webcam-utility/) that makes it easy for Windows or OSX users. But I use Linux ([cue sad trombone](https://sadtrombone.com/)).

If you’re like me and a handy webcam utility is not an option, let’s continue.

## Setup

Firstly, make sure your camera is supported by checking this list: [gphoto.org/proj/libgphoto2/support.php](http://gphoto.org/proj/libgphoto2/support.php).

Install required software:

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

Next, run this random command. I’m still not 100% sure what it does, but I think it creates a “dummy” video capture device for you to use. This will make more sense later.

```
sudo modprobe v4l2loopback
```

Now, you can connect your camera and turn it on. After connecting your camera, you may see this icon:

![Linux camera icon](https://cdn.statically.io/img/austingil.com/f=auto%2Cq=70/wp-content/uploads/image-1.png)

This icon means your camera is connected as a drive. You don’t want this as it will interfere with the webcam utility.

Easiest way to deal with this is to kill all the gphoto processes by running this command:

```
pkill gphoto
```

If you just want to see the processes, you can use this command:

```
ps aux | grep gphoto
```

## Using The DSLR As A Webcam

Now, with the camera ready, we need to see where the “dummy” video device is mounted by running this command:

```
v4l2-ctl --list-devices
```

You may see a number of different drives like the image below. The key thing to pay attention to is the “Dummy video device (0x0000)” drive. You’ll need to reference that in the next step.

![](https://cdn.statically.io/img/austingil.com/f=auto%2Cq=70/wp-content/uploads/image.png)

Now we can use gphoto to control the camera with the following command. Note the reference to the dummy video. Yours may be different. It’s also possible to change on your same computer at a later point in time.

```
gphoto2 --stdout autofocusdrive=1 --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video4
```

With that command running, your camera should have started capturing video and you should see some live text processing the video in the terminal. To test it, feel free to check it on any website like [webcamtests.com](https://webcamtests.com/).

## Improve Your Setup

Unfortunately, the steps above are tedious, so the first thing you’re going to want to do is automate them. I prefer using [Bash aliases](https://www.gnu.org/software/bash/manual/html_node/Aliases.html) to make it easy.

First, we’ll open our `.bashrc` file:

```
sudo nano ~/.bashrc
```

I like to make one called “prepcam” to setup v4l2loopback and kill gphoto. Then I make another one called “dslrcam” to start the webcam. To do the same, add these lines to the bottom of your `.bashrc` file.

```
alias prepcam="sudo modprobe v4l2loopback && pkill gphoto"

alias dslrcam="gphoto2 --stdout autofocusdrive=1 --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video4"

```

With those changes in place, we can save and close the file. If you used `nano` like me, use `ctrl+x`, then when it prompts you to save, press `y`, and finally hit `enter` to keep the file with the same name.

We also need to load the changes in our Bash profile.

```
source ~/.bashrc
```

You’ll probably also want to pick up a dummy battery. These are things that look like camera batteries, and as far as the camera is concerned work like camera batteries, but they have a cable that plugs into the wall. These are handy to provide a consistent power source without the need to recharge.

For my camera, the model I was looking for was called “LP-E6 Style Dummy Battery”.

Picking up a USB hub was the next thing I would recommend. I like it because I use my camera in conjunction with a microphone on a boom arm and I like having a single cable to connect for my “recording mode”.

## Closing Thoughts

This was a fun project for me to work on, and I’m happy with the results. With that said, it was only worth it because I already had a DSLR camera I don’t use that often.

If I were to start from scratch today, I would make my life much easier by either picking up a camera that makes this all simpler.

If you want to pick up a nice camera that doubles as a webcam, the [Sony ZV-E10 Mirrorless Camera](https://electronics.sony.com/imaging/interchangeable-lens-cameras/aps-c/p/ilczve10-b) seems like it **should** only need a USB connection and be ready to go.

If all you want is a webcam, the best reviews I’ve found are for the [Lgitech C922 Pro](https://www.logitech.com/en-us/products/webcams/c922-pro-stream-webcam.960-001087.html) and compared to a full on camera, it’s MUCH cheaper at around $75. It won’t serve as a camera as well, but hey, smartphones are pretty darn good these days.

## References:

- [https://www.crackedthecode.co/how-to-use-your-dslr-as-a-webcam-in-linux/](https://www.crackedthecode.co/how-to-use-your-dslr-as-a-webcam-in-linux/)
- [https://www.youtube.com/watch?v=TsuY4o2zLVQ](https://www.youtube.com/wa)

Thank you so much for reading. If you liked this article, [please share it](https://twitter.com/share?via=Stegosource), and if you want to know when I publish more articles, [sign up for my newsletter](https://austingil.com/newsletter/) or [follow me on Twitter](https://twitter.com/Stegosource). Cheers!

* * *

_Originally published on [austingil.com](https://austingil.com/dslr-webcam-linux/)._