Thumbnail generation from multiple frames
A nice to have feature request:
Concerning thumbnail creation by grabbing a single frame at some time stamp within a movie it often represents the corresponding movie better to extract several frames at different location in time within the movie timeline and combine them.
I attached an example.
It is really easy to do in java:
(this piece of code is using javacv, so forget the grabbing part... for the example only the combining part is interesting and simple... and dont forget the aspect ratio in case..)
Concerning thumbnail creation by grabbing a single frame at some time stamp within a movie it often represents the corresponding movie better to extract several frames at different location in time within the movie timeline and combine them.
I attached an example.
It is really easy to do in java:
(this piece of code is using javacv, so forget the grabbing part... for the example only the combining part is interesting and simple... and dont forget the aspect ratio in case..)
- Code:
// Set resolution
int imageHeight = frameGrabber.getImageHeight();
int sizedWidth = (int)(frameGrabber.getImageWidth()*frameGrabber.getAspectRatio());
// Setup combined image
BufferedImage combinedImage = new BufferedImage(sizedWidth*2, imageHeight*2, BufferedImage.TYPE_INT_RGB);
Graphics g = combinedImage.getGraphics();
for (int i = 1; i <= 4; i++) {
int seekFrame = seekFrameGap*i;
// Jump to frame
frameGrabber.setFrameNumber(seekFrame);
frameGrabber.setDeinterlace(true);
// Grab image
Frame frame = frameGrabber.grabImage();
// Convert grabed frame to Java image
BufferedImage img = frameConverter.convert(frame);
// Size the Image with aspect ratio
BufferedImage sizedImg = toBufferedImage(img.getScaledInstance(sizedWidth, imageHeight, Image.SCALE_SMOOTH), img.getType());
// Combine the 4 thumbnails
int x = (i == 1 || i == 3) ? 0 : sizedWidth;
int y = (i == 1 || i == 2) ? 0 : imageHeight;
g.drawImage(sizedImg,x,y,null);
}
ImageIO.write(combinedImage, THUMBNAIL_FORMAT, extractedThumbnail);