}
}
}
};
Processor processor = null;
DataSink dataSink = null;
try {
processor = Manager.createProcessor(dataSource);
processor.addControllerListener(controllerListener);
processor.configure();
// Put the Processor into configured state so we can set
// some processing options on the processor.
if (!waitForState(processor, Processor.Configured)) {
throw new IOException("Failed to configure the processor.");
}
// Set the output content descriptor to QuickTime.
processor.setContentDescriptor(new ContentDescriptor(FileTypeDescriptor.QUICKTIME));
// Query for the processor for supported formats.
// Then set it on the processor.
TrackControl trackControls[] = processor.getTrackControls();
Format format[] = trackControls [0].getSupportedFormats();
if (format == null || format.length <= 0) {
throw new IOException("The mux does not support the input format: " + trackControls [0].getFormat());
}
trackControls [0].setFormat(format [0]);
// We are done with programming the processor. Let's just realize it.
processor.realize();
if (!waitForState(processor, Controller.Realized)) {
throw new IOException("Failed to realize the processor.");
}
// Now, we'll need to create a DataSink.
// Caution: do not use file.toURI().toURL() with JMF
dataSink = Manager.createDataSink(processor.getDataOutput(),
new MediaLocator(file.toURL()));
dataSink.open();
dataSink.addDataSinkListener(dataSinkListener);
this.fileDone = false;
// Start the actual transcoding
processor.start();
dataSink.start();
// Wait for EndOfStream event.
synchronized (this.waitFileSync) {
while (!this.fileDone) {
this.waitFileSync.wait();
}
}
if (this.fileError != null) {
throw new IOException(this.fileError);
}
} catch (NoProcessorException ex) {
IOException ex2 = new IOException(ex.getMessage());
ex2.initCause(ex);
throw ex2;
} catch (NoDataSinkException ex) {
IOException ex2 = new IOException("Failed to create a DataSink for the given output MediaLocator");
ex2.initCause(ex);
throw ex2;
} catch (InterruptedException ex) {
if (dataSink != null) {
dataSink.stop();
}
throw new InterruptedIOException("Video creation interrupted");
} finally {
if (dataSink != null) {
dataSink.close();
dataSink.removeDataSinkListener(dataSinkListener);
}
if (processor != null) {
processor.close();
processor.removeControllerListener(controllerListener);
}