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):
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
- Let's assume your device is
/dev/media0
:
webcam_device="video0"
- 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.
- 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 (!)