joelpurra / node-uvc

Node.js library for USB Video Class (UVC) devices. Used to write software for webcams, camcorders, etcetera.
https://joelpurra.com/projects/node-uvc/
GNU Lesser General Public License v3.0
17 stars 1 forks source link

Windows version of libuvc #1

Open alexivaner opened 2 years ago

alexivaner commented 2 years ago

Do you have the windows version of libuvc? I tried to run display-detail example but have the following error. Glad if you could help. Thank you so much.

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'D:\Kerja\Octon\ptzExample2\node_modules\@ffi-libraries\libuvc-v0.0.6\platforms\windows-x86_64\index.js'
Require stack:
- D:\Kerja\Octon\ptzExample2\node_modules\@ffi-libraries\libuvc-v0.0.6\index.js
- D:\Kerja\Octon\ptzExample2\node_modules\uvc\src\device.js
- D:\Kerja\Octon\ptzExample2\node_modules\uvc\src\context.js
- D:\Kerja\Octon\ptzExample2\node_modules\uvc\src\index.js
- D:\Kerja\Octon\ptzExample2\node_modules\uvc\index.js
- D:\Kerja\Octon\ptzExample2\node_modules\uvc\examples\display-details\display-details.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (D:\Kerja\Octon\ptzExample2\node_modules\@ffi-libraries\libuvc-v0.0.6\index.js:60:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (D:\Kerja\Octon\ptzExample2\node_modules\uvc\src\device.js:22:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\Kerja\\Octon\\ptzExample2\\node_modules\\@ffi-libraries\\libuvc-v0.0.6\\index.js',
    'D:\\Kerja\\Octon\\ptzExample2\\node_modules\\uvc\\src\\device.js',
    'D:\\Kerja\\Octon\\ptzExample2\\node_modules\\uvc\\src\\context.js',
    'D:\\Kerja\\Octon\\ptzExample2\\node_modules\\uvc\\src\\index.js',
    'D:\\Kerja\\Octon\\ptzExample2\\node_modules\\uvc\\index.js',
    'D:\\Kerja\\Octon\\ptzExample2\\node_modules\\uvc\\examples\\display-details\\display-details.js'
  ]
}
joelpurra commented 2 years ago

@alexivaner: sorry, no. Doesn't seem like Conan supports libuvc for Windows, presumably because libuvc itself seems to have issues compiling/running on Windows.

If the Conan recipe is improved, a new version of these bindings could be generated/packaged.

alexivaner commented 2 years ago

@alexivaner: sorry, no. Doesn't seem like Conan supports libuvc for Windows, presumably because libuvc itself seems to have issues compiling/running on Windows.

If the Conan recipe is improved, a new version of these bindings could be generated/packaged.

Thank you for your reply. I am a little bit wondering, what is the difference between this library and the other one uvc-control? is that the libuvc part? Because I saw you also active in the management of uvc-control and uvcc. My problem so far is I tried to control the PTZ camera with uvc-control, I could manage it when I replace the original driver with WinUSB but I couldn't get the camera streaming. Then if I switch back to the original driver, I could only get the camera stream and when trying to control the motor of PTZ, it said LIBUSB_PARAMETER_INVALID. This is why I tried to use this library that use libuvc as a backend. It will really help if you could give me some clue regarding this problem. Another workaround, I tested uvc-control at MacOS using libusb, but everything seems to be okay, both camera stream and ptz control works. Only in Windows, I could not manage both of them works.

alexivaner commented 2 years ago

Also yesterday I downloaded the compiled version of libuvc for windows from this repo: https://github.com/libuvc/libuvc/issues/136#issuecomment-653756627

The compiled version could be downloaded from this link: https://github.com/libuvc/libuvc/files/4872777/libuvc-master-complied.zip

But since I am not a C++ guy, I have no idea how to use this compiled version. Maybe, could it help for this libuvc in js? Thanks. Sorry for troubling you with so many questions.

joelpurra commented 2 years ago

@alexivaner wrote:

what is the difference between this library and the other one uvc-control? is that the libuvc part? Because I saw you also active in the management of uvc-control and uvcc.

Here's what I would say regarding the libraries I've worked with:

C/C++:

Javascript/Typescript:

Generated C/C++ library Node.js Foreign Function Interface (FFI) wrapper packages:

Note that I am also not a C/C++ programmer, which is why I use Node.js wrappers.

My problem so far is I tried to control the PTZ camera with uvc-control, I could manage it when I replace the original driver with WinUSB but I couldn't get the camera streaming.

WinUSB replaces the operating system USB (and therefore also UVC) driver for the camera. This way libusb can freely claim the interface on the camera USB device. Since the operating system driver has lost control, applications relying on the "standard" way to stream video cannot access the camera.

Then if I switch back to the original driver, I could only get the camera stream and when trying to control the motor of PTZ, it said LIBUSB_PARAMETER_INVALID.

Did you mean LIBUSB_ERROR_INVALID_PARAM?

Most cameras seem to have this "problem", which may not actually be the fault of the camera. Am not a USB/UVC standards expert, so guessing a bit here. Your camera is most likely following the UVC standard specification, which I think says that all camera control transfers (such as PTZ changes) should be sent to the camera's video control interface. If the camera is already used for video streaming, it cannot be claimed for control transfers.

Some cameras work despite another application already streaming video, but only if you send the camera control transfers to the device rather than the interface. This is probably intentional by the camera manufacturer, so they can ship their own camera control software, but am unsure if it is part of the standard. This workaround is used in uvcc.

There is a chance that changing the USB device configuration may offer both streaming and controls, but am unsure if the operating system driver would allow this, and if so, how it would react to the change.

This is why I tried to use this library that use libuvc as a backend. It will really help if you could give me some clue regarding this problem.

Using libuvc may not help, since the problem probably stems from the camera not accepting control transfer while streaming video to another application.

  1. Using low-level libraries like libusb/libuvc is similar to replacing the driver. Try using a Windows-only camera control application, which interacts with the built-in operating system driver instead. Am not using Windows much, so not sure which application would work. Please let me know what you find!
  2. Which camera do you use? If you are lucky, the workarounds in uvcc will work for your camera. If not, you may want to try a different camera. I was lucky when I bought a Logitech C920 HD Pro Webcam years ago, since control transfers to device works well even when other applications are streaming video.

Another workaround, I tested uvc-control at MacOS using libusb, but everything seems to be okay, both camera stream and ptz control works. Only in Windows, I could not manage both of them works.

The operating system's UVC driver in macOS (and Linux) works differently. Again, I can't personally confirm usage on Windows.

joelpurra commented 2 years ago

@alexivaner wrote:

But since I am not a C++ guy, I have no idea how to use this compiled version. Maybe, could it help for this libuvc in js?

The FFI code in node-uvc is generated by node-ffi-packager and should work, but untested at least by myself, on Windows.

Luckily it seems that the dependencies node-ffi-library-libjpeg-v9d and node-ffi-library-libusb-v1.0.23 already support windows-x86_64. You should first test if they run well on your machine. Did they work?

To get Windows support in node-ffi-library-libuvc-v0.0.6, try copying the files in ptzExample2\node_modules\@ffi-libraries\libuvc-v0.0.6\platforms\ from the linux-x86_64 directory to windows-x86_64. Then copy uvc.dll to the bin subdirectory and modify index.json to point to it. Does it work?

The best would of course to fix Windows support in libuvc, so that Conan can update their libuvc recipe, so that node-ffi-packager can generate a new node-ffi-library-libuvc-v0.0.6 package, so that node-uvc can use the update FFI wrapper...


Oh, and because of a bug in node-ffi-napi, it is recommended that you use Node.js v12 while testing. Node.js v14 and above might crash.

alexivaner commented 2 years ago

Wow, thank you so much for your really detailed answer.

  1. Using low-level libraries like libusb/libuvc is similar to replacing the driver. Try using a Windows-only camera control application, which interacts with the built-in operating system driver instead. Am not using Windows much, so not sure which application would work. Please let me know what you find!

About this one, I tried using AMCap, both video streaming and motor control works well when I used the original driver, so I hope is there any possibility to modify the library so it is also compatible with this original driver? Maybe the buffer send is somehow different that caused invalid parameter error

  1. Which camera do you use? If you are lucky, the workarounds in uvcc will work for your camera. If not, you may want to try a different camera. I was lucky when I bought a Logitech C920 HD Pro Webcam years ago, since control transfers to device works well even when other applications are streaming video.

I am using Aver PTZ330 camera. Thank you so much for your great works, it helps a lot of people though. It is not that easy to create all of those libraries.

The FFI code in node-uvc is generated by node-ffi-packager and should work, but untested at least by myself, on Windows.

Luckily it seems that the dependencies node-ffi-library-libjpeg-v9d and node-ffi-library-libusb-v1.0.23 already support windows-x86_64. You should first test if they run well on your machine. Did they work?

To get Windows support in node-ffi-library-libuvc-v0.0.6, try copying the files in ptzExample2\node_modules\@ffi-libraries\libuvc-v0.0.6\platforms\ from the linux-x86_64 directory to windows-x86_64. Then copy uvc.dll to the bin subdirectory and modify index.json to point to it. Does it work?

The best would

If I have time, I would try this one, thank you so much for your detailed explanation.

joelpurra commented 2 years ago

@alexivaner wrote:

About this one, I tried using AMCap,

Nit: that is not the AMCap website, it's a spam website trying to make money off of the hard work of independent developers. The credit should go to Noël Danjou who created AMCap. See also the AMCap FAQ.

both video streaming and motor control works well when I used the original driver, so I hope is there any possibility to modify the library so it is also compatible with this original driver? Maybe the buffer send is somehow different that caused invalid parameter error

It looks like Windows-specific software indeed, which is what I suspected. To both stream video and control the camera result I would not rely on libuvc or libusb, but instead something based on Windows' own APIs . Surely there's camera control software for Windows, too.

This is out of my comfort zone, but have a look at documentation such as Audio/Video Capture in Microsoft Media Foundation for some UVC video streaming code. Unsure about control transfers for camera settings, but it should be in there somewhere, and perhaps it's possible to modify if even though another application is streaming video.

I am using Aver PTZ330 camera.

Cool camera! Would be nice to get it working properly.

If I have time, I would try this one, thank you so much for your detailed explanation.

Let me know your findings! It'd be great if libuvc works on Windows, even with a workaround.

Wow, thank you so much for your really detailed answer. [---] Thank you so much for your great works, it helps a lot of people though. It is not that easy to create all of those libraries.

You're welcome =)