视频首帧生成图片
依赖
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-all-deps</artifactId>
<version>3.5.0</version>
</dependency>
java 代码
public static void getFirstFrame(MultimediaObject video, File image) {
VideoAttributes videoattr = new VideoAttributes();
videoattr.addFilter(() -> {
return "fps=1";
});
EncodingAttributes attrs = new EncodingAttributes();
attrs.setVideoAttributes(videoattr);
try {
new Encoder().encode(List.of(video), image, attrs, null, List.of(new ValueArgument(ArgType.OUTFILE, "-vframes", ea -> Optional.of("1").map(Object::toString)), new ValueArgument(ArgType.OUTFILE, "-q:v", ea -> Optional.of("2").map(Object::toString))));
} catch (IllegalArgumentException | EncoderException e) {
e.printStackTrace();
}
}