如何使用 Java 自动化视频快照?
下面是我的尝试。不幸的是,seek 命令似乎不起作用,因为无论视频在哪里,[100,100] 处像素的颜色都保持不变。
我需要的是一个可以创建视频快照的应用程序(最好不需要 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();
}
}
输出:
0
0xffffffff
...
640000
0xffffffff
...
670000
0xffffffff