36

I can't use my digital camera ( Canon ixus 160) as webcam is there an application for that ? or just in the settings?

2

4 Answers 4

33

Here's another solution.

List of gphoto2 supported cameras: http://gphoto.org/proj/libgphoto2/support.php

You need install gphoto, v4l2loopback-utils and ffmpeg.

Then

sudo modprobe v4l2loopback

and

gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1

Now you have webcamera from your digital camera.

3
  • 3
    I get this error (cut at top): Input #0, mjpeg, from 'pipe:': Duration: N/A, bitrate: N/A Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1056x704, 25 tbr, 1200k tbn, 25 tbc Stream mapping: Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native)) [swscaler @ 0x559c14f77de0] deprecated pixel format used, make sure you did set range correctly [v4l2 @ 0x559c14f42fc0] ioctl(VIDIOC_G_FMT): Invalid argument Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument Error initializing output stream 0:0 -- Conversion failed! ➜ ~
    – noreabu
    Commented Nov 4, 2017 at 11:01
  • @noreabu if you have other webcams, the /dev/video1 may not be the loopback device. You can check type of devices with v4l2-ctl --list-devices Commented Apr 22, 2020 at 11:38
  • 1
    It worked for me... but the resolution is 1056x704. Is it possible to change it to a 16:9 resolution, such as 720p? I am using a Cannon T3i and this option is available on Entangle... however I don't know how to change your command to switch to a different aspect ratio
    – Rafael
    Commented May 5, 2020 at 22:40
22

This can be done but requires a number of steps. First, you must install gphoto and v4l2loopback-utils.

sudo apt-get install gphoto2 v4l2loopback-utils

Plug in your camera via USB (when the camera mounts automatically, unmount it). Then run gphoto2 --abilities to see if your camera is capable of doing this. Here's the output when connecting a Canon EOS 1200D

enter image description here

Then run sudo modprobe v4l2loopback to activate the kernel module needed to create a video device from your camera.

I've seen older tutorials on this task that use gst-launch-0.10 to achieve the next step of this task (e.g. this one). I am using Ubuntu 17.04 which uses gst-launch-1.0. Below is the updated command to create a video device from your digital camera:

gphoto2 --stdout --capture-movie | gst-launch-1.0 fdsrc ! decodebin3 name=dec ! queue ! videoconvert ! v4l2sink device=/dev/video1

This will create a video device in /dev/video1, which you can now use in programs like VLC.

If you see any errors about the device being in use you need to kill the gvfs-gphoto2-volume-monitor process by running killall gvfs-gphoto2-volume-monitor.

9
  • 6
    I get this: ➜ ~ gphoto2 --stdout --capture-movie | gst-launch-1.0 fdsrc ! decodebin3 name=dec ! queue ! videoconvert ! v4l2sink device=/dev/video1 Setting pipeline to PAUSED ... Nehme Vorschaubilder als Film in 'stdout' auf. Drücke Ctrl-C zum abbrechen. ERROR: Pipeline doesn't want to pause. ERROR: from element /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: »/dev/video1« ist kein Wiedergabegerät. Additional debug info: v4l2_calls.c(642): gst_v4l2_open (): /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: Capabilities: 0x5200001 Setting pipeline to NULL ... Freeing pipeline ...
    – noreabu
    Commented Nov 4, 2017 at 10:57
  • @noreabu sounds like a bug that you should report Commented Nov 4, 2017 at 19:32
  • 1
    Try /dev/video2 Commented Dec 2, 2018 at 21:34
  • This worked via the ffmpeg answer above. I had to use guvcview to see the output
    – Jonathan
    Commented Jan 15, 2019 at 19:11
  • I'm getting modprobe: FATAL: Module v4l2loopback not found in directory /lib/modules/4.15.0-36-generic
    – virtualxtc
    Commented Jun 25, 2019 at 19:35
9

I was able to get video & image recording with a Canon DSLR 600D

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

Plug in camera, any mode seemed to work, test with the basics:

Prep

sudo modprobe v4l2loopback
killall gvfs-gphoto2-volume-monitor

Test

lsusb
gphoto2 --auto-detect
LANG=C gphoto2 --summary
LANG=C gphoto2 --list-all-config

Try

gphoto2 --capture-image
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1

Visualize (in another terminal)

guvcview

or

guvcview-brlin.guvcview

You can try different /dev/video1 commands

There's also EOS Movie Recorder

Unzip this: https://sourceforge.net/projects/eos-movrec/files/eos-movrec/0.3.3_beta/eos-movrec-0.3.3_beta.zip/download

cd eos-movrec-0.3.2_beta
sudo apt install libgphoto2-dev                                     
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
3
  • 3
    thanks. i use this and then capture the window in OBS "gphoto2 --stdout --capture-movie | ffplay - "
    – y o
    Commented Apr 2, 2020 at 2:15
  • Thank you for this. Is it possible to access the camera microphone at the same time (and make it an accessible device)?
    – azmeuk
    Commented May 24, 2020 at 14:53
  • OBS has microphone capability, and plugins that can expose the whole setup as a webccam too
    – Jonathan
    Commented Aug 13, 2020 at 2:18
6

I found this very useful for me and it did work with my Canon 5D Mark 3

How to use you DSLR camera as a webcam

OBS is a great tool for live streaming and recording a presentation or training. It can also be used to create a virtual webcam to act as input to tools such as Jitsi, Skype and Zoom. Lots of us have good DSLR type cameras, and these can act as a webcam for input to OBS (and any other tool that can use a webcam source). This allows you to use a high quality camera for the video input, and gives you the full control that you get with a digital camera. In this video, I show you how to use pretty much any camera as a webcam for OBS without any special software or hardware adapters. All you need is a camera and a USB cable. This is achieved using the combination of gphoto2, ffmpeg, and v42loopback.

  1. Make sure your camera make and model is supported. You will find a list of cameras supported by this method at http://gphoto.org/proj/libgphoto2/support.php Fortunately, my Canon cameras are all supported. You will need a supported camera and a USB cable to connect the camera to your computer.

  2. Set your camera so that it does not automatically power off. On my Canon 6D Mark ii this is "Auto power off: Disable" on the wrench screen 2.

  3. If you have back-button focus enabled, you need to set focus back the the half press of the shutter key. If you use back button-focus you already know how to do this. If you leave back-button focus on, you will get errors relating to shutter button half press.

  4. If you don't have gphoto2 installed, you need to install it first.

    sudo apt install -y gphoto2
    
  5. If you don't have the video loopback driver installed, you need to install it first.

    sudo apt install -y v4l2loopback-utils
    
  6. If you don't have ffmpeg installed, you need to install it first.

    sudo apt install -y ffmpeg
    
  7. Plug in your camera via USB (if the camera mounts automatically, unmount it) by selecting it in your file manager (Nautilus if you are using Gnome) and right click, and select "Unmount" from the popup menu.

  8. Enable and determine the virtual video device First unload v4l2loopback so you can determine which device it is creating.

    sudo rmmod v4l2loopback
    

    Ignore any errors.

  9. List all video devices so you know which one is next in line ls /dev/video* You will see something like /dev/video0 /dev/video1 which indicates video devices already on my computer. If you see nothing here, then you have no video devices.

  10. Activate v4l2loopback Run

    sudo modprobe v4l2loopback exclusive_caps=1 max_buffers=2
    

to activate the kernel module ('loopback driver') that enables the creation of a video device from your DSLR camera.

  1. List all video devices so you know which one is the one to use ls /dev/video* You will see something like /dev/video0 /dev/video1 /dev/video2 The last one will be the one used by the loopback driver, in this case video2.

  2. TESTING Now you can do some testing using gphoto 2. List auto-detected cameras and the ports to which they have been connected.

    gphoto2 --auto-detect
    

    You will see something like:

    Model                          Port                                            
    ----------------------------------------------------------
    Canon EOS 6d Mark II           usb:001,013 
    
  3. Capture the video and pipe ot out to the virtual webcam device

    gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video2
    
  4. That is it. Now you can go and add it to your source in OBS.

All simple, and all free thanks to Free and Open Source Software.

3
  • Same comment as earlier. Is it possible to access the camera microphone at the same time (and make it an accessible device) ?
    – azmeuk
    Commented May 24, 2020 at 14:54
  • Thanks for this awesome tutorial. It works flawlessly on my EOS 6D. How do I make autofous work?
    – tcapelle
    Commented Jan 1, 2021 at 17:35
  • Thanks, key was activated v4l2loopback with parametrs max_buffers and exclusive_caps
    – Peter1982
    Commented Jun 2, 2021 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .