Webcam settings on Ubuntu and Fedora Linux CLI from terminal

About a month ago I gave a few examples on the topic of controlling your Video4Linux compatible webcam device on Ubuntu Linux operating system. Here's the link if you are interested:

Webcam settings control on Ubuntu Linux operating system

Today we will approach that topic from a different angle. We will use CLI to control our webcam device. Who would want to control visual device like webcam from CLI you might ask? I'm doing it CLI way, because I want to tweak my webcam using my Linux operating system startup scripts. That's something I can't do by using GUI.

Second reason for using CLI for webcam control could be that you feel better typing commands on your terminal instead of clicking around with your mouse. Or maybe you don't have mouse or GUI available? Anyways, lets get started...

For controlling webcam from Linux terminal we will use nifty little program "V4l2-ctl". Now I will give you short instructions how to install it on Fedora and Ubuntu.

Installing "V4l2-ctl" on Fedora

Here's how to install "V4l2-ctl" on Fedora Linux operating system:

su -c 'yum install v4l-utils'

Installing "V4l2-ctl" on Ubuntu

Here's how to install "V4l2-ctl" on Ubuntu Linux operating system:

sudo apt-get install v4l-utils

Using "V4l2-ctl"

After installing "V4l2-ctl" you can use following command to get basic info about your Video4Linux device:

v4l2-ctl --info

Next thing to do is to "probe" you webcam capabilities and controls:

v4l2-ctl --list-ctrls

We will use the output of the v4l2-ctl--list ctrls command to see what can we control. Output of this command could be something like this:

brightness (int)  : min=0 max=255 step=1 default=128 value=128
contrast (int)  : min=0 max=255 step=1 default=128 value=128
gamma (int)  : min=1 max=6 step=1 default=4 value=4
auto_gain (bool) : default=1 value=1
light_frequency_filter (menu) : min=0 max=2 default=0 value=0
sharpness (int)  : min=0 max=3 step=1 default=2 value=2

Now when we know what can we control, we can for example increase brightness to 200 out of maximum 255 and turn the auto_gain off. Here's how:

v4l2-ctl --set-ctrl brightness=200
v4l2-ctl --set-ctrl auto_gain=0

Now you can check are your settings applied by issuing v4l2-ctl --list-ctrls command again. Your next step could be putting your settings inside BASH and using this script to apply your webcam settings at boot. If you are interested in something like that and you run Debian based operating system like Ubuntu you can find more info in the "Step 2" of my following article:

Logitech webcam and "cannot set freq 16000 to ep 0×86" (Ubuntu bug #459445)

My friends, that's it for this little CLI webcam guide. Live long and prosper!

DevGenii

A quality focused Magento specialized web development agency. Get in touch!

9 thoughts on “Webcam settings on Ubuntu and Fedora Linux CLI from terminal

  1. Vida

    Hi, thanks for your guidance.
    I have a Fujitsu lh531 and Ubuntu 10.04.
    How can I use this method to flip my webcam?! I need a vertical flip.

    Reply
    1. Marko Author

      Hello, I’m afraid you can’t use this method. You can try preloading v4l1compat.so library because this is what’s solves vertical flip problem with some web cams. So if you want to run for example Skype you would use following line to start it from terminal:

      LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype

      If it works you can modify your menu launchers to use similar line for your web cam applications.

      Cheers and good luck!

      Reply
  2. anmol rana

    hi,

    i am using logitech quickcam messenger on my arm eval kit.

    when i use cat /dev.video0 >test.avi, and after sometime press ctrl-c, the file is created with few mbs of data.

    however test.avi doesnt play in gnome-mplayer. i took the file to host pc as wellas other windwos based pc and tried to play with vlc. The progress bar moves ahead but no display. it says undefined type.

    regards.

    Reply
  3. Mike Z

    What a fantastic howto! I was trying to use uvcdynctrl with no luck. This option worked perfectly to disable auto exposure and auto white balance on my logitech C310 camera. Thanks!

    Reply
  4. Eva P

    Hi,

    this gui is quite nice but mu point is to run the webcam on start up with the defined settings as default settings (into bash).

     

    The small script you wrote (and that i’ve read) is fixing a bug i do not have, so could you may be edit an other small bash script to reach this aim ? 🙂

    (script where we put the differents values of our choice as default settings of the webcam, that could be run on start up)

     

    I’m not so good in writing script, didn’t have time yet to  explore those script codes 🙁

     

    thanks a lot, a very kind of you to share your scripts with us 🙂

     

     

     

    Reply
  5. Shameel

    Hi,
    I tried installing v412-ctl packages in my Raspberry pi running Rasbian OS. But an error occurs saying “Unable to locate package v41-utils”.
    It reads package lists, builds dependancy tree and state information is also read succesfully, after this the error is occurring.
    Do you have any suggestions.

    Reply
    1. Peter

      the package is called v4l2 ( Video for linux 2 ), so you problem is that you switched the “l” with a “1”. So try v4l2-utils instead, hope it helped.

      Reply
  6. Junior

    This looks like it’s set to video 0. My problem is that I want to use an external cam. The only way I’ve found to do that is to run

    sudo rm /dev/video0

    Which disables my internal laptop webcam and my external one now works but it is video1 Anyway to get it to run with video1?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *