Skip to content

Image Capture With Java Media Framework

Introduction

The Java™ Media Framework is a framework for handling streaming media (video/audio) using the Java™ programming language. This framework allows us to acquire, process and deliver multimedia content from a variety of sources. A part this framework provides access to image capture using Webcams (internal or external).

Installation

The installation downloads are available here

http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html

Windows

The downloads section contains a windows installer (power pack installer) that simplifies the installation process. Default setting will install the library to

“C:\Program Files\JMF2.1.1e” on 32 Bit OS or
“C:\Program Files (x86)\JMF2.1.1e\” on 64 Bit OS

Ubuntu Linux

The download offered (power pack installer) for Linux has a problem which could result in failed installation and a zero sized file replacing the original download file. To overcome this, see this forum post http://ubuntuforums.org/archive/index.php/t-1137722.html. The steps for a successful install are as follows

  1. Download the .bin file from here
  2. Rename the .bin to a .zip and extract the contents
    $ mv jmf-2_1_1e-linux-i586.bin jmf-2_1_1e-linux-i586.zip
    $ unzip jmf-2_1_1e-linux-i586.zip
  3. Rename the .zip file back to .bin
    $ mv jmf-2_1_1e-linux-i586.zip jmf-2_1_1e-linux-i586.bin
  4. add execute permissions
    $ chmod +x jmf-2_1_1e-linux-i586.bin
  5. run the installer
    $ ./jmf-2_1_1e-linux-i586.bin

    The installation should complete successfully.

Configuring the IDE

Netbeans

  1. Open Menu->Tools->Libraries
  2. Click “New Library”
    image
  3. Enter “JMF” as new library name and click “OK”
  4. Click “Add JAR/Folder”
  5. Browse to lib subdirectory in the installation folder:“C:\Program Files\JMF2.1.1e\lib” on 32 Bit OS or
    “C:\Program Files (x86)\JMF2.1.1e\lib” on 64 Bit OSand select all the jar files to add to the library.
  6. Incase you have downloaded the documentation (.zip)select the “Javadoc” tab, Click “Add Zip/Folder”, select the zip file to enable popup help during auto completion.
    image
  7. Click “OK” to save the settings and dismiss the dialog.

Eclipse

  1. Open Menu->Window->Preferences
  2. Select Java->Build Path->User Libraries
    image
  3. Select “New” and enter “JMF” as the name of the library and click “OK”
    image
  4. Select “Add Jars”
  5. Browse to lib subdirectory in the installation folder:“C:\Program Files\JMF2.1.1e\lib” on 32 Bit OS or
    “C:\Program Files (x86)\JMF2.1.1e\lib” on 64 Bit OS
    image
  6. Select All jar files and click “Open” to add the jars to user library.

Writing your first application

Netbeans

  1. Create a new project.
  2. Open “Projects” View.
  3. Right Click “Libraries” folder.
  4. Select “Add Library”.
  5. Select “JMF” library created in previous step.
  6. Click “OK” to add the library reference.
  7. Use the below code to scan for cameras (internal/external)
    
    package testapp;
    
    import java.util.Vector; 
    import javax.media.CaptureDeviceManager; 
    
    public class CaptureDeviceEnumerator
    {
        public static void main(String[] args)
        {
            System.out.println("Scanning for devices ..."); 
            Vector deviceList = CaptureDeviceManager.getDeviceList(null); 
            System.out.format("%1$s devices detected.\n", deviceList.size()); 
            for (Object device : deviceList)
            {
                System.out.println(device);
            }
        }
    }
    
    

Eclipse

  1. Create a new java project
    imageimage
  2. In the java settings page, select the libraries tab and click the “Add Library”
    image
  3. Select the “User Library” option
    image
  4. Select the JMF library and select finish
    image
  5. Add a new class and use the above code to test the library

Conclusion

This post should be able to guide you to download, install, configure and test the JMF library. My next post will be on doing something more useful such as capturing an image and doing some processing.

External References