{"id":33,"date":"2011-07-29T15:06:59","date_gmt":"2011-07-29T15:06:59","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/multimedia\/?p=33"},"modified":"2011-07-31T09:43:26","modified_gmt":"2011-07-31T09:43:26","slug":"video-capture-in-openimaj","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/multimedia\/2011\/07\/29\/video-capture-in-openimaj\/","title":{"rendered":"Video Capture in OpenIMAJ"},"content":{"rendered":"<p><a href=\"http:\/\/blog.soton.ac.uk\/multimedia\/files\/2011\/07\/webcams.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-36 align right alignright\" src=\"http:\/\/blog.soton.ac.uk\/multimedia\/files\/2011\/07\/webcams-300x228.png\" alt=\"webcams\" width=\"300\" height=\"228\" srcset=\"https:\/\/blog.soton.ac.uk\/multimedia\/files\/2011\/07\/webcams-300x228.png 300w, https:\/\/blog.soton.ac.uk\/multimedia\/files\/2011\/07\/webcams.png 303w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Video capture from a webcam in Java is one of those things that is supposed to be easy, but isn&#8217;t. There are many libraries out there that try to provide support for video capture, but they all fall short. For example, <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/tech\/index-jsp-140239.html\">JMF<\/a> doesn&#8217;t support capture on a Mac, QuickTime for Java is deprecated and doesn&#8217;t support linux or 64-bit OSX\/Windows, <a href=\"http:\/\/lti-civil.org\/\">lti-civil<\/a> is rather ancient and uses Quicktime for Java on the Mac (deprecated, no 64-bit), and doesn&#8217;t support 64-bit versions of other operating systems.<\/p>\n<p>Our requirements for OpenIMAJ are seemingly rather simple:<\/p>\n<ul>\n<li>List the available video devices<\/li>\n<li>Open a device by name or identifier<\/li>\n<li>Grab images from the device<\/li>\n<li>Close the device<\/li>\n<\/ul>\n<p>In addition, we want to be able to support both 64-bit and 32-bit Java Virtual Machines running under Linux, OSX and Windows, and would rather the user didn&#8217;t have to install anything (i.e. the video capture support must be self-contained in a jar file).<\/p>\n<p>Unfortunately, we were unable to find any existing library that would allow us to do this, so we set about implementing our own capture support. The OpenIMAJ core-video-capture library is a 250kb jar file that fulfils all our requirements.<\/p>\n<p>We constructed the core-video-capture library by writing a small dynamic native library for each platform and architecture (using c++) that exposes functions for the four requirements above. The native library uses the host operating systems current built in video capture framework (DirectShow on Windows, using the videoInput wrapper <a href=\"https:\/\/github.com\/ofTheo\/videoInput\">here<\/a>; QTKit on Mac OSX; v4l2 on Linux). On the Java side we used the excellent <a href=\"http:\/\/code.google.com\/p\/bridj\/\">bridj<\/a> to bind the native code to a Java class. We packaged the native libraries as resources into the library jar. Finally, we added a small bit of static code in the Java class to determine the architecture and operating system, unpack the relevant native library to a temporary location and add it to the bridj library search path. The native library is set to be automatically removed when the JVM terminates.<\/p>\n<p>Developers using core-video-capture should use the <a href=\"http:\/\/www.openimaj.org\/apidocs\/org\/openimaj\/video\/capture\/VideoCapture.html\"><code>org.openimaj.video.capture.VideoCapture<\/code><\/a> class. The <code>org.openimaj.video.capture.OpenIMAJGrabber<\/code> provides a lower-level interface to the native libraries.<\/p>\n<p>Some tutorials using the VideoCapture class can be found on the <a href=\"https:\/\/sourceforge.net\/p\/openimaj\/wiki\/Video%20Processing%20in%20OpenIMAJ\/\">wiki<\/a>. There are also plenty of demos in the demos directory that use live video input.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Video capture from a webcam in Java is one of those things that is supposed to be easy, but isn&#8217;t. There are many libraries out there that try to provide support for video capture, but they all fall short. For example, JMF doesn&#8217;t support capture on a Mac, QuickTime for Java is deprecated and doesn&#8217;t [&hellip;]<\/p>\n","protected":false},"author":189,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15076,52],"tags":[366,15079,15088,15089],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-openimaj","category-software","tag-java","tag-opensource","tag-video-capture","tag-webcam"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/users\/189"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":11,"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":52,"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/posts\/33\/revisions\/52"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/multimedia\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}