1.maven
<
dependency
>
<
groupId
>org.bytedeco
</
groupId
>
<
artifactId
>javacv
</
artifactId
>
<
version
>1.0
</
version
>
</
dependency
>
2.
File targetFile =
new File(AppGlobals.
tomcatPath+
"/"+AppGlobals.
rootFolder+
"/"+AppGlobals.
tchApproveInfoFolder+
"/"+
"aaa.jpg")
;
FFmpegFrameGrabber ff = FFmpegFrameGrabber. createDefault(AppGlobals. tomcatPath+videoFilePath) ;
ff.start() ;
int lenght = ff.getLengthInFrames() ;
int i = 0 ;
org.bytedeco.javacv.Frame f= null;
while (i < lenght) {
// 过滤前100帧
f = ff.grabFrame() ;
if ((i > 100) && (f. image != null)) {
break;
}
i++ ;
}
Java2DFrameConverter converter = new Java2DFrameConverter() ;
BufferedImage bi = converter.getBufferedImage(f) ;
ImageIO. write(bi , "jpg" ,targetFile) ;
FFmpegFrameGrabber ff = FFmpegFrameGrabber. createDefault(AppGlobals. tomcatPath+videoFilePath) ;
ff.start() ;
int lenght = ff.getLengthInFrames() ;
int i = 0 ;
org.bytedeco.javacv.Frame f= null;
while (i < lenght) {
// 过滤前100帧
f = ff.grabFrame() ;
if ((i > 100) && (f. image != null)) {
break;
}
i++ ;
}
Java2DFrameConverter converter = new Java2DFrameConverter() ;
BufferedImage bi = converter.getBufferedImage(f) ;
ImageIO. write(bi , "jpg" ,targetFile) ;