First the bad news: There is currently no built-in solution to do that in any distro I know.
The good news is that such a solution is very easy to implement and can be adapted for many similar problems: we only need to use a bit of udev and bash.
First, we need a programatic (script-friendly) way to set these settings. My favorite is v4l2ctrl
, as it can save V4L2 configurations and then restore them on demand. For example:
- First change your camera settings with any program you like. I really recommend qv4l2 for that, it's awesome.
Then, save the camera settings to a file. (-d /dev/video0
is optional, but useful if you have more than one camera.)
v4l2ctrl -d /dev/video0 -s camera-settings.txt
If you unplug and plug again the settings will be lost, but now we can recover them:
v4l2ctrl -d /dev/video0 -l camera-settings.txt
Once you get it working like that, it's time to automate it with udev. For this we will create a rule file of our liking that matches the camera. The file can be called /etc/udev/rules.d/99-v4l2-default-settings.rules
and contain something like this:
SUBSYSTEM=="video4linux", ATTR{name}=="HD Pro Webcam C920", RUN+="/etc/camera-defaults/udev-hook.sh"
The above will run as root the script /etc/camera-defaults/udev-hook.sh
that we will soon create whenever a device of subsystem video4linux
whose manufacturer name is "HD Pro Webcam C920" is detected or unplugged.
We could add many different filters to our rule. You can use udevadm info -a -p $(udevadm info -q path -n /dev/video0)
to get all possible variables for the device, as well as for its parent devices.
Finally, create the script. Here is something simple that will work. Give it execution permissions!
#!/bin/bash
set -eu
# Useful for debugging, if you want to check what variables are available:
# set > /tmp/vars
if [ "$ACTION" == "add" ]; then
v4l2ctrl -d "$DEVNAME" -l "/etc/camera-defaults/camera-settings.txt"
fi
Move camera-settings.txt
to the specified directory, unplug and plug again. The settings from that file should have been restored successfully.
Any time in the future you need to save your settings permanently, use your favorite program to tweak them and then run:
v4l2ctrl -s /etc/camera-defaults/camera-settings.txt