java 视频获取第一帧保存图片
【代码】java 视频获取第一帧保存图片。
·
jar
<!-- 获取视频第一帧依赖 -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg-platform</artifactId>
<version>3.4.2-1.4.1</version>
</dependency>
代码
package com.qike.aliyun.media.utils;
import org.bytedeco.javacv.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
public class VideoFrameGrabber {
public static void main(String[] args) throws Exception {
// 视频地址
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("https://douyin-xjy.oss-cn-hangzhou.aliyuncs.com/douyin-xjy/hecheng/2023/04/18/fe5bc62a0b6e4500b1d2ad60541222f9.mp4");
grabber.start();
Java2DFrameConverter converter = new Java2DFrameConverter();
BufferedImage image = converter.convert(grabber.grabImage());
// 本地图片保存地址
ImageIO.write(image, "png", new File("/Users/liushuangshuang/Desktop/图片/first_frame.png"));
grabber.stop();
}
}
更多推荐
已为社区贡献5条内容
所有评论(0)