com.xuggle.mediatool
Class ToolFactory

Package class diagram package ToolFactory
java.lang.Object
  extended by com.xuggle.mediatool.ToolFactory

public class ToolFactory
extends Object

Start Here -- A Factory for MediaTools, and global settings for the API.

Here's an example of a ToolFactory program that opens up an input media file, transcodes all the media to a new format, while playing the media on your machine:

 IMediaReader reader = ToolFactory.makeReader("input.mpg");
 reader.addListener(ToolFactory.makeViewer(true));
 reader.addListener(ToolFactory.makeWriter("output.flv", reader));
 while (reader.readPacket() == null)
   ;
 


Method Summary
static boolean isTurboCharged()
          Is ToolFactory running in Turbo-Charged mode?
static void main(String[] args)
          A sample program for the ToolFactory.
static IMediaDebugListener makeDebugListener()
          Construct a debug listener which logs all event types.
static IMediaDebugListener makeDebugListener(IMediaDebugListener.Event... events)
          Construct a debug listener with custom set of event types to log.
static IMediaDebugListener makeDebugListener(IMediaDebugListener.Mode mode, IMediaDebugListener.Event... events)
          Construct a debug listener with custom set of event types to log.
static IMediaDebugListener makeDebugListener(String name, IMediaDebugListener.Mode mode, IMediaDebugListener.Event... events)
          Construct a debug listener with custom name and set of event types to log.
static IMediaReader makeReader(IContainer container)
          Create an IMediaReader to reads and dispatches decoded media from a media container for a given source URL.
static IMediaReader makeReader(String url)
          Create an IMediaReader to reads and dispatches decoded media from a media container for a given source URL.
static IMediaViewer makeViewer()
          Construct a default media viewer.
static IMediaViewer makeViewer(boolean showStats)
          Construct a media viewer and optionally show media statistics.
static IMediaViewer makeViewer(boolean showStats, int defaultCloseOperation)
          Construct a media viewer, optionally show media statistics and specify the default frame close behavior.
static IMediaViewer makeViewer(IMediaViewer.Mode mode)
          Construct a media viewer which plays in the specified mode.
static IMediaViewer makeViewer(IMediaViewer.Mode mode, boolean showStats)
          Construct a media viewer which plays in the specified mode and optionally shows media statistics.
static IMediaViewer makeViewer(IMediaViewer.Mode mode, boolean showStats, int defaultCloseOperation)
          Construct a media viewer which plays in the specified mode, optionally shows media statistics and specifies the default frame close behavior.
static IMediaWriter makeWriter(String url)
          Create a MediaWriter which will require subsequent calls to IMediaWriter.addVideoStream(int, int, ICodec, int, int) and/or IMediaWriter.addAudioStream(int, int, ICodec, int, int) to configure the writer.
static IMediaWriter makeWriter(String url, IContainer inputContainer)
          Use a specified IContainer as a source for and meta data about the container and it's streams.
static IMediaWriter makeWriter(String url, IMediaReader reader)
          Use a specified IMediaReader as a source for media data and meta data about the container and it's streams.
static void setTurboCharged(boolean turbo)
          Turns on and off Turbo-Charging for the ToolFactory package.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeReader

public static IMediaReader makeReader(String url)
Create an IMediaReader to reads and dispatches decoded media from a media container for a given source URL.

Parameters:
url - the location of the media content, a file name will also work here
Returns:
An IMediaReader

makeReader

public static IMediaReader makeReader(IContainer container)
Create an IMediaReader to reads and dispatches decoded media from a media container for a given source URL.

Any Xuggler resourced opened by the IMediaReader will be closed by the IMediaReader, however resources opened outside the IMediaReader will not be closed. In short IMediaReader closes what it opens.

Parameters:
container - an already created media container to read data from.

makeWriter

public static IMediaWriter makeWriter(String url,
                                      IMediaReader reader)
Use a specified IMediaReader as a source for media data and meta data about the container and it's streams. The IMediaReader must be configured such that streams will not be dynamically added to the container, which is the default for IMediaReader.

Parameters:
url - the url or filename of the media destination
reader - the media source
Throws:
IllegalArgumentException - if the specified IMediaReader is configure to allow dynamic adding of streams.

makeWriter

public static IMediaWriter makeWriter(String url,
                                      IContainer inputContainer)
Use a specified IContainer as a source for and meta data about the container and it's streams. The IContainer must be configured such that streams will not be dynamically added to the container.

Parameters:
url - the url or filename of the media destination
inputContainer - the source media container which will be queries to determine what streams and media should be added when writing data.
Throws:
IllegalArgumentException - if the specifed IContainer is not a of type READ or is configure to allow dynamic adding of streams.

makeWriter

public static IMediaWriter makeWriter(String url)
Create a MediaWriter which will require subsequent calls to IMediaWriter.addVideoStream(int, int, ICodec, int, int) and/or IMediaWriter.addAudioStream(int, int, ICodec, int, int) to configure the writer. Streams may be added or further configured as needed until the first attempt to write data.

Parameters:
url - the url or filename of the media destination

makeViewer

public static IMediaViewer makeViewer()
Construct a default media viewer.


makeViewer

public static IMediaViewer makeViewer(IMediaViewer.Mode mode)
Construct a media viewer which plays in the specified mode.

Parameters:
mode - the play mode of this viewer

makeViewer

public static IMediaViewer makeViewer(boolean showStats)
Construct a media viewer and optionally show media statistics.

Parameters:
showStats - display media statistics

makeViewer

public static IMediaViewer makeViewer(IMediaViewer.Mode mode,
                                      boolean showStats)
Construct a media viewer which plays in the specified mode and optionally shows media statistics.

Parameters:
mode - the play mode of this viewer
showStats - display media statistics

makeViewer

public static IMediaViewer makeViewer(boolean showStats,
                                      int defaultCloseOperation)
Construct a media viewer, optionally show media statistics and specify the default frame close behavior.

Parameters:
showStats - display media statistics
defaultCloseOperation - what should Swing do if the window is closed. See the WindowConstants documentation for valid values.

makeViewer

public static IMediaViewer makeViewer(IMediaViewer.Mode mode,
                                      boolean showStats,
                                      int defaultCloseOperation)
Construct a media viewer which plays in the specified mode, optionally shows media statistics and specifies the default frame close behavior.

Parameters:
mode - the play mode of this viewer
showStats - display media statistics
defaultCloseOperation - what should Swing do if the window is closed. See the WindowConstants documentation for valid values.

makeDebugListener

public static IMediaDebugListener makeDebugListener()
Construct a debug listener which logs all event types.


makeDebugListener

public static IMediaDebugListener makeDebugListener(IMediaDebugListener.Event... events)
Construct a debug listener with custom set of event types to log.

Parameters:
events - the event types which will be logged

makeDebugListener

public static IMediaDebugListener makeDebugListener(IMediaDebugListener.Mode mode,
                                                    IMediaDebugListener.Event... events)
Construct a debug listener with custom set of event types to log.

Parameters:
mode - log mode, see IMediaDebugListener.Mode
events - the event types which will be logged

makeDebugListener

public static IMediaDebugListener makeDebugListener(String name,
                                                    IMediaDebugListener.Mode mode,
                                                    IMediaDebugListener.Event... events)
Construct a debug listener with custom name and set of event types to log.

Parameters:
name - symbolic name for this listener
mode - log mode, see IMediaDebugListener.Mode
events - the event types which will be logged

main

public static void main(String[] args)
A sample program for the ToolFactory. If given one argument on the command line, it will interpret that as a media file to read and play. If given more than one, it will attempt to transcode the first file into formats guessed for all the other arguments.

For example, this decodes and plays "input.flv", while transcoding "input.flv" into "output1.mov" and "output2.mp4"

 com.xuggle.mediatool.ToolFactory input.flv output1.mov output2.mp4
 

Parameters:
args - input filename and option output filenames

setTurboCharged

public static void setTurboCharged(boolean turbo)
Turns on and off Turbo-Charging for the ToolFactory package.

Turbo-Charging is off by default.

When running Turbo-Charged ToolFactory will make a variety of tuning assumptions that can speed up execution of your program, sometimes by significant amounts. ToolFactory was designed from the ground up to run Turbo-Charged, but it can cause issues for other com.xuggle.xuggler-based programs running in the same Java process.

It is safe to turn on if your program only uses interfaces in the com.xuggle.mediatool API, and you are not running in the same Java process as other programs using the com.xuggle.xuggler API.

If you turn on Turbo-Charging and then access any of the underlying com.xuggle.xuggler interfaces (e.g. IMediaCoder.getContainer()) behind ToolFactory, you must:

Failure to follow these rules could lead to OutOfMemoryError errors, or to premature releasing of resources.

Turbo-Charging works by changing the global JNIMemoryManager.MemoryModel that the underlying com.xuggle.xuggler API in your program is using. If you are using ToolFactory in a java program that contains other code using the com.xuggle.xuggler API, you will force that code to use the new memory model.

Turbo-Charging should not be used by pregnant women.

Badgers considering Turbo-Charging should check burrows for at least three feet of vertical clearance.

Turbo-Charging Java Programs should be given at least 2-weeks of vacation per year in order to adequately recover from the Turbo-Charging experience.

Turbo-Charging is illegal without a license in British Columbia. Contact the Royal Canadian Mounted Police.

Writing documentation about Turbo-Charging may lead to excessive stupidity. Limiting documentation to four warnings or fewer is strongly recommended.

Parameters:
turbo - should we turn on turbo mode
See Also:
JNIMemoryManager.setMemoryModel(com.xuggle.ferry.JNIMemoryManager.MemoryModel)

isTurboCharged

public static boolean isTurboCharged()
Is ToolFactory running in Turbo-Charged mode?

Returns:
true if Turbo-Charged. false if really just slogging along and finding its own way.


Copyright © 2008, 2010 Xuggle