creating mov files with JMF

hello guys i am making a motion detection and capture program. i managed the detection code... the problem is writing video to a quicktime file. i made a record class which is used to record movie to a file. the recordFile(DataSource ds) in record class is used as the function for recording. I cannot get the thing to record. Can somebody help me. I send the DataSource ds which is the cloned version from the main motionDetection class..... please do help fast guys.

here is the record class

import java.io.*;

import java.util.Date;

import java.awt.Component;

import java.awt.Dimension;

import javax.media.*;

import javax.media.protocol.*;

import javax.media.format.VideoFormat;

import java.net.URL;

import java.net.MalformedURLException;

import javax.media.*;

import javax.media.control.*;

class recordFile {

private DataSource recordCamSource;

private Processor recordProcessor;

MotionDetector dataSource=new MotionDetector();

private DataSink dataSink;

camStateHelper playhelper;

boolean stateTransitionOK = true;

private static MotDetCodec mdCodec;

Object waitSync = new Object();

public recordFile(DataSource recordDataSource){

this.recordCamSource = recordDataSource;

try{

recordProcessor = Manager.createProcessor(recordCamSource);

}catch (IOException e) {

System.out.println("Exception creating processor: ");

}catch (NoProcessorException e) {

System.out.println("Exception creating processor: ");

}

}

public void recordToFile(File file){

URL movieUrl = null;

MediaLocator dest = null;

try{

movieUrl = file.toURL();

dest = new MediaLocator(movieUrl);

}catch(MalformedURLException e){

}

try{

recordProcessor = Manager.createProcessor(recordCamSource);

}catch (IOException e) {

System.out.println("Exception creating record processor: " );

}catch (NoProcessorException e) {

System.out.println("Exception creating record processor: ");

}

recordProcessor.configure();

if ( !waitForState( recordProcessor.Configured ) ) {

System.err.println("Failed to configure the processor.");

System.exit(0);

}

checkIncoding(recordProcessor.getTrackControls());

recordProcessor.setContentDescriptor(null);

if (recordProcessor != null) {

setJPEGQuality(recordProcessor, 1.0f);

recordProcessor.start();

}

VideoFormat vfmt = new VideoFormat(VideoFormat.CINEPAK);

(recordProcessor.getTrackControls())[0].setFormat(vfmt);

(recordProcessor.getTrackControls())[0].setEnabled(true);

recordProcessor.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME));

Control control = recordProcessor.getControl("javax.media.control.FrameRateControl");

if ( control != null && control instanceof javax.media.control.FrameRateControl )

((javax.media.control.FrameRateControl)control).setFrameRate(15.0f);

if(!playhelper.realize(10000)){

System.out.println("cannot realize processor");

}

try {

if(recordProcessor.getDataOutput()==null){

System.out.println("No Data Output");

}

dataSink = Manager.createDataSink(recordProcessor.getDataOutput(), dest);

//recordProcessor.start();

dataSink.open();

dataSink.start();

} catch (NoDataSinkException ex) {

System.out.println(" No DataSink " );

} catch (IOException ex) {

System.out.println("IOException " );

}

}

public void stopRecording(){

try {

recordProcessor.close();

dataSink.stop();

dataSink.close();

} catch (IOException e) {

System.out.println(" cannot stop recording " );

}

}

public void checkIncoding(TrackControl track[]){

for (int i = 0; i < track.length; i++) {

Format format = track.getFormat();

if (track.isEnabled() && format instanceof VideoFormat) {

Dimension size = ((VideoFormat)format).getSize();

float frameRate = ((VideoFormat)format).getFrameRate();

int w = (size.width % 8 == 0 ? size.width :(int)(size.width / 8) * 8);

int h = (size.height % 8 == 0 ? size.height :(int)(size.height / 8) * 8);

VideoFormat jpegFormat = new VideoFormat(

VideoFormat.JPEG_RTP, new Dimension(w, h), Format.NOT_SPECIFIED, Format.byteArray, frameRate);

}

}

}

void setJPEGQuality(Player p, float val) {

Control cs[] = p.getControls();

QualityControl qc = null;

VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);

for (int i = 0; i < cs.length; i++) {

if (cs instanceof QualityControl && cs instanceof Owned) {

Object owner = ((Owned)cs).getOwner();

if (owner instanceof Codec) {

Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);

for (int j = 0; j < fmts.length; j++) {

if (fmts[j].matches(jpegFmt)) {

qc = (QualityControl)cs;

qc.setQuality(val);

break;

}

}

}

if (qc != null) break;

}

}

}

boolean waitForState(int state) {

// waits for a state confirmation for the player

synchronized (waitSync) {

try {

while (recordProcessor.getState() != state && stateTransitionOK)

waitSync.wait();

} catch (Exception e) {}

}

System.out.println("stateTransitionOK");

return stateTransitionOK;

}

public void controllerUpdate(ControllerEvent event) {

// if the playeris dead - we leave

if (recordProcessor == null)

return;

if ( event instanceof ConfigureCompleteEvent ||

event instanceof RealizeCompleteEvent||

event instanceof PrefetchCompleteEvent ) {

synchronized ( waitSync ) {

stateTransitionOK = true;

waitSync.notifyAll();

}

} else if ( event instanceof ResourceUnavailableEvent ) {

synchronized ( waitSync ) {

stateTransitionOK = false;

waitSync.notifyAll();

}

// close the application

} else if ( event instanceof EndOfMediaEvent||

event instanceof ControllerClosedEvent ||

event instanceof ControllerErrorEvent ) {

recordProcessor.close();

System.exit(0);

}

}

}

[6479 byte] By [dare-devila] at [2007-11-27 1:04:48]
# 1
> .... please do help fast guys.> Oh darn, I must be too late by now seeing it was so urgent and all...Ah well, better luck next time.
prometheuzza at 2007-7-11 23:39:54 > top of Java-index,Java Essentials,Java Programming...