4

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,250
  • 1
  • 16
  • 36
AnandaGowda
  • 51
  • 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,542
  • 4
  • 24
  • 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,701
  • 3
  • 35
  • 50
anquegi
  • 11,125
  • 4
  • 51
  • 67
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