Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open more than 2 webcams #139

Closed
ousmanou opened this issue Aug 30, 2013 · 16 comments
Closed

Unable to open more than 2 webcams #139

ousmanou opened this issue Aug 30, 2013 · 16 comments
Labels

Comments

@ousmanou
Copy link

@sarxos hi!
thank for your Webcam capture , but i am unable to open more than 2 webcams
i need some helps
i always got this exception

Exception in thread "pool-2-thread-1" com.github.sarxos.webcam.WebcamException: Cannot execute task
    at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.process(WebcamProcessor.java:57)
    at com.github.sarxos.webcam.WebcamProcessor.process(WebcamProcessor.java:120)
    at com.github.sarxos.webcam.WebcamTask.process(WebcamTask.java:35)
    at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.open(WebcamOpenTask.java:20)
    at com.github.sarxos.webcam.Webcam.open(Webcam.java:187)
    at com.github.sarxos.webcam.Webcam.open(Webcam.java:147)
    at com.github.sarxos.webcam.WebcamPanel.start(WebcamPanel.java:529)
    at cameraGUI$RunCamera.run(cameraGUI.java:147)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: com.github.sarxos.webcam.WebcamException: Cannot start native grabber!
    at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice.open(WebcamDefaultDevice.java:220)
    at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.handle(WebcamOpenTask.java:38)
    at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:66)
    ... 3 more
@sarxos
Copy link
Owner

sarxos commented Aug 30, 2013

Hi,

Thank you for the report. Can you share more details?

  • What is your operating system - Linux, Windows, Mac or something else,
  • What is the architecture - 32- or 64-bit,
  • What Java are you using (either openjdk or Oracle, and which version),
  • Are these two webcams connected via USB,
  • Do you have any code sample where issue is reproducible.

Moreover, can you perform a small test to check whether Webcam Capture API is able to open both cameras, but not at once? Try open the first one, then close, and then try to open the second one. I'm asking you to do that since there are some webcam devices which default, the build-in driver, is not able to handle, and the effect you are showing above is exactly the same. However, if you are able to open both devices separately, it means that it should not be the case.

@ousmanou
Copy link
Author

thank you for you fast response
the operating system that i use is windows 7 32-bit
and jdk1.7.0_21
Everything work fine when i connect two cameras simultaneously by using your same code given in the examples folder however i want to connect 4 cameras simultaneously . I try your test everything is fine i can open all of them separately .But whenever i tried to connect all the cameras simultaneously i get the error mentioned above.
Is there any way to perform that task ?
thank you once more

@ousmanou
Copy link
Author

i forgot to mention that all webcams are connected via USB

@sarxos
Copy link
Owner

sarxos commented Aug 31, 2013

Hi,

Thank you for the details. To be honest, I never tested default driver with more than two webcams, but will try this in this week. Will have to borrow webcam devices from my friends since I do not have so many of them :)

Theoretically the default driver (which use videoinput library by oftheo) should be able to handle up to 20 webcams at once - I will have to verify this.

As the w/a you can try installing GStreamer and try to use dedicated driver. For more details please check webcam-capture-gstreamer-driver page.

@ousmanou
Copy link
Author

ousmanou commented Sep 1, 2013

Hi , @sarxos ,
i try to use webcam-capture-gstreamer-driver but i didn't solve the problem .

@sarxos
Copy link
Owner

sarxos commented Sep 2, 2013

Hi,

Is the problem exactly the same, or stack trace is different? Can you post it here?

@ousmanou
Copy link
Author

ousmanou commented Sep 2, 2013

Hi
To be exact , i tested firstly examples inside the webcamcapture-gstreamer-driver examples folder before including in my academic project , unfortunately even the example did not work i got the following exception

java.lang.ExceptionInInitializerError
Caused by: java.util.UnknownFormatConversionException: Conversion = 'P'
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2646)
at java.util.Formatter$FormatSpecifier.(Formatter.java:2675)
at java.util.Formatter.parse(Formatter.java:2528)
at java.util.Formatter.format(Formatter.java:2469)
at java.util.Formatter.format(Formatter.java:2423)
at java.lang.String.format(String.java:2797)
at com.github.sarxos.webcam.ds.gstreamer.GStreamerDriver.init(GStreamerDriver.java:79)
at com.github.sarxos.webcam.ds.gstreamer.GStreamerDriver.(GStreamerDriver.java:49)
at ListSupportedResolutions.(ListSupportedResolutions.java:16)

@sarxos
Copy link
Owner

sarxos commented Sep 2, 2013

Ah, I know this exception - it's caused by a bug I accidentally made in String.format(..), it was already fixed in 8373146

Can you try it again with this JAR?

https://oss.sonatype.org/content/repositories/snapshots/com/github/sarxos/webcam-capture-driver-gstreamer/0.3.10-SNAPSHOT/webcam-capture-driver-gstreamer-0.3.10-20130807.231208-5.jar

@ousmanou
Copy link
Author

ousmanou commented Sep 3, 2013

hi
now i can run simultaneously two webcams with gstreamdriver , when i try to start the third one i get this message

0:00:10.738508000 300 07C1DF68 ERROR dshowvideosrc gstdshowvideosrc.cpp:589:gst_dshowvideosrc_change_state: Can't RUN the directshow capture graph (error=0x8007001f)

@sarxos
Copy link
Owner

sarxos commented Sep 3, 2013

Hi @ousmanou,

That gives us the explanation of why default capture driver didn't work. Some background: all the Windows implementations which deals with web camera devices are build on top of DirectShow, which expose API to build capture graph which will fetch images from such device. The 0x800701f is, according to the winapi, an error caused by the device not functioning properly:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd319335%28v=vs.85%29.aspx

ERROR_GEN_FAILURE
0x8007001F

May be used to indicate that the device has stopped responding (hung) or a general failure has occurred on the device. The device may need to be manually reset.

I'm not familiar with neither low level DirectShow functions nor with winapi and thus cannot give you any answer on why this is happening.

Are you connecting all the cameras to the USB hub, or you are using your build-in USB ports, and if this is the case, are you using USB3 as well? I googled a little bit and found that some people are encountering the same error when using multiple webcams, but there is no direct answer from Microsoft on why such error appears in case of multiple webcams.

This is worth to read:

http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/0278445c-c381-46f6-920b-b285b2a1a9ba/error-code-0x8007001f-after-starting-the-filter-graph

@ousmanou
Copy link
Author

ousmanou commented Sep 4, 2013

thank very much for your wonderful help ; Just one question , will i get better result using another operating system ?

@sarxos
Copy link
Owner

sarxos commented Sep 5, 2013

Not sure... However, from my experience I found that the fastest and less error-prone webcam support implementation is available on Linux. If I can be hones - implementing properly working Windows implementation was a pain in the arse... Just take a short compare look on these two systems, and on what they give you: the Video For Linux library (libv4l) is open source, constantly improved, very fast, and from the other hand Windows DirectShow is... closed implementation, not maintained any more, to be replaced by Media Foundation in future, hard to code.

@ousmanou
Copy link
Author

ousmanou commented Sep 6, 2013

@sarxos
thanks a lot
i will try with Linux ASAP

@sarxos
Copy link
Owner

sarxos commented Nov 15, 2013

Hi,

I was looking to reproduce this issue for some time, but I haven't had more than 2 webcam devices for tests. Lately I found some cheep ones on sale and bought 2 more. Today I tested this issue with 4 webcams total (using Ubuntu Linux) and was able to confirm that such issue exists, but it's caused by the USB and libv4l limitations, not the API itself.

Test environment:

  • Ubuntu Linux 12.04
  • 1 x embedded PC webcam
  • 3 x UVC webcam (Titanum) conected to USB hub

The outcome:

  • 4 webcams works fine with resolution QQVGA (176x144)
  • 3 webcams works fine with resolution QVGA (320x240), 1 fail to initialize
  • 2 webcams works fine with resolution VGA (640x480), 2 fail to initialize

The error message from libv4l is:

libv4l2: error turning on stream: No space left on device

NOTE! The error message is pretty misleading, but it means that there is not enough bandwidth on the USB controller to execute this operation.

Unfortunately I don't know the solution. In the future I will try to expose more camera parameters to the API so user will be able to tune them up so bandwidth is not so heavily consumed.

There is nothing I can do for now in regards to this ticket so I'm closing it.

@sarxos sarxos closed this as completed Nov 15, 2013
@sarxos
Copy link
Owner

sarxos commented Apr 9, 2015

Just FYI, the newest webcam-captrure-driver-v4l4j (Linux only) should select the most appropriate (i.e. the most bandwidth-friendly) image format. Therefore, at least on Linux, opening more webcams at once should be technically possible.

@nestormace
Copy link

Dear Sarxos:
I have a similar problem. I'm trying to connect 11 USB IPEVO HD Plus webcams to a PC running a Java program using a USB hub. The PC runs Windows XP.
I'm testing with just 2 webcams. The program open() both cameras, then reads several still images from both cameras and then close() both cameras.
I used to get all black images from the second camera and out of focus images.
Then I added a delay of around 2 seconds between each open() and all other commands and between each close() and any other command. I could get a correct behaviour for resolution of up the 1270 X 780.
Thing get worse with higher resolution - some runs present the old problems.
Things are also worse when using a hub than when using a PC USB port for each camera.
Is there some way to avoid these problems or at least to improve my "solution"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants