Capture video from multiple USB cameras and display side-by-side in the user interface using a JAVA + Java applet

I need to make 2 applets that will run on a server like TOMCAT, and when I access the client side web page [HTML page], I have 2 cameras attached to this client PC , and I want to show video from both cameras on 2 web pages on the client side at the same time .

I tried using JMF. Out put -

  • It does not work simultaneously for both cameras on most machines. It works to capture one camera at a time

  • It works on some machines, but you need to select cameras every time you open web pages. Select camera 1 for the first applet and camera 2 for the second applet.

Is there a way with / without JMF so that I can open 2 web pages on one client PC with two applets for the same work on the remote server and show video from each USBCAM on each page?

I used this when working with JMF.

private void StartStreaming() { String mediaFile = "vfw:Micrsoft WDM Image Capture (Win32):0"; try { MediaLocator mlr = new MediaLocator(mediaFile); _player = Manager.createRealizedPlayer(mlr); if (_player.getVisualComponent() != null) { setSize(480, 320); jpnVideoStream.add("South", _player.getVisualComponent()); } } catch (Exception e) { System.err.println("Got exception " + e); } _player.start(); } 

This is what is present in both of my applets. But, as I said, most of the time it launches one CAM, and then gives the device to use and cannot capture the message.

Please suggest any solution.

+4
source share
3 answers

The problem is that you are trying to use the same webcam in both applets.

Use instead:

 String mediaFile = "webcam 1" in applet 1 String mediaFile = "webcam 2" in applet 2 

Your first webcam: vfw: Micrsoft WDM Image Capture (Win32): 0

You can check your second webcam using: JMStudio. select File-> Settings-> Device Capture, and then click Capture Detection.

This can also be done using code, but the above is simpler. I also list the code:

 Vector list = CaptureDeviceManager.getDeviceList(null); int i; CaptureDeviceInfo tempDevice; // List all the devices ... if( list!=null) { if( list.size() == 0) { System.out.println("the device list is zero : "); System.exit(1); } System.out.println("The devices are : "); for( i=0;i< list.size() ;i++ ) { tempDevice = (CaptureDeviceInfo) list.elementAt(i); System.out.println(tempDevice.getName()); } } 

NOTE. Try running the code as an administrator if it works.

+1
source

If I remember correctly, then in your code (JMF implementation) there should be a list / array of devices (resources) that java is trying to read data (webcam stream). I assume that you need to change the code so that if the resource is busy, try reading two from the resource. In fact, you are browsing the entire list of resources, trying to read everything that is available to you.

Hope this helps.

0
source

It can work with JavaCV http://code.google.com/p/javacv/

0
source

All Articles