title: Automate Video Snapshots
body: <p>How can I use Java to automate video snapshots?</p>
  
  <p>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.</p>
  
  <p>What would I need is an app that would create snapshots of video (preferably without the need of GUI).</p>
  
  <pre><code>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 &lt; (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();
      }
  }
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>0
  0xffffffff
  ...
  640000
  0xffffffff
  ...
  670000
  0xffffffff
  </code></pre>