3

I'm using a Logitech C720 webcam with my PC, which runs Devuan Beowulf GNU/Linux (~= Debian 10 Buster but without systemd).

In a related, but not Linux-specific, question on SuperUser, it turns out that I need to change my webcam's power line frequency setting.

However - I have no idea how to do that. My desktop environment, Cinnamon, does not have an item in the "System Settings" dialog for it. How do I make this setting, then?

3 Answers 3

14

On the command line, you can set the uvcvideo driver's power line frequency setting to the 50 Hz value with:

v4l2-ctl --set-ctrl=power_line_frequency=1

If your webcam is not /dev/video0, add a -d /dev/videoN option with the correct number. The v4l2-ctl command comes in package v4l-utils, at least on Debian and related distributions.

Also, v4l2-ctl -L will display a list of settings available in your webcam. It will also describe the available choices for settings like power line frequency. Your webcam may have a list of available settings that is different from mine.

To make the power line frequency setting persistent, you might want to make an udev rule of it. To do that, create a file named /etc/udev/rules.d/81-uvcvideo.ruleswith the following contents:

# Set power line frequency to European
ACTION=="add", SUBSYSTEM=="video4linux", DRIVERS=="uvcvideo", RUN+="/usr/bin/v4l2-ctl --set-ctrl=power_line_frequency=1"
10
  • There is no v4l2-ctl, nor does there seem to be a package offering it.
    – einpoklum
    Apr 23, 2020 at 7:25
  • @einpoklum I saw your comment edits and tried to incorporate them all to my answer; how about now?
    – telcoM
    Apr 23, 2020 at 7:34
  • I guess that's better, but - this just doesn't work on Devuan/Debian. Maybe this utility is found on other distributions? Or older versions of Debian/Devuan? The approach is sound, of course; see my new answer!
    – einpoklum
    Apr 23, 2020 at 8:10
  • @einpoklum Interesting: my answer is based on what I have on my Debian 10 system, and it certainly works here! But you might have a different webcam with differently-named settings (I believe at least some of the names come from the webcam firmware, although I might be wrong there). Are you sure you have the v4l-utils package installed?
    – telcoM
    Apr 23, 2020 at 8:20
  • 1
    If you have more than one webcam you may want to specify the device you're changing settings for. There are many ways to select devices in udev so I'll just show one example; the rest is well documented in udev manpage (man 7 udev). My Logitech C930e is configured with this rule: SUBSYSTEM=="video4linux", KERNEL=="video[0-9]*", ACTION=="add", ENV{ID_VENDOR_ID}=="046d", ENV{ID_MODEL_ID}=="0843", RUN+="/usr/bin/v4l2-ctl -d %N --set-ctrl zoom_absolute=140". You can print the required device infos with udevadm info /dev/video0 - change the dev path to other webcams you have as needed. Nov 20, 2020 at 22:33
2

If the app you're using does not allow you to make the relevant settings, and there's no "settings applet", use an app which can make these settings.

A prominent example would be guvcview - the GNU UVC viewer program. It's a utility for capturing video from devices using the Linux USB Video Class driver (UVC). When you start it up, you'll find the power line frequency setting:

enter image description here

and now you can change the US-centric 60 Hz into the more common 50 Hz.

Notes:

  • GUVCView may fail to start if another app is actively using the camera.
  • Setting the frequency this way does not persist with system reboots.
2
  • Unfortunately, these settings are not persistent. :/ It's not like the power line frequency changed between webcams, or when re-plugging one, or ... ever, really.
    – Raphael
    Dec 7, 2020 at 15:59
  • 1
    @Raphael: Indeed... and this is addressed in my other answer :-)
    – einpoklum
    Dec 7, 2020 at 16:58
0

Use the control utility for the Linux UVC driver

(This is a variant on @telcoM's answer)

(USB) webcams are controlled by the Linux USB Video Client driver. Their device files are /dev/video0, /dev/video1 etc.

One of the driver's setting is the power line frequency, which (typically) has 3 options:

  • 0 for Disabled, i.e. the driver won't account for the voltage cycle at all.
  • 1 for 50 Hz (most of the world)
  • 2 for 60 Hz (US and some others)

There are two alternative control utilities for this driver available on Debian systems. One is named v4l-ctl, covered in telcoM's answer, and the other is named uvcdynctrl; it is installed with the eponymous package, i.e. you need to run the following (as root or via sudo):

apt install uvcdynctrl

When the package is installed, do the following (not necessarily as a root user - it depends on the permissions of your camera's device file):

  1. List the available devices to make sure you see your camera:

    uvcdynctrl -l
    

    The output should look something like this:

    Listing available devices:
    video0   UVC Camera (046d:0825)
    Media controller device: /dev/media0
    Entity 1: UVC Camera (046d:0825). Type: 65537, Revision: 0, Flags: 1, Group-id: 0, Pads: 1, Links: 0
      Device node
      Entity: 1, Pad 0, Flags: 1
    video1   UVC Camera (046d:0825)
    Media controller device /dev/media1 doesn't exist
    
  2. Let's assume your device is /dev/media0:
    webcam_device="video0"
    
  3. Get the current power line frequency setting:
    uvcdynctrl -d${webcam_device} "--get=Power Line Frequency"
    
    This time, the output should be just a single number. In your case it will likely be 2, which corresponds to a frequency of 60 Hz.
  4. Set a new power line frequency:
    uvcdynctrl -d${webcam_device} "--set=Power Line Frequency" 1
    

If you know your device name, only the fourth command is necessary, of course.

Persisting your setting

As @telcoM notes, however, this is not a persistent setting. To make it persistent, you need to add a udev rule, to be executed when the camera is connected.

Create a file named /etc/udev/rules.d/81-uvcvideo.rules, with contents:

# Set power line frequency to 50 Hz
ACTION=="add", SUBSYSTEM=="video4linux", DRIVERS=="uvcvideo", RUN+="/usr /bin/uvcdynctrl -d$attr{name} --set=Power\\ Line\\ Frequency 1"

Notes:

  • $attr{name} should hold the new attached device's name, e.g. video0, video1 etc.
  • Theoretically, one could make this setting globally, irrespective of the device used. But - who knows? Maybe one of your cameras is pointed to a naturally-lit room where no powerline frequency correction is necessary.
  • The above rule has not been tested (!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.