3

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.

Shrikant Havale
  • 1,190
  • 1
  • 15
  • 34
AnandaGowda
  • 41
  • 1
  • 4

3 Answers3

1

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.

Raúl
  • 1,532
  • 4
  • 23
  • 37
0

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

icedwater
  • 4,472
  • 3
  • 33
  • 47
anquegi
  • 10,506
  • 3
  • 46
  • 62
0

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);
}
Smig
  • 683
  • 6
  • 17