views:

285

answers:

3

How can I get video and audio streams from web cameras with Java (in a cross-platform way)?

For example, we have a computer with 3-4 USB web cameras; we want to get their streams and make them visible in the user interface. How can we perform such a thing? I need code for a simple app which would find ALL cameras on the computer and let us select camera to wach. Can any one, please share such one?

A: 

I'd use flex. It can be relatively easily integrated with java backend.

UPD:

Pure Java needed

Then you should consider JavaFX solutions. I'm not a big expert in javafx, I've only written some basic test applications, but I'm sure it's a modern way of solving described problem with pure java.

Roman
sorry - PURE JAVA needed... I like Flex... not my boss...
Blender
bugaga...=) Yep - modern way... or you suggest to send video stream from flash to java for encoding while JAVA can handel it on its own just for fun?=)
Blender
@Ole Jak: with which part are you disagreed? You aren't agree that flash (flex) solution is counted better due to flash is simply more popular? Or don't you agree that JavaFX solution is counted better solution than solution based on applets? If you know answers then don't ask questions. -1.
Roman
1) I do not agree to send data from flash to java because of TIME IT TAKES (you'd need to bild it in old client - server way and just keep sanding data thru http or sockets - not needed dev time spending))2) JavaFX - give an example (with source) please. 3)
Blender
+5  A: 

With java media framework JMF or FMJ

Here is an example with JVM

Enrique
+1  A: 

I see your comment about the solution needing to be "pure" java, but this is really "nearly" impossible. You will need to use some sort of native library for accessing the devices, with that being stated; I suggest that you look at Xuggler as your solution. Xuggler supports Windows, Mac, and Linux and they also offer example code for handling audio and video. Lastly the library is FREE. Webcam capture example: http://xuggle.googlecode.com/svn/trunk/java/xuggle-xuggler/src/com/xuggle/xuggler/demos/DisplayWebcamVideo.java

While Xuggle does not have an example of microphone capture, you can find samples on the mailing list or you could use code written by the packet-mulitbroadcaster project found here: https://code.google.com/p/packet-multibroadcaster/

Mondain
As a matter of fact, here's a post about capturing the screen and microphone: http://groups.google.com/group/xuggler-users/browse_thread/thread/111792482bdf1d21
Mondain