a first video frame taken java

maven dependent 
taken image of the first frame-dependent
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>0.8</version>
</dependency>

// 文件转换依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>RELEASE</version>
</dependency>
// Get the file name
MP4 file.getOriginalFilename = String (); 
String IMG = System.currentTimeMillis () + ".jpg";
path // store file
File file2 = new new File ( "D: \\ \\ the Download" MP4 +);
File file4 new new file = ( "D: \\ the Download \\" + img);

// writes the incoming document to "D: \\ Download \\" + mp4
file.transferTo (file2); 
// call interception method, to be written back to the "D: \\ Download \\" + img inside the file
File1 = JiequImg.fetchFrame File (file2, file4); 
// File files into MultipartFile
= New new FileInput the FileInputStream the FileInputStream (file1); 
a MultipartFile toMultipartFile new new MockMultipartFile = ( "File", file1.getName (), "file application / JSON; charset = UTF-. 8", IOUtils.toByteArray (FileInput));
toMultipartFile.getInputStream () ;
// Upload
String S = fastDFSClientWrapper.uploadFile (file);
// off flow (not related flow can not delete files)
fileInput.close ();
// delete the video
file2.delete ();
// delete the first frame picture
file1 .delete ();






{class JiequImg public

public static fetchFrame File (File File, File file4)
throws Exception {
Long Start = System.currentTimeMillis ();
FFmpegFrameGrabber new new FFmpegFrameGrabber FF = (File);
ff.start ();
int lenght = ff.getLengthInFrames () ;
int I = 0;
frame F = null;
the while (I <lenght) {
//. 5 previous frame filter, to avoid all black image, according to their own circumstances
F = ff.grabFrame ();
IF ((I> . 5) && (f.image = null)) {!
BREAK;
}
I ++;
}
of IplImage IMG = f.image;
int owidth = img.width();
int oheight = img.height();
// 对截取的帧进行等比例缩放
int width = 800;
int height = (int) (((double) width / owidth) * oheight);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
bi.getGraphics().drawImage(f.image.getBufferedImage().getScaledInstance(width, height, Image.SCALE_SMOOTH),
0, 0, null);
//ff.flush();
ImageIO.write(bi, "jpg", file4);
ff.stop();
return file4;
}
}

Guess you like

Origin www.cnblogs.com/bt2882/p/11493134.html