本文共 1868 字,大约阅读时间需要 6 分钟。
???JavaCV??????????????????????????????????????JavaCV?????????????JAR???????????IDEA?Eclipse???????????????????????????????????
?????????JavaCV?????????????
????????????JavaCV????
import org.bytedeco.javacv.FFmpegFrameGrabber;import org.bytedeco.javacv.Frame;import org.bytedeco.javacv.Java2DFrameConverter;
?????????????????
public static final String VIDEO_PATH = "path/to/your/video.mp4";
??FFmpegFrameGrabber?????????????????????
public class VideoFrameGrabber { public static void grabFrames(String videoPath, String outputDir, String fileName, int frameRate) throws IOException { FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(videoPath); grabber.start(); for (int i = 0; i < frameRate; i++) { Frame frame = grabber.grabImage(); if (frame == null) continue; // ?????? saveFrame(frame, outputDir, fileName, i); } grabber.stop(); } private static void saveFrame(Frame frame, String outputDir, String fileName, int index) { Java2DFrameConverter converter = new Java2DFrameConverter(); BufferedImage image = converter.getBufferedImage(frame); String filePath = outputDir + File.separator + fileName + "_" + index + ".jpg"; File output = new File(filePath); try { ImageIO.write(image, "jpg", output); } catch (IOException e) { e.printStackTrace(); } }} ???????????????
public static void main(String[] args) throws IOException { VideoFrameGrabber.grabFrames(VIDEO_PATH, "output/", "video", 30);} ?????????????????????????????????????????
转载地址:http://asgq.baihongyu.com/