l1npengtul / nokhwa

Cross Platform Rust Library for Powerful Webcam/Camera Capture
Apache License 2.0
533 stars 137 forks source link

Nokhwa hangs during camera init on windows with the "Cam Link 4k" by elgato. #101

Open ConnorBP opened 1 year ago

ConnorBP commented 1 year ago

I have a video feed at 1080p 60 going into my elgato cam link 4k which i have also tried at 30 fps and it seems to pause somewhere during init when i call this: let mut camera = Camera::new(index,requested)?;. The init runs smoothly for my built in web cam, but for whatever reason when i change index to 1 which is my cam link it freezes without error and hangs forever. Not quite sure what is going on here just yet but it is quite annoying and almost certainly a bug.

Giotino commented 1 year ago

Hi, it also happens with my Logitech HD Pro Webcam C920 on Windows. With some debugging I found out that an index += 1; was missing from the MediaFoundation "drivers" for Windows.

Looking at the current senpai (master, main) branch it has been fixed: https://github.com/l1npengtul/nokhwa/blob/dbdb42bdc6c377b029cf40b3cca02c0a76cedf53/nokhwa-bindings-windows/src/lib.rs#L643 but the current release 0.10.3 has been released 3 day before the fix... (https://github.com/l1npengtul/nokhwa/commit/c6ddc22d202b950d52ddac34aaafbde44dac48af). There's also a 0.10.4 version on crates.io that I wasn't able to find referenced anywhere in this repo (edit: found it), but the issue is also there.

@l1npengtul Trying to apply that patch to the 0.10.3 version fixes the issue. With that I found out there's another issue: the compatible_format_list contains a lot of duplicates, in my case 1136 total formats when there are only 284 unique ones.

I think it can be easly fixed by deduping the framerate_list that contains [0, 0, 0, X, X, X, X] (where X is the framerate). The framerate_list is also initialized with three 0es, I'm not sure why.

l1npengtul commented 1 year ago

i was probably sleep deprived when i wrote that

Giotino commented 1 year ago

I don't know the release cycle of this crate, but since it affects some of the most popular webcam on the market (and not only some unknown brands) and since the last (and only) update from the release of the 0.10.3 (and 0.10.4) version was the one cited in my previous message: wouldn't be a good idea to release a nokhwa-bindings-windows 0.4.1 with this update (and maybe the deduplication of formats)?

BTW: the unrecognized format that broke my camera (and probably @ConnorBP 's one) was H.264 which I immagine is offered by a lot of known brands and medium to high end quality webcams.

l1npengtul commented 1 year ago

yeah, I'll release a windows 0.4.1

h264 wont be until 0.11 though :c