Can not acces frame grabber

I am attempting to read an MPEG video and to grab each individual frame so that I can used pixel data within my program.

I can create a player/processor for the video. I get the format control, the frame positiong control, butNOT the frame grabbing control.

Why can I not access the frame grabbing control. How do I gain access to this control. Help...

My current source coude looks like the following:

package TestIt;

import java.io.IOException;

import java.awt.*;

import java.net.URL;

import javax.media.*;

import javax.media.control.*;

import javax.media.format.*;

import javax.media.protocol.*;

import javax.media.rtp.*;

publicclass TestItimplements ControllerListener

{

public TestIt()

{

this.processor =null;

}

publicvoid run()

{

// Define data source location

String dataLocation ="file:///D:/VideoData/clip_8.mpg";

// Create media locator

MediaLocator mediaLocator =new MediaLocator(dataLocation);

if(mediaLocator ==null)

{

System.out.println("Did not create media locator");

System.exit(0);

}

// Create data source

DataSource dataSource =null;

try

{

dataSource = Manager.createDataSource(mediaLocator);

}

catch(Exception exception)

{

System.out.println("Cannot create data source: " +

exception.getMessage());

System.exit(0);

}

// Data source characteristics

if(dataSourceinstanceof PullBufferDataSource)

{

System.out.println("Data Source Type: PullBufferDataSource");

}

elseif(dataSourceinstanceof PullDataSource)

{

System.out.println("Data Source Type: PullDataSource");

}

elseif(dataSourceinstanceof PushBufferDataSource)

{

System.out.println("Data Source Type: PushBufferDataSource");

}

elseif(dataSourceinstanceof PushDataSource)

{

System.out.println("Data Source Type: PushDataSource");

}

System.out.println("Content Type: " + dataSource.getContentType());

// Create a playert/processor

try

{

this.processor = Manager.createProcessor(dataSource);

}

catch(Exception exception)

{

System.out.println("Cannot create player/processor: " +

exception.getMessage());

}

this.processor.addControllerListener(this);

// Put player/processor in configured state

this.processor.configure();

// Put player/processor in realize state

this.processor.realize();

}

publicvoid controllerUpdate(ControllerEvent theEvent)

{

System.out.println("Received: Controller Event: " + theEvent.toString());

if(theEventinstanceof TransitionEvent)

{

System.out.println("Type: TransitionEvent");

if(theEventinstanceof ConfigureCompleteEvent)

{

System.out.println("Sub-Type: ConfigureCompleteEvent");

}

elseif(theEventinstanceof RealizeCompleteEvent)

{

System.out.println("Sub-Type: RealizeCompleteEvent");

// Some Player characteristic

System.out.println("Duration: " +

this.processor.getDuration().getSeconds());

// Get format control

this.formatControl = (FormatControl) this.processor.getControl(

"javax.media.control.FormatControl");

if(this.formatControl ==null)

{

System.out.println("Cannot get Format Control");

}

Format format = this.formatControl.getFormat();

System.out.println("Encoding: " + format.getEncoding());

if(formatinstanceof VideoFormat)

{

VideoFormat videoFormat = (VideoFormat) format;

System.out.println("Frame Rate: " +

videoFormat.getFrameRate());

System.out.println("Maximum Data Length: " +

videoFormat.getMaxDataLength());

Dimension dimension = videoFormat.getSize();

System.out.println("Width: " + dimension.getWidth());

System.out.println("Height: " + dimension.getHeight());

}

// Get frame positioning control

this.framePositioningControl =

(FramePositioningControl) this.processor.getControl(

"javax.media.control.FramePositioningControl");

if(this.framePositioningControl ==null)

{

System.out.println("Cannot get Frame Positioning Control");

}

// Get frame grabbingr control

this.frameGrabbingControl =

(FrameGrabbingControl) this.processor.getControl(

"javax.media.control.FrameGrabbingControl");

if(this.frameGrabbingControl ==null)

{

System.out.println("Cannot get Frame Grabbing Control");

}

}

}

}

// Attributes

Processor processor;

FormatControl formatControl;

FramePositioningControl framePositioningControl;

FrameGrabbingControl frameGrabbingControl;

publicstaticvoid main(String[] thArgs)

{

TestIt testIt =new TestIt();

testIt.run();

}

}

[9059 byte] By [kootera] at [2007-11-26 16:33:45]
# 1
I think you may need to set the format you want from the processor before you realize itMessage was edited by: Stefan_Maric
Stefan_Marica at 2007-7-8 22:58:29 > top of Java-index,Security,Cryptography...
# 2

From the JMF Javadocs

public interface FrameGrabbingControl

extends Control

The FrameGrabbingControl is the interface to grab a still video frame from the video stream. This control can be exported by a Renderer or a Player via the getControl method.

FrameGrabbingControl MUST be obtained from a PLAYER not a PROCESSOR

Have re-worked one of my JMF Apps to contain the following

Player p = cP.getPlayer();

Control c = p.getControl("javax.media.control.FrameGrabbingControl");

if(c instanceof FrameGrabbingControl){

System.out.println("Got Frame Grabbing Control");

}

No error / No null pointer

will add a bit more code to obtain an image from a buffer

Stefan_Marica at 2007-7-8 22:58:29 > top of Java-index,Security,Cryptography...
# 3

I switch my processor to a player and reran my test. I still could not get the frame grabbing control. I also now could not get the frame positioning control. The JavaDoc snippit from Stefan_Maric is useful, however it states the control can be exported, not will be exported. I believe what is happening is that the plugin used by the player does not support the frame grabbbbing control or frame positioning control. Therefore this does not work for me. Maybe I am wrong in this belief.

I am goung to try a different approach where I create a codec to be programmed into a processor.Any other input for how to access individual frame would be most welcome.

worzela at 2007-7-8 22:58:29 > top of Java-index,Security,Cryptography...
# 4

The following seems to basically work

private void processGrabFrame(CameraPanel cP) throws Exception{

Player p = cP.getPlayer();

Control c = p.getControl("javax.media.control.FrameGrabbingControl");

if(c instanceof FrameGrabbingControl){

System.out.println("Got Frame Grabbing Control");

FrameGrabbingControl fGC = (FrameGrabbingControl)c;

Buffer buf = fGC.grabFrame();

FormatControl fC = FormatControl)p.getControl("javax.media.control.FormatControl");

VideoFormat vF = (VideoFormat)fC.getFormat();

BufferToImage bufToI = new BufferToImage(vF);

new ShowImage(bufToI.createImage(buf));

}

}

// Not pretty - but seems to work

public class ShowImage extends JFrame{

private Container cont;

private Image image;

private JPanel jPMain;

private JButton jBImage;

public ShowImage(Image img){

super("Frame Grabber");

image = img;

cont = getContentPane();

jPMain = new JPanel();

jBImage = new JButton("Image Goes here");

jBImage.setIcon(new ImageIcon(img));

jPMain.add(jBImage);

cont.add(jPMain);

setVisible(true);

System.out.println("ShowImage");

}

}

Stefan_Marica at 2007-7-8 22:58:29 > top of Java-index,Security,Cryptography...