question to JMF FrameGrabbing
hi @all,
i want to write a program which grab EVRY frame in a Stream i used the frame grabbin contol for it, an go always 1 step forward, but when i grab the frame i grabs many times the fitst frame than many times the 30 frame and so on. in the api stands following:
"If the Player or Renderer is in the Started state, the exact frame returned is not well-defined. "
I think thats my problem because the current media time goes on with the right steps.
How can i gurantee that the renderer is in the correct state, or can i
somehow else solve the problem.
I would be real thankful for your help.
Hi, thanks for your reply, the source is the follow:
public class VideoToFrameSequenceConverter extends javax.swing.JPanel implements ControllerListener, java.lang.Runnable {
private Player player;
private javax.media.control.FrameGrabbingControl grabber;
private javax.media.control.FramePositioningControl posCon;
private javax.media.util.BufferToImage bti;
private javax.media.Buffer buffer;
private int framePosition = 0;
private boolean firstTime = true;
private boolean endReached = false;
private java.lang.Thread thread;
private double endTimeSeconds;
public VideoToFrameSequenceConverter(java.lang.String source) {
Manager.setHint(Manager.PLUGIN_PLAYER, new Boolean(true));
try {
player = Manager.createPlayer(new URL("file:///" + source));
}
catch (javax.media.NoPlayerException e) {
e.printStackTrace();
}
catch (java.io.IOException e) {
e.printStackTrace();
}
player.addControllerListener(this);
player.realize();
player.prefetch();
thread = new java.lang.Thread(this);
}
public void stopConversionThread() {
try {
thread.interrupt();
thread.join();
}
catch (java.lang.InterruptedException e) {
}
}
public void run() {
java.awt.image.BufferedImage picture;
while (!endReached) {
if (posCon != null && grabber != null) {
if (player.getMediaTime().getSeconds() <= endTimeSeconds) {
buffer = grabber.grabFrame();
if (buffer != null) {
bti = new javax.media.util.BufferToImage( (javax.media.format.VideoFormat) buffer.getFormat());
picture = (java.awt.image.BufferedImage) bti.createImage(buffer);
framePosition++;
java.io.File f = new java.io.File("c:/test/frame" + framePosition +".jpg");
try {
javax.imageio.ImageIO.write(picture, "jpeg", f);
}
catch (java.lang.Exception e) {
}
System.out.println("Skiped: " + posCon.skip(1));
}
}
else {
endReached = true;
stopConversionThread();
}
}
}
}
public void controllerUpdate(ControllerEvent event) {
if (event instanceof javax.media.PrefetchCompleteEvent) {
posCon = (javax.media.control.FramePositioningControl) player.getControl("javax.media.control.FramePositioningControl");
grabber = (javax.media.control.FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
endTimeSeconds = player.getDuration().getSeconds();
if (firstTime) {
thread.start();
firstTime = false;
}
}
}
}
I start the process from the main program with VideoToFrameSequenceConverter p = new VideoToFrameSequenceConverter ("test.mpg");