toxi.video.capture
Class JMFSimpleCapture

java.lang.Object
  extended by toxi.video.capture.JMFSimpleCapture
All Implemented Interfaces:
SimpleCapture

public class JMFSimpleCapture
extends java.lang.Object
implements SimpleCapture

JMFSimpleCapture is a implementation of the SimpleCapture interface using Sun's Java Media Framework. It came about as hopefully slightly more robust alternative to the the QT4Java approach of the existing Processing Capture class, though so far has only been tested under Windows and with a small set of camera models. Since meanwhile JMF is an unmaintained product, there might be major issues with newer cameras and/or larger capture sizes. I wrote this code for a particular project and I had a good user experience with the underlying technology.

Version:
0.4
Author:
Karsten Schmidt < i n f o [ a t ] t o x i . co . u k >

Constructor Summary
JMFSimpleCapture()
           
 
Method Summary
 java.lang.String getError()
          String description of an error occured previously.
 processing.core.PImage getFrame()
          Reads the current frame from the internal video capture and converts it into a PImage object
 int getHeight()
          Retrieves the pixel height of the capture instance
 int getWidth()
          Retrieves the pixel width of the capture instance
 boolean initVideo(java.lang.String deviceID, int width, int height, int fps)
          Initializes video capture for the given device.
static void listDeviceFormats(java.io.PrintStream ps, java.lang.String deviceID)
          Prints all available capture formats of the given device to a PrintStream
static void listDeviceFormats(java.lang.String deviceID)
          Prints all available capture formats of the given device to the console
static void listDevices()
          Lists all connected capture devices to the console
static void listDevices(java.io.PrintStream ps, boolean showFormats)
          Writes details of all connected capture devices to the given PrintStream and optionally shows available capture formats too
 void shutdown()
          Handles freeing up any resources used by the SimpleCapture instance
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JMFSimpleCapture

public JMFSimpleCapture()
Method Detail

getError

public java.lang.String getError()
Description copied from interface: SimpleCapture
String description of an error occured previously.

Specified by:
getError in interface SimpleCapture
Returns:
string or null if all is ok

getFrame

public processing.core.PImage getFrame()
Description copied from interface: SimpleCapture
Reads the current frame from the internal video capture and converts it into a PImage object

Specified by:
getFrame in interface SimpleCapture
Returns:
the most recent captured frame as PImage

getHeight

public int getHeight()
Description copied from interface: SimpleCapture
Retrieves the pixel height of the capture instance

Specified by:
getHeight in interface SimpleCapture
Returns:
image height

getWidth

public int getWidth()
Description copied from interface: SimpleCapture
Retrieves the pixel width of the capture instance

Specified by:
getWidth in interface SimpleCapture
Returns:
image width

initVideo

public boolean initVideo(java.lang.String deviceID,
                         int width,
                         int height,
                         int fps)
Initializes video capture for the given device.

IMPORTANT: framerate is currently ignored. The device's default framerate for the chosen resolution is used.

Specified by:
initVideo in interface SimpleCapture
Parameters:
deviceID - device descriptor
width - capture frame width
height - capture frame height
fps - frame rate
Returns:
false, if the device could not be initialized. The exact reason can be found out via getError().
See Also:
SimpleCapture.initVideo(java.lang.String, int, int, int)

listDeviceFormats

public static void listDeviceFormats(java.io.PrintStream ps,
                                     java.lang.String deviceID)
Prints all available capture formats of the given device to a PrintStream

Parameters:
ps - a valid PrintStream instance
deviceID - descriptor string of device

listDeviceFormats

public static void listDeviceFormats(java.lang.String deviceID)
Prints all available capture formats of the given device to the console

Parameters:
deviceID - descriptor string of device

listDevices

public static void listDevices()
Lists all connected capture devices to the console


listDevices

public static void listDevices(java.io.PrintStream ps,
                               boolean showFormats)
Writes details of all connected capture devices to the given PrintStream and optionally shows available capture formats too

Parameters:
ps - a valid PrintStream instance
showFormats - true, if format information is required

shutdown

public void shutdown()
Description copied from interface: SimpleCapture
Handles freeing up any resources used by the SimpleCapture instance

Specified by:
shutdown in interface SimpleCapture