Set up a webcam with Linux

You want to use your webcam with a Linux computer? Good, then this article is for you.

If you have a notebook or a laptop with an integrated webcam, this will most probably work out of the box. If you have a USB webcam, connect it to your computer.

Then, you open a console (aka terminal) and type 


The "cheese" application will start up and show your webcam's output like this:

A capture from a webcam in the program Cheese

If this works, congratulations, you can now use your webcam with video editors, conferencing software, and so on. But:

  • cheese may not be installed
  • the drivers (aka kernel modules) for the webcam may not work
  • your Linux computer may not have a graphical user interface (or you may not want it)
  • you may want to switch between several webcams

Install Cheese

If you do not have the software cheese installed, you can install it by means of your distribution. Find out your Linux distribution, open a terminal and enter:

  • for Debian, Raspbian, Ubuntu, Kubuntu, Flubuntu, Xubuntu, GEUbuntu, Edubuntu and similar:

    sudo apt-get install cheese
    • for SUSE Linux
    yast -i cheese
    Afterwards, cheese will be installed.

    Fix the webcam drivers

    To check if your webcam's kernel modules are working, watch if the kernel can see the device. To do this, open a console and type

    ls -ltr /dev/video*
    the output should be something like this
    crw-rw----+ 1 root video 81, 0 Nov 11 09:06 /dev/video0

    If this is the case, congratulations, you have exactly one webcam recognized by the Linux kernel, and it's named video0.
    If the kernel does not see the webcam, check if it is really connected well. Because times where you had to manually load drivers for webcams should be over for long time now. Anyway, I was successful (long time ago) by commanding 
    hwinfo --usb

    I had a Logitech Quickcam Messenger plugged in and got:

    06: USB 00.2: 0000 Unclassified device
      [Created at usb.122]                
      UDI: /org/freedesktop/Hal/devices/usb_device_46d_8da_noserial_if2
      Unique ID: Eopr.vE+cdFBwClB                                      
      Parent ID: uIhY.uOe2OKugI8D                                      
      SysFS ID: /devices/pci0000:00/0000:00:1a.2/usb3/3-1/3-1:1.2      
      SysFS BusID: 3-1:1.2                                             
      Hardware Class: unknown                                          
      Model: "Logitech QuickCam Messanger"                             
      Hotplug: USB                                                     
      Vendor: usb 0x046d "Logitech, Inc."                              
      Device: usb 0x08da "QuickCam Messanger"                          
      Revision: "1.00"                                                 
      Driver: "snd-usb-audio"                                          
      Driver Modules: "snd_usb_audio"                                  
      Speed: 12 Mbps                                                   
      Module Alias: "usb:v046Dp08DAd0100dc00dsc00dp00ic01isc02ip00"    
      Driver Info #0:                                                  
        Driver Status: quickcam_messenger is active                    
        Driver Activation Cmd: "modprobe quickcam_messenger"
      Driver Info #1:                                                  
        Driver Status: gspca is active                                 
        Driver Activation Cmd: "modprobe gspca"
      Config Status: cfg=new, avail=yes, need=no, active=unknown       
      Attached to: #20 (Hub)

    This meant I could install and load the webcam driver like this (as I was using SUSE, I used yast -i to install the driver):

    yast -i gspcav-kmp-default
    modprobe gspca

    Then the kernel could "see" the device:

    ls /dev/video*
    /dev/video  /dev/video0

    Then I started gqcam and it showed me the webcam's output. Needless to say, today I'd not use gqcam, but cheese... but that was not available on this old Linux distro, and nowadays, the driver loads automatically anyways.

    There was also a webcam which needed the uvcvideo device driver:

    yast -i uvcvideo_kmp_default
    modprobe uvcvideo
    Good luck in trying this!

    Without graphical user interface

    Maybe you want to set up a surveillance system with your webcam taking pictures every 5 seconds over night. Then you need a command line solution to take pictures. You can:

    • use fswebcam:
    fswebcam -r 640x480 mypicture.jpg
    To take videos, you can:
    • use mencoder:
    mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0 -nosound -ovc lavc -o myvideo.avi
    • streamer, example for five seconds:
    streamer -c /dev/video0 -f jpeg -F stereo -o myvideo.avi -t 0:05

    Switch between webcams

    Switching between webcams should be done in the application, or you should choose another device on the command line. Only if this is absolutely not possible, you can delete the webcam device you do not want to use.

    Next steps

    Next, I want to use a RaspBerry Pi to take pictures of my gas meter and OCR it using DocumentAI. Then, I can make daily pictures and dump my gas counter measurements to find out how much gas I consumed when. Same for electrical power.


    Popular posts from this blog

    PuTTY: No supported authentication methods available

    My SAT>IP Server