David Fischer's Java Programming Examples:
Capture Video from Logitech QuickCam Pro 3000
Camera with Java JMF
Homepage (in German Language)
 
Homepage (in German Language)
 
This example program will capture the video and audio stream from a Logitech QuickCam Pro 3000 USB camera for 10 seconds and stores it on a file, named "testcam.avi". You can later use the microsoft windows media player to display this file. 100% written in Java, using the media framework library (JMF) from Sun. Tested on Windows 2000. With some minor modifications, this programm will also work for any other USB cameras.
 
Purpose / Benefits Why I've done this Download Source
TestQuickCamPro.java
MyDataSinkListener.java
DeviceInfo.java
Stdout.java
 
Download Compiled Classes
TestQuickCamPro.class
MyDataSinkListener.class
DeviceInfo.class
Stdout.class
 

Operating System: Windows 2000 or Windows XP
Required Hardware: Logitech QuickCam Pro 3000 / ... or any other USB camera
Required Software: jdk 1.3 or jdk 1.4 plus jmf2.1.1 and (Logitech) camera drives
 
You can just start this program with   java TestQuickCamPro
 
Console Output:

get list of all media devices ...
>>> capture video device = vfw:Logitech USB Video Camera:0
>>> capture video format = size=176x144, encoding=yuv, maxdatalength=38016
>>> capture audio device = DirectSoundCapture
>>> capture audio format = linear, 16000.0 hz, 8-bit, mono, unsigned
... list completed.
starting capturing ...
... capturing done
datasink: ... end of stream reached.
Please make shure that you setup first the camerea drives and jmf2.1.1 correctly.
"jmf.jar" must be part of your CLASSPATH.
 
And here is also a test video, recorded by this program, "testcam.avi".
If you dont' hear any audio, then you should update your windows media player to version 7.* or higher.

Test Video: testcam.avi  
 
 
Configuration Hint: perhaps you need a small change of the capture device. On my XP system
I had to run again the JMF Registry Editor with "Detect Capture Devices" to make the
"DirectSoundCapture" device available. You must set JMF_HOME to the JMF installation directory
before you start the JMF Registry Editor. The Device "vfw:Logitech USB Video Camera" is still
not here but can be replaced by the "Microsoft WDM Image Capture":
 
JMF Registry Editor
 

String defaultVideoDeviceName = "Microsoft WDM Image Capture";
String defaultAudioDeviceName = "DirectSoundCapture";
String defaultVideoFormatString = "size=176x144, encoding=yuv, maxdatalength=38016";
String defaultAudioFormatString = "linear, 16000.0 hz, 8-bit, mono, unsigned";


 
How to Modify the Input Devices or the Resoultion ?
 
1.) Start the program first with no modifications, using the debug flag as argument:
 
java TestQuickCamPro -dd
 
... and you will get an list of all video devices, audio devices and the supported formats:

get list of all media devices ...
device 0: vfw:Logitech USB Video Camera:0
>>> capture video device = vfw:Logitech USB Video Camera:0
 - format: size=640x480, encoding=rgb, maxdatalength=921600
 - format: size=160x120, encoding=rgb, maxdatalength=57600
 - format: size=176x144, encoding=rgb, maxdatalength=76032
 - format: size=320x240, encoding=rgb, maxdatalength=230400
 - format: size=352x288, encoding=rgb, maxdatalength=304128
 - format: size=160x120, encoding=yuv, maxdatalength=28800
>>> capture video format = size=176x144, encoding=yuv, maxdatalength=38016
 - format: size=176x144, encoding=yuv, maxdatalength=38016
 - format: size=320x240, encoding=yuv, maxdatalength=115200
 - format: size=352x288, encoding=yuv, maxdatalength=152064
 - format: size=640x480, encoding=yuv, maxdatalength=460800
device 1: vfw:Microsoft WDM Image Capture (Win32):1
 - format: size=640x480, encoding=yuv, maxdatalength=460800
 - format: size=160x120, encoding=rgb, maxdatalength=57600
 - format: size=176x144, encoding=rgb, maxdatalength=76032
 - format: size=320x240, encoding=rgb, maxdatalength=230400
 - format: size=352x288, encoding=rgb, maxdatalength=304128
 - format: size=640x480, encoding=rgb, maxdatalength=921600
 - format: size=160x120, encoding=yuv, maxdatalength=28800
 - format: size=176x144, encoding=yuv, maxdatalength=38016
 - format: size=320x240, encoding=yuv, maxdatalength=115200
 - format: size=352x288, encoding=yuv, maxdatalength=152064
device 2: DirectSoundCapture
>>> capture audio device = DirectSoundCapture
 - format: linear, 48000.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 48000.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 48000.0 hz, 8-bit, stereo, unsigned
 - format: linear, 48000.0 hz, 8-bit, mono, unsigned
 - format: linear, 44100.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 44100.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 44100.0 hz, 8-bit, stereo, unsigned
 - format: linear, 44100.0 hz, 8-bit, mono, unsigned
 - format: linear, 32000.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 32000.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 32000.0 hz, 8-bit, stereo, unsigned
 - format: linear, 32000.0 hz, 8-bit, mono, unsigned
 - format: linear, 22050.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 22050.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 22050.0 hz, 8-bit, stereo, unsigned
 - format: linear, 22050.0 hz, 8-bit, mono, unsigned
 - format: linear, 16000.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 16000.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 16000.0 hz, 8-bit, stereo, unsigned
>>> capture audio format = linear, 16000.0 hz, 8-bit, mono, unsigned
 - format: linear, 16000.0 hz, 8-bit, mono, unsigned
 - format: linear, 11025.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 11025.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 11025.0 hz, 8-bit, stereo, unsigned
 - format: linear, 11025.0 hz, 8-bit, mono, unsigned
 - format: linear, 8000.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 8000.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 8000.0 hz, 8-bit, stereo, unsigned
 - format: linear, 8000.0 hz, 8-bit, mono, unsigned
device 3: JavaSound audio capture
 - format: linear, 44100.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 44100.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 22050.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 22050.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 11025.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 11025.0 hz, 16-bit, mono, littleendian, signed
 - format: linear, 8000.0 hz, 16-bit, stereo, littleendian, signed
 - format: linear, 8000.0 hz, 16-bit, mono, littleendian, signed
... list completed.
 
 
2.) Modify now the sourcecode of TestQuickCamPro.java on line 43 up to line 46:
 

43: private static String defaultVideoDeviceName = "Logitech USB Video Camera";
44: private static String defaultAudioDeviceName = "DirectSoundCapture";
45: private static String defaultVideoFormatString = "size=176x144, encoding=yuv, maxdatalength=38016";
46: private static String defaultAudioFormatString = "linear, 16000.0 hz, 8-bit, mono, unsigned";
Hint: do not include "device n:" in the device string nor "-format:" in the format string.
 
 
3.) Recompile TestQuickCamPro.java and run it with no debug flag
 
javac TestQuickCamPro.java
java TestQuickCamPro
 
If all works successfull, you will see an output like this:

get list of all media devices ...
>>> capture video device = vfw:Logitech USB Video Camera:0
>>> capture video format = size=176x144, encoding=yuv, maxdatalength=38016
>>> capture audio device = DirectSoundCapture
>>> capture audio format = linear, 16000.0 hz, 8-bit, mono, unsigned
... list completed.
starting capturing ...
... capturing done
datasink: ... end of stream reached.
 
Between "starting capturing ..." and "... capturing done" there is an 10 Seconds delay (Line 241).
During this time-slice the video and audio data will be recorded and stored to the file "testcam.avi".


 
Useful Links
Last updated on 23. Jan 2003
Please send any comments or feedback to fischer@d-fischer.com
David Fischer, Switzerland, Bern

About the Author

David Fischer, Bachelor of Sience I have worked many years as programmer, system architect, consultant and project leader.

My preferred work is technical trouble shooting, IT security consulting and web application tuning.

I have also written a (commercial) Java web stress test product: http://www.proxy-sniffer.com. So if you are interested on a high quality and cheap web stress test tool you can download the evaluation version from this pages.


 

....and just for fun...
Undocumented and unsupported example to turn your logitech camera to a real, http webcam with a permanet video stream. You must be an expert in java to make any modifications on the code. The documentation is incomplete. Try this example only if you have already some (successful) experiences with JMF. AT THE MOMENT I HAVE NO TIME TO GIVE ANY SUPPORT FOR IT. You may download it here. You must modify the file "StartServer.bat". Then try to access it with the browser on http://127.0.0.1:81. Take into consideration that if you do any code modifications you must compile the applet with JDK 1.1 (not with a higher version, because this is a compatibility bug of sun), but that you should compile the server (all other classes) with Java SDK 1.3 or 1.4.

Video Applet in Action        Video to Applet Architecture

 

....for java developers...
Here is a really thin, easy and powerfull Java web server - made to extend existing java programms with a web interface. The source is not free, but the usage is free as long you don't redistribute it: http://www.d-fischer.com:83/. Documentation in English and download available.