AnandaGowda
AnandaGowda

Reputation: 51

How to extract a frame from video using Java

Is there any solution to "Extract a frame from video file in Java using core library without importing external libraries"?

Say for I saw Image, BufferedStrategy, BufferCapabilities in Java AWT libraries.

Upvotes: 4

Views: 6048

Answers (3)

Smig
Smig

Reputation: 693

According to this answer on another question, you can do that without external libraries by leveraging features of JavaFX.

Quoting original answer below:

You can use the snapshot() of MediaView. First connect a mediaPlayer to a MediaView component, then use mediaPlayer.seek() to seek the video position. And then you can use the following code to extract the image frame:

int width = mediaPlayer.getMedia().getWidth();
int height = mediaPlayer.getMedia().getHeight();
WritableImage wim = new WritableImage(width, height);
MediaView mv = new MediaView();
mv.setFitWidth(width);
mv.setFitHeight(height);
mv.setMediaPlayer(mediaPlayer);
mv.snapshot(null, wim);
try {
    ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", new File("/test.png"));
} catch (Exception s) {
    System.out.println(s);
}

Upvotes: 0

anquegi
anquegi

Reputation: 11522

I think that you should use Xuggler from here or you can find it in maven.

In the github repository is a sample under demos with the file: DecodeAndCaptureFrames.java

Upvotes: 0

Raúl
Raúl

Reputation: 1552

The Java Media Framework API (JMF) enables audio, video and other time-based media operations, without use of any third party library.

Seeking frames inside a movie with JMF.

xuggler is a good third party library, widely used.

Upvotes: 1

Related Questions