How to get the the single images of an mp4-Movie in Java

一曲冷凌霜 提交于 2019-12-03 13:59:19
Jovi Dsilva

you could use jcodec(http://jcodec.org/) in the followinf program i am extracting frames from a video.

/*
 * To extract frames from a mp4(avc) video
 * 
 */
package avc_frame;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.jcodec.api.FrameGrab;
import org.jcodec.api.JCodecException;

public class Avc_frame {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException, JCodecException {

        long time = System.currentTimeMillis();
        for (int i = 50; i < 57; i++) { 
            BufferedImage frame = FrameGrab.getFrame(new File("/Users/jovi/Movies/test.mp4"), i);
            ImageIO.write(frame, "bmp", new File("/Users/jovi/Desktop/frames/frame_"+i+".bmp"));
        }
        System.out.println("Time Used:" + (System.currentTimeMillis() - time)+" Milliseconds");
    }
}
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
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
    {
        FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber("C:/Users/Digilog/Downloads/Test.mp4");
        frameGrabber.start();
        IplImage i;
        try {

            i = frameGrabber.grab();
            BufferedImage  bi = i.getBufferedImage();
            ImageIO.write(bi,"png", new File("D:/Img.png"));
            frameGrabber.stop();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
}

This link might give you some basic idea about how to do. Try this..

http://krishnabhargav.blogspot.in/2008/02/processing-videos-in-java.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!