David Fischer's Java Programming Examples: Capture Video from Logitech QuickCam Pro 3000 Camera with Java JMF |
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
- 100% Java.
- Non Windows/GUI based program ->> command line utility.
- May be used together with a scheduler and a local webserver to publish periodically live video fragments on the internet.
- Easy sourcecode and easy to understand: you may make your own modifications in a short time.
- No "non interactive" utility shipped from Logitech together with the camera that does an easy job like this.
- In opposite to a webcam with a built in webserver, USB cameras are still "stupid" devices.
There is a need of an utility to publish data on the internet without third party services. - JMF examples from Sun didn't work on my environment: JMStudio frozen and/or video data corrupted.
- I was interested to know if it's possible to access the camera from a java program.
- No java sourcecode examples found somewhere on the internet at current time (except these ones from sun).
Does somebody use JMF ???
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. |
"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.
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":
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"; |
- Line 43: set a valid video device (based on the output "device n:")
- Line 44: set a valid audio device (based on the output "device n:")
- Line 45: set a valid video format of the device (based on the output "-format:")
- Line 46: set a valid audio format of the device (based on the output "-format:")
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
- Java Media Framework Homepage from Sun (free download of JMF)
- Java Media Framework Programming Examples from Sun
- Sun's central Java Homepage (free download of Java SDK)
- Logitech Homepage
- Logitech QuickCam Drivers Download
- Logitech QuickCam SDK / Development Kit. Free but needs registration (if you hate Java and prefer MS Visual C++ !?)
Last updated on 23. Jan 2003
Please send any comments or feedback to fischer@d-fischer.com
David Fischer, Switzerland, Bern
About the Author
|
....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. See the webcam in action.
....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.
'JAVA' 카테고리의 다른 글
JAVA 에서 Excel 파일 다루기 (0) | 2008.11.19 |
---|