Automate Video Snapshots

1

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
java
javafx-2
video-capture
snapshot
asked on Stack Overflow Dec 3, 2012 by Radim Burget • edited Dec 3, 2012 by Mike G

3 Answers

1

I don't think it's possible. FX media API is oriented to playback not data manipulation, you can't easily load picture data without actual media on screen.

Given you don't want UI there is no actual work for FX and you may want to solve your task by other tools, e.g. ffmpeg, see ffmpeg to get screenshot

answered on Stack Overflow Dec 3, 2012 by Sergey Grinev • edited May 23, 2017 by Community
0

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

answered on Stack Overflow Dec 25, 2012 by Radim Burget
0
  1. Create a mediaView : new MediaView(mediaplayer)

  2. use the current time property and add a change listener **:every time that the playing duration has been changed the listener will be called

  3. inside this listener , we are going to take snapshots of the mediaView.
    Exemple

        player.currentTimeProperty().addListener(new ChangeListener<Duration>() {
        @Override
        public void changed(ObservableValue<? extends Duration> arg0, Duration arg1, Duration arg2) {
            // TODO Auto-generated method stub
    
            WritableImage write = new WritableImage(media.getWidth(),media.getHeight());
            mview.snapshot(new SnapshotParameters(),write);
            //Now Write is Your current image 
    
        }
    });
    
answered on Stack Overflow Oct 12, 2020 by user12179366

User contributions licensed under CC BY-SA 3.0