How can I use Java to automate video snapshots?
Below is my attempt. Unfortunately, the seek command seems does not work since the color of the pixel at [100,100] remains still the same no matter where the video is.
What would I need is an app that would create snapshots of video (preferably without the need of GUI).
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.WritableImage;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;
public class VideoController extends Application {
private MediaPlayer media;
int posun = 100; // milisecs
int pocatek = 0; // milisecs
Duration cas = new Duration(0);
@Override
public void start(Stage scene) throws Exception {
String uri = "http://download.oracle.com/otndocs/products/javafx/arth_512.flv";
final Media medium = new Media(uri);
media = new MediaPlayer(medium);
final MediaView video = new MediaView(media);
// videoPane.getChildren().add(video);
media.setOnReady(new Runnable() {
@Override
public void run() {
media.play();
for (int i = pocatek; i < (int) medium.getDuration().toMillis(); i += posun) {
System.out.println(i);
cas = new Duration(i);
media.seek(cas);
WritableImage wi = new WritableImage(1000, 1000);
video.snapshot(new SnapshotParameters(), wi);
Color c = wi.getPixelReader().getColor(100, 100);
System.out.println(c);
// video.snapshot(params, image);
}
}
});
}
public static void main(String[] args) {
launch();
}
}
OUTPUT:
0
0xffffffff
...
640000
0xffffffff
...
670000
0xffffffff
There is not recommended to use JAVAFX for this task. Much better solution is to use XUGGLER. The exact case is described in this tutorial:
http://www.javacodegeeks.com/2011/02/xuggler-tutorial-frames-capture-video.html