mardi 29 avril 2014

webcam - capture vidéo à partir de plusieurs caméras usb et affichage dans une interface utilisateur côte à côte à l'aide de JAVA + applet Java - Stack Overflow


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


I have tried using JMF. Out put is



  1. It doesnt work simultaneously for both cameras in most machines. It works for one camera capture at a time


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



Is there a way with/without JMF that I can open 2 webpages on one client PC with 2 applets for the same running on a remote server and show the videos from each USBCAM on each page?


I have used this while 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 my both applets. But as I said, most of the times, it starts one CAM and then gives the device is in use and cannot capture message.


Please suggest any solution.




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


Instead use :


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

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


You can check your second webcam by :using JMStudio. select File->Preferences->Capture Devices and then click on Detect Capture devices.


This can also be done using code but the above one is simpler. Still I m listing 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 admin if it dosent work.




If I recall correctly then in your code (JMF implementation), there should be list/array of devices (resources) java is trying to read the data (webcam stream) from. My guess would be, that you need to change code in such a way that if resource one is busy, then try to read from resource two. Essentially you are going over entire list of resources trying to read whatever is available to you.


Hope that helps.




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



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


I have tried using JMF. Out put is



  1. It doesnt work simultaneously for both cameras in most machines. It works for one camera capture at a time


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



Is there a way with/without JMF that I can open 2 webpages on one client PC with 2 applets for the same running on a remote server and show the videos from each USBCAM on each page?


I have used this while 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 my both applets. But as I said, most of the times, it starts one CAM and then gives the device is in use and cannot capture message.


Please suggest any solution.



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


Instead use :


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

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


You can check your second webcam by :using JMStudio. select File->Preferences->Capture Devices and then click on Detect Capture devices.


This can also be done using code but the above one is simpler. Still I m listing 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 admin if it dosent work.



If I recall correctly then in your code (JMF implementation), there should be list/array of devices (resources) java is trying to read the data (webcam stream) from. My guess would be, that you need to change code in such a way that if resource one is busy, then try to read from resource two. Essentially you are going over entire list of resources trying to read whatever is available to you.


Hope that helps.



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


0 commentaires:

Enregistrer un commentaire