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

Is setting the manual focus available? #8

Closed witnessmenow closed 3 years ago

witnessmenow commented 3 years ago

Hello Again :)

I see I can swap between manual and and auto focus by setting the auto_focus flag, but is it possible to change the focus value?

I can verify the auto focus is being toggled by opening the settings menu (it doesnt update in real time, but it is different if I open and close it)

image

Using a C920 with windows.

witnessmenow commented 3 years ago

I was seeing available options using export,

C:\WINDOWS\system32>uvcc --vendor 0x46d --product 0x82d export
{
  "absolute_exposure_time": 666,
  "absolute_pan_tilt": [
    0,
    0
  ],
  "absolute_zoom": 100,
  "auto_exposure_mode": 8,
  "auto_exposure_priority": 1,
  "auto_focus": 0,
  "auto_white_balance_temperature": 1,
  "backlight_compensation": 0,
  "brightness": 128,
  "contrast": 128,
  "gain": 224,
  "power_line_frequency": 2,
  "saturation": 128,
  "sharpness": 128,
  "white_balance_temperature": 3233
}

But I do see there is more options in ranges, but I could not set "absolute_focus"


{
  "absolute_exposure_time": {
    "min": 3,
    "max": 2047
  },
  "absolute_focus": {
    "min": 0,
    "max": 250
  },
  "absolute_pan_tilt": {
    "min": [
      -36000,
      -36000
    ],
    "max": [
      36000,
      36000
    ]
  },
  "absolute_zoom": {
    "min": 100,
    "max": 500
  },
  "backlight_compensation": {
    "min": 0,
    "max": 1
  },
  "brightness": {
    "min": 0,
    "max": 255
  },
  "contrast": {
    "min": 0,
    "max": 255
  },
  "gain": {
    "min": 0,
    "max": 255
  },
  "saturation": {
    "min": 0,
    "max": 255
  },
  "sharpness": {
    "min": 0,
    "max": 255
  },
  "white_balance_temperature": {
    "min": 2000,
    "max": 6500
  }
}

C:\Users\Brian>uvcc --vendor 0x46d --product 0x82d set absolute_focus 100
Error: Could not find a settable control named "absolute_focus".
    at CameraHelper.setValues (C:\Users\Brian\AppData\Roaming\npm\node_modules\uvcc\dist\camera-helper.js:54:19)
    at async CommandHandlers.execute (C:\Users\Brian\AppData\Roaming\npm\node_modules\uvcc\dist\command-handlers.js:43:24)
    at async CommandManager.execute (C:\Users\Brian\AppData\Roaming\npm\node_modules\uvcc\dist\command-manager.js:71:28)
    at async mainAsync (C:\Users\Brian\AppData\Roaming\npm\node_modules\uvcc\dist\index.js:73:9)```
robin7331 commented 3 years ago

Same for macOS. I am able to find "absolute_focus" in my controls list but I'm not able to set any value to it.

➜  ~ uvcc set absolute_focus 100
Error: Could not find a settable control named "absolute_focus".
    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)

Getting the value (which is always 0) is working though. Is this read only?

➜  ~ uvcc get absolute_focus
0
joelpurra commented 3 years ago

@witnessmenow, @robin7331: absolute_focus is not always settable, since it requires auto_focus to be turned off. You already noticed this though.

It looks like the fix for absolute_focus is the same as for absolute_exposure_time -- the controls hardcoded in uvc-control lack the optional SET_CUR entry, thus uvcc doesn't know the value can be written (sometimes).

See

I'll patch this control specifically, but would appreciate it if someone could verify+patch controls.js in uvc-control so it matches the UVC standard document. (Either upstream or in my fork.)

robin7331 commented 3 years ago

I just saw you already added SET_CUR to node-uvc-control #1cc8b2b

Is there anything left to do except verifying according to the UVC standard document?

joelpurra commented 3 years ago

@witnessmenow, @robin7331: I've released uvcc v2.0.4, which should fix this issue. Can you please verify?


Update uvcc:

# 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!

joelpurra commented 3 years ago

@robin7331: for absolute_focus in particular I think that's it. Verifying (and patching) all controls against the standard would be greeeeeat though =)

robin7331 commented 3 years ago

Works like charm. Thanks for the quick fix! 👋

witnessmenow commented 3 years ago

I patched my local version of UVC-controls in my node_modules folders and that worked! I have been looking for a solution to programmatically setting the focus of my C920 while still allowing OBS to use the stream for at least 2 years (not constantly)!

Thanks so much for your work on this!

Pre-submit edit: (got called away to referee the kids!)

Updated using npm update -g uvcc and works great, thank you!