Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best approach for extract / extracting images / image sequence from videos / video file in Java

Well, there is FFMPEG and some Java bindings and wrappers for it but I need to distribute for each specific platform the right binary file of FFMPEG.

Isnt there any plain Java solution or library without any dependencies like FFMPEG for converting a video fle to an image sequence?

Solutions like FFMPEG, XUGGLER or JMF (abandoned) are not suitable. Is there really no pure Java solution for this?

Maybe for specific video codecs / files at least?

I just want to extract the images from the video file to jpeg / png files and save them to the disk

like image 342
Daniel Ruf Avatar asked Dec 27 '12 15:12

Daniel Ruf


2 Answers

Is there really no pure Java solution for [extracting images from a video stream]?

Let's see. You have to:

  • Decode the video.
  • Present the decoded images at least as fast as 24 images / second. I suppose you can skip this step.
  • Save the decoded images.

It appears that decoding the video would be the most challenging step. People and companies have spent years developing codecs (encoder / decoder) for various video formats.

There's a project on SourceForge, JMF wrapper for ffmpeg, that has developed a few pure Java video codecs. Perhaps you can look at their source code and see how to develop a Java video codec for yourself.

You can look for other pure Java video codecs if you wish.

like image 136
Gilbert Le Blanc Avatar answered Sep 21 '22 13:09

Gilbert Le Blanc


There is a pure Java implementation of the following codecs: H.264 ( AVC ), MPEG 1/2, Apple ProRes, JPEG; and the following file formats: MP4 ( ISO BMF, QuickTime ), Matroska, MPEG PS and MPEG TS.
The library is called JCodec ( http://www.jcodec.org ).
It has very little documentation for now but the development team is constantly working on this.
Here's how you can simply grab a frame from an MP4 file ( sample from their web site ):

int frameNumber = 150;
BufferedImage frame = FrameGrab.getFrame(new File("filename.mp4"), frameNumber);
ImageIO.write(frame, "png", new File("frame_150.png"));

To add JCodec to your project you can simply add below to your pom.xml:

<dependency>
    <groupId>org.jcodec</groupId>
    <artifactId>jcodec</artifactId>
    <version>0.1.3</version>
</dependency>

For latest version, see here.

like image 26
Stanislav Vitvitskyy Avatar answered Sep 19 '22 13:09

Stanislav Vitvitskyy