digitaltrails / vdu_controls

VDU controls - a control panel for monitor brightness/contrast/...
GNU General Public License v3.0
103 stars 4 forks source link

Webcam very dark and stuttering heavily since using the Lux metering Bash script #89

Closed major-mayer closed 6 days ago

major-mayer commented 1 week ago

Hi there, I noticed that since I'm using my webcam with the lux metering bash script, my webcam image has become very dark and stutters heavily. I've tested it using multiple apps (Chromium, Firefox, Zoom, Gnome Camera).

I'm not 100% sure if that has something to do with the script itself, or it's just a coincidence that it started happening after I enabled the script. Either way, I thought that you maybe have an idea what could be the reason for this behavior. If so, feel free to tell me.

My rough guess would be that some configuration necessary for the lux metering is not properly reset after the script is executed.

PS: Do you know any off the shelf lux metering device, that's also compatible with this app? I'm not really into electronics that much, and not interested in building my own device.

digitaltrails commented 1 week ago

Sorry you've having problems with the camera. You will probably have to do some investigation.

It may be that some error has prevented restoration of the camera settings or the values specific to your camera differ from mine. The possible settings can be queried and this should list default values:

v4l2-ctl  --device /dev/video0 -l

I would restore any that are not on the default value. In particular auto_exposure would be worth checking. Perhaps getting access to a Windows machine with the actual manufacturer's software and drivers might also be worth a go.

I don't know of any pre-built inexpensive devices, but if google could locate a USB device that works with Linux, that might be able to be scripted to work. Perhaps some photography gadget (although photography gears is usually pricey).

The electronics side was pretty straight forward. I am also not much into building stuff, but it was a cheap experiment. I would confess, that after first thinking about building something, it was a couple of years before I got around to it, that's how much I'm not into building electronics. I do regret not doing it sooner, I needn't have put so much effort into the other alternatives present in vdu_controls.

major-mayer commented 1 week ago

Thanks for the very quick response, as always :heart: Indeed, using your command, I've discovered that there are some non-default values for the webcam:

 v4l2-ctl  --device /dev/video0 -l                                                              ✔ 

User Controls

                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=64 step=1 default=32 value=32
                     saturation 0x00980902 (int)    : min=0 max=128 step=1 default=64 value=64
                            hue 0x00980903 (int)    : min=-40 max=40 step=1 default=0 value=0
        white_balance_automatic 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=72 max=500 step=1 default=109 value=109
                           gain 0x00980913 (int)    : min=0 max=100 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1 (50 Hz)
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=6 step=1 default=2 value=2
         backlight_compensation 0x0098091c (int)    : min=0 max=2 step=1 default=1 value=1

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=1 (Manual Mode)
         exposure_time_absolute 0x009a0902 (int)    : min=1 max=5000 step=1 default=157 value=64
     exposure_dynamic_framerate 0x009a0903 (bool)   : default=0 value=1

I tried resetting those values to their default ones, but this gives me an error:

 v4l2-ctl  --device /dev/video0  --set-ctrl auto_exposure=3,exposure_time_absolute=157,exposure_dynamic_framerate=0     
VIDIOC_S_EXT_CTRLS: failed: Permission denied
Error setting controls: Permission denied

I also tried it with sudo, but that returned the same error. Maybe that's the reason why the restoring of the default settings in the script wasn't successful?

And thanks for your input about the electronic stuff, I might think about it again, because the components seem to be really cheap and professional camera equipment (which I've also found on the Internet) definitely isn't.

Edit: Those are the settings after i tried to change them back to default values:

v4l2-ctl  --device /dev/video0 -l                                                          255 ✘ 

User Controls

                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=64 step=1 default=32 value=32
                     saturation 0x00980902 (int)    : min=0 max=128 step=1 default=64 value=64
                            hue 0x00980903 (int)    : min=-40 max=40 step=1 default=0 value=0
        white_balance_automatic 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=72 max=500 step=1 default=109 value=109
                           gain 0x00980913 (int)    : min=0 max=100 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1 (50 Hz)
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=6 step=1 default=2 value=2
         backlight_compensation 0x0098091c (int)    : min=0 max=2 step=1 default=1 value=1

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=1 (Manual Mode)
         exposure_time_absolute 0x009a0902 (int)    : min=1 max=5000 step=1 default=157 value=157
     exposure_dynamic_framerate 0x009a0903 (bool)   : default=0 value=0

Seems like only the auto_exposure value wasn't changed.

Edit 2: Surprisingly, just changing the value v4l2-ctl --device /dev/video0 --set-ctrl auto_exposure=3 works :open_mouth: But not in combination with the other two values. The settings still say it is on value 1, but using any camera application, I can clearly see a difference in brightness and the stuttering is also gone.

 v4l2-ctl  --device /dev/video0 -l                                                          255 ✘ 

User Controls
[...]
                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=1 (Manual Mode)
digitaltrails commented 1 week ago

If it's on auto-exposure I would expect that it then dynamically controls things such as exposure_time_absolute, and perhaps also exposure_dynamic_framerate. That may be why it refuses to set those. I would expect setting auto-exposure back to 3 is all that is needed.

If it's like my camera, "3" means aperture priority, which means only aperture is controllable, exposure is automatically computed based on the current aperture. I think webcams generally have only a fixed/single aperture, so really "3" probably just means fully-automatic.

digitaltrails commented 1 week ago

Yes, a home built arduino approach is still the best bet. If the components can be sourced with pins pre-soldered, then no soldering would be required, just a solderless-breadboard and jumper-wires would be sufficient. I put the result inside an clear-box to protect the jumpers from coming loose (just a box I made by folding and stapling some clear plastic foil). It's been quite reliable. Since making it I've only had problems a couple of times, a reset by momentarily unplugging the USB cable fixed those. Certainly the parts are surprisingly cheap.

I do also wonder if some inexpensive industrial light-meters, such as those made by Uni-T, and sold on aliexpress, might be made to work. Uni-T seem to make several bluetooth-enabled measuring devices based around a common enclosure. Github appears to contain a few projects that can obtain values from some of them. Even if they were accessible, my main concern would be to find out it they can be on-continuously, they're battery powered, so I suspect they may timeout and go offline.

major-mayer commented 6 days ago

If it's on auto-exposure I would expect that it then dynamically controls things such as exposure_time_absolute, and perhaps also exposure_dynamic_framerate. That may be why it refuses to set those. I would expect setting auto-exposure back to 3 is all that is needed.

Yeah it seems like it really expects auto_exposure to be set alone. So now, I've just hard-coded this to the bash script and tested it manually that the webcam exposure time is automatically determined again after the script has been run.

For the future, I will either build myself a light meter or use one of those industrial light meters that you mentioned. Thanks for the hint, I will tell when I get any results :slightly_smiling_face: