Best approach for extracting / extracting images / image sequence from video / video file in Java

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

Is there any simple Java solution or library without any dependencies, such as FFMPEG, to convert a video stream into a sequence of images?

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

Perhaps for certain video codecs / files at least?

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

+6
source share
3 answers

Actually there is no pure Java solution for [extracting images from a video stream]?

We will see. You must:

  • Decode the video.
  • Imagine decoded images of at least 24 images per second. I suppose you can skip this step.
  • Save the decoded images.

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

There is a project on SourceForge, a JMF wrapper for ffmpeg , which developed some clean Java video codecs. Perhaps you can look at the source code and see how to develop a Java video codec for yourself.

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

+3
source

There is a clean 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 ).
He currently has very little documentation, but the development team is constantly working on it.
Here's how you can just grab a frame from an MP4 file (sample from your website):

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 your pom.xml below:

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

For the latest version see here .

+2
source
 import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.concurrent.ExecutionException; import javax.imageio.ImageIO; import org.bytedeco.javacpp.opencv_core.IplImage; import org.bytedeco.javacv.FFmpegFrameGrabber; import org.bytedeco.javacv.FrameGrabber.Exception; public class Read{ public static void main(String []args) throws IOException, Exception, InterruptedException, ExecutionException { FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber("C:/Users/Digilog/Downloads/Test.mp4"); frameGrabber.start(); IplImage i; try { for(int ii=0;ii<frameGrabber.getLengthInFrames();ii++){ i = frameGrabber.grab(); BufferedImage bi = i.getBufferedImage(); String path = "D:/Image/Image"+ii+".png"; ImageIO.write(bi,"png", new File(path)); } frameGrabber.stop(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 
+2
source

All Articles