kig på nedenstående eksempel, og læs i JMF dokumentationen for Java (kan downloades)
public void SaveData()
{
Format formats[] = new Format[2];
formats[0] = new AudioFormat(AudioFormat.IMA4);
formats[1] = new VideoFormat(VideoFormat.CINEPAK);
DataSource source1= null;
DataSink filewriter = null;
FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME);
Processor p = null;
try {
p = Manager.createRealizedProcessor(new ProcessorModel(formats, outputType));
} catch (IOException e) {
System.exit(-1);
} catch (NoProcessorException e) {
System.exit(-1);
} catch (CannotRealizeException e) {
System.exit(-1);
}
System.out.println("...to be starting SaveData()");
source1 = p.getDataOutput();
// create a File protocol MediaLocator with the location of the file to which bits are to be written
MediaLocator dest = new MediaLocator("
file://alarm.mov");
//create a datasink to do the file writing & open the sink to make sure we can write to it.
try {
//System.out.println("filewriter initialiseres...");
filewriter = Manager.createDataSink(source1, dest);
System.out.println("datasink tildelt source og destination");
filewriter.open();
} catch (NoDataSinkException e) {
System.out.println("fejl: NoDataSinkException " + e);
System.exit(-1);
} catch (IOException e) {
System.out.println("fejl: IOException " + e);
System.exit(-1);
} catch (SecurityException e) {
System.out.println("fejl: security exception " + e);
System.exit(-1);
}
// starter filewriter og processor
try {
filewriter.start();
} catch (IOException e) {
System.out.println("fejl ved start af datasink: " + e);
System.exit(-1);
}
System.out.println("Saving VideoData initialized...");
p.start();
for (int i=0;i<40000;i++)
{
System.out.println(i);
}
p.stop();
p.close();
filewriter.close();
}