joelpurra / uvcc

USB Video Class (UVC) device configurator. Used for webcams, camcorders, etcetera. Command line interface for automation.
https://joelpurra.com/projects/uvcc/
GNU General Public License v3.0
98 stars 5 forks source link

Get error trying to do `uvcc set absolute_exposure_time` on C920 camera #6

Closed galak closed 4 years ago

galak commented 4 years ago

kumar-macair:node-uvc-control galak$ uvcc set absolute_exposure_time 500 Error: Could not find a settable control named "absolute_exposure_time". at CameraHelper.setValues (/usr/local/lib/node_modules/uvcc/dist/camera-helper.js:54:19) at async CommandHandlers.execute (/usr/local/lib/node_modules/uvcc/dist/command-handlers.js:43:24) at async CommandManager.execute (/usr/local/lib/node_modules/uvcc/dist/command-manager.js:71:28) at async mainAsync (/usr/local/lib/node_modules/uvcc/dist/index.js:73:9)

joelpurra commented 4 years ago

@galak: absolute_exposure_time is not always a settable control. This depends on both other settings, such as auto-exposure, and general (hardware) support for the camera in question.

uvcc checks with uvc-control if the control is settable before attempting to set values, and throws if it is not.

From UVC 1.5 Class specification.pdf:

4.2.2.1.4 Exposure Time (Absolute) Control
[---] Note that the manual exposure control is further limited by the frame interval, which always has higher precedence. If the frame interval is changed to a value below the current value of the Exposure Control, the Exposure Control value will automatically be changed. The default Exposure Control value will be the current frame interval until an explicit exposure value is chosen. When the Auto-Exposure Mode control is in Auto mode or Aperture Priority mode attempts to programmatically set this control shall result in a protocol STALL and an error code of bRequestErrorCode = “Wrong state”. [---]
Optional Requests: SET_CUR

While I also have a C920 camera, I haven't experimented much with the absolute_exposure_time control specifically. Did you find a combination of settings where it is possible to set it?

galak commented 4 years ago

I've tried under linux with v4l2-ctl I was able to set exposure_absolute which I'm guessing is the same setting.

Here's a dump from v4l2-ctl:

                     brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                       contrast 0x00980901 (int)    : min=0 max=255 step=1 default=128 value=128
                     saturation 0x00980902 (int)    : min=0 max=255 step=1 default=128 value=128
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                           gain 0x00980913 (int)    : min=0 max=255 step=1 default=0 value=0
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=2 value=2
      white_balance_temperature 0x0098091a (int)    : min=2000 max=6500 step=1 default=4000 value=4000 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=255 step=1 default=128 value=128
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
              exposure_absolute 0x009a0902 (int)    : min=3 max=2047 step=1 default=250 value=250 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=1
                   pan_absolute 0x009a0908 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute 0x009a0909 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute 0x009a090a (int)    : min=0 max=250 step=5 default=0 value=0 flags=inactive
                     focus_auto 0x009a090c (bool)   : default=1 value=1
                  zoom_absolute 0x009a090d (int)    : min=100 max=500 step=1 default=100 value=100            
joelpurra commented 4 years ago

@galak: are you sure the setting was applied? I would guess you tried to set exposure_absolute to 500, like in your first uvcc example, but in your v4l2-ctl output it has a value of 250, which is also the default.

joelpurra commented 4 years ago

Note also flags=inactive for settings in auto mode, such as exposure_auto affecting exposure_absolute.

From the Video4Linux documentation in the Linux kernel:

If a control is not applicable to the current configuration of the device (for example, it doesn’t apply to the current video input) drivers set the V4L2_CTRL_FLAG_INACTIVE flag.

A bit deeper, in the documentation for void v4l2_ctrl_auto_cluster(...):

Use for control groups where one control selects some automatic feature and the other controls are only active whenever the automatic feature is turned off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs red and blue balance, etc. [---] In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s) if autofoo is in auto mode.

Basically, uvcc could be more clear regarding controls which are not settable at the time. That might overlap with controls which are optionally settable. uvcc could also just ignore (not throw an error) such "unsettable" input, and perhaps only warn for --verbose output.

galak commented 4 years ago

Mostly I'm trying to figure out how to explicitly set the exposure.

to do that I can do:

Set exposure to manual: v4l2-ctl -d /dev/video1 -c exposure_auto=1

Set exposure_absolute: v4l2-ctl -d /dev/video1 -c exposure_absolute=600

Read back exposure: v4l2-ctl -d /dev/video1 -C exposure_absolute exposure_absolute: 624

So trying to figure out how to do that with uvcc.

galak commented 4 years ago

Here's a bit more log from uvcc:

kumar-macair:~ galak$ uvcc get auto_exposure_mode
8
kumar-macair:~ galak$ uvcc set auto_exposure_mode 1
kumar-macair:~ galak$ uvcc get auto_exposure_mode
1
kumar-macair:~ galak$ uvcc get absolute_exposure_time
333
kumar-macair:~ galak$ uvcc set absolute_exposure_time 600
Error: Could not find a settable control named "absolute_exposure_time".
    at CameraHelper.setValues (/usr/local/lib/node_modules/uvcc/dist/camera-helper.js:54:19)
    at async CommandHandlers.execute (/usr/local/lib/node_modules/uvcc/dist/command-handlers.js:43:24)
    at async CommandManager.execute (/usr/local/lib/node_modules/uvcc/dist/command-manager.js:71:28)
    at async mainAsync (/usr/local/lib/node_modules/uvcc/dist/index.js:73:9)
kumar-macair:~ galak$ 
galak commented 4 years ago

So if I remove the settableControlNames.includes check then I'm able to modify absolute_exposure_time and see a difference.

joelpurra commented 4 years ago

@galak: ah, I see. It seems to have been caused by a bug in uvc-control -- it doesn't list the optional SET_CUR for absolute_exposure_time.

The upstream hasn't been updated in a while. I've fixed it in my fork, used by uvcc, though. I tested the fix locally, and took the liberty of closing this issue by releasing uvcc v2.0.3.

Does that fix your issue?

galak commented 4 years ago

@galak: ah, I see. It seems to have been caused by a bug in uvc-control -- it doesn't list the optional SET_CUR for absolute_exposure_time.

The upstream hasn't been updated in a while. I've fixed it in my fork, used by uvcc, though. I tested the fix locally, and took the liberty of closing this issue by releasing uvcc v2.0.3.

Does that fix your issue?

I'm not to familiar with node/npm. How would you suggest I install v2.0.3?

galak commented 4 years ago

I'm not to familiar with node/npm. How would you suggest I install v2.0.3?

nevermind figured it out. v2.0.3 fixes the issue. Thanks!

joelpurra commented 4 years ago

@galak: should be easy enough! I assume you installed uvcc the recommended way.

# NOTE: standard global executable installation.
npm install --global uvcc

# NOTE: update global executable installation.
npm update --global uvcc

You can also run npx uvcc and always use the latest version (for this and other npm executables), possibly at the cost of additional network traffic/delay.

Note: haven't verified the list of controls as implemented in uvc-control -- thanks for this report, and please report any further issues!