secile / UsbCamera

C# source code for using usb camera and web camera in WinForms/WPF. With only single CSharp source code. No external library required.
MIT License
179 stars 55 forks source link

Problem with showing preview #26

Open Al3xMa opened 1 year ago

Al3xMa commented 1 year ago

First of all, thank you for this. This is realy great.

I'm trying to develop wpf app with this and i was testing with 3 different cameras (Logitech brio, one from lg and razer kiyo). Lg and Razer are working fine with no problem, but i cant get it to work with brio and i dont know why. I tried it with all possible video formats that i get from GetVideoFormat() method.

Problem appears here, when it tries to subscribe to event: image

image

Message of exception here is: "Value does not fall within the expected range." image

Any idea, what could be or can be done? If you need any more info, let me know. Thanks.

secile commented 1 year ago

Hello. Thank you for using my library and sending me a question.

I don't know reason why, but it seems that your camera Logitech brio is not support 'Preview Pin'. As far as I know, even if camera do not support 'Preview Pin', DirectShow's component Capture Graph Builder will make 'Preview Pin' automatically by inserting Smart Tee filter.

This is described in comment line 292 and below. or see also link below. https://learn.microsoft.com/en-us/windows/win32/directshow/previewing-video

So, I believed all camera supports 'Preview Pin'.

I do not have any idea to fix this problem at present, so, as a plan B, is it possible to adopt '2. use Timer and GetBitmap()' approach to show preview?

// 2. use Timer and GetBitmap().
var timer = new System.Windows.Threading.DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(1000.0 / 30);
timer.Tick += (s, ev) => Preview = camera.GetBitmap();
timer.Start();
secile commented 1 year ago

If you can use GraphEdit, I have some items I would like you to try. GraphEdit is tool for test DirectShow created by Microsoft. As to GraphEdit, show page below.

https://learn.microsoft.com/en-us/windows/win32/directshow/using-graphedit?ranMID=46128&ranEAID=wizKxmN8no4&ranSiteID=wizKxmN8no4-1yUTJ264eGGZk13yddGnyQ&epi=wizKxmN8no4-1yUTJ264eGGZk13yddGnyQ&irgwc=1&OCID=AID2200057_aff_7794_1243925&tduid=(ir__ib09dtywykkfbyq9klrj3irq2n2x6r6bpdcwhd6d00)(7794)(1243925)(wizKxmN8no4-1yUTJ264eGGZk13yddGnyQ)()&irclickid=_ib09dtywykkfbyq9klrj3irq2n2x6r6bpdcwhd6d00

By using GraphEdit, I want you to check Logitech brio has a Preview Pin or not.

Al3xMa commented 1 year ago

Thanks for quick response!

If i try with the second, timer option, i get this:

image

I have managed to setup GrapEdit and i inserted my device in it as shown in screenshot below. What do you want me to try? image

secile commented 1 year ago

By using timer, you got black image, right? Something is wrong...

Does another app can use Logitech BRIO? for instance, windows camera app can use the camera?

thank you for sending screen shot. there are 2 Capture Pin. does the camera has 2 dual cameras like in camera and out camera? I have never tested dual camera. It can be the reason.