If this blog helped you in any way, please donate a dollar here

Wednesday, December 21, 2011

Encoding Webcam data in Java

Java is the blue eyed boy of modern society. From Open Source lovers to Oracle, they all love Java. So, apparently, something like capturing data from a webcam and creating a video out if it should be a walk in the walk in the park, right?


Well, in this case, the walk appears to be rather full of potholes! Not only that, the road seems to veer off and disappear at times.


You see, there are various multimedia frameworks available in Java that allow you to capture webcam, but all of them have a JNI interface. This is where things so ugly. On Linux, such specific bits of code rely on Video for Linux (v4l or v4l2) abstractions. On Windows, DirectShow is the way to go.
However, this is not without it's various caveats. On Linux, GStreamer has solved most of today's problems, thus I shall be focusing mainly on Windows here, where DirectShow holds more precedence. Here's a small list of some Multi-media frameworks that offer a ray of hope into this task.


Name
URL
JMF  http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html  
lti-civil  http://lti-civil.org/  
FMJ  http://fmj-sf.net/
JMyron  http://webcamxtra.sourceforge.net/
DirectShow Java*  http://www.humatic.de/htools/dsj.htm
Xuggler  http://www.xuggle.com/xuggler/


Among the above, the best experience can be achieved from Xuggler. Don't be fooled by the name, it is a powerful media framework and relies on libavdevice drivers to read webcam data. It works fine on both 32-bit and 64-bit Operating Systems.[1]


However, there's a piece of code, nicely integrated into Jitsi (formerly SIP-Communicator) that meets all requirements of an ideal piece of Webcam Encoding Library. It has the class name of jdirectshow and as the name suggests, it uses DirectShow with JNI bindings. The class is named net.java.sip.communicator.impl.neomedia.directshow.


I observed the best performance from this particular piece of Library code.


* : Windows only
1 : I Checked it on Windows XP 32-bit and Windows 7 Home Premium on a Corei5 x64 processor.


NB: If you are aware of any other media framework that does this, please feel free to share your comment!

No comments:

Post a Comment