Generate Thumbnail from Video Using Java
public String generateThumnail(String videoUrl) {
logger.info("************************************");
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoUrl);
logger.info(" generateThumnail videoUrl---" + videoUrl);
String fileName = videoUrl.substring(videoUrl.lastIndexOf('/') + 1);
logger.info("generateThumnail fileName---" + fileName);
fileName = fileName.substring(0, fileName.lastIndexOf("."));
logger.info("generateThumnail fileName---1" + fileName);
String path = thumbUrl + fileName + ".png";
String filenameS3 = fileName + ".png";
logger.info("generateThumnail filenameS3---1" + filenameS3);
try {
frameGrabber.start();
Java2DFrameConverter aa = new Java2DFrameConverter();
BufferedImage bi;
Frame f = frameGrabber.grabKeyFrame();
bi = aa.convert(f);
while (bi != null) {
ImageIO.write(bi, "png", new File(serverPath + fileName + ".png"));
f = frameGrabber.grabKeyFrame();
bi = aa.convert(f);
File myFile = new File(serverPath + fileName + ".png");
InputStream is = new FileInputStream(myFile);
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType("image/png");
meta.setContentLength(myFile.length());
s3client.putObject(new PutObjectRequest(bucketNameThumb, filenameS3, is, meta)
.withCannedAcl(CannedAccessControlList.PublicRead));
}
frameGrabber.stop();
} catch (Exception e) {
logger.info("Error Message: " + e.getMessage());
}
return path;
}
Post Views: 3,452