I searched Google for various terms on how to get the thumbnail of the videos but only found how to "generate" the thumbnail of a frame from the video using Xuggler
but I'm having errors.
Belowismyclass:
packageutil;importjava.awt.image.BufferedImage;importjava.io.File;importjava.io.IOException;importjava.util.List;importjavax.imageio.ImageIO;importcom.xuggle.mediatool.IMediaReader;importcom.xuggle.mediatool.MediaListenerAdapter;importcom.xuggle.mediatool.ToolFactory;importcom.xuggle.mediatool.event.IVideoPictureEvent;importcom.xuggle.xuggler.Global;importmodel.Video;publicclassBuildThumbnailUtil{publicstaticfinaldoubleSECONDS_BETWEEN_FRAMES=1;privatestaticfinalStringoutputFilePrefix="C:/Documents and Settings/Panda/Desktop/MovieList/";
private static int mVideoStreamIndex = -1;
private static long mLastPtsWrite = Global.NO_PTS;
public static final long MICRO_SECONDS_BETWEEN_FRAMES = (long) (Global.DEFAULT_PTS_PER_SECOND * SECONDS_BETWEEN_FRAMES);
public static void buildThumbnail(List<Video> videos) {
for (Video v : videos) {
IMediaReader mediaReader = ToolFactory.makeReader(v.getPath());
try {
mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
ImageSnapListener isListener = new ImageSnapListener();
mediaReader.addListener(isListener);
while (!isListener.isImageGrabbed()) {
mediaReader.readPacket();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private static class ImageSnapListener extends MediaListenerAdapter {
public boolean imageGrabbed = false;
public void onVideoPicture(IVideoPictureEvent event) {
if (event.getStreamIndex() != mVideoStreamIndex) {
if (mVideoStreamIndex == -1)
mVideoStreamIndex = event.getStreamIndex();
else
return;
}
if (mLastPtsWrite == Global.NO_PTS)
mLastPtsWrite = event.getTimeStamp() - MICRO_SECONDS_BETWEEN_FRAMES;
if (event.getTimeStamp() - mLastPtsWrite >= MICRO_SECONDS_BETWEEN_FRAMES * 10) {
String outputFilename = dumpImageToFile(event.getImage());
this.imageGrabbed = true;
double seconds = ((double) event.getTimeStamp()) / Global.DEFAULT_PTS_PER_SECOND;
System.out.printf("at elapsed time of %6.3f seconds wrote: %s\n", seconds, outputFilename);
mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES;
}
}
private String dumpImageToFile(BufferedImage image) {
try {
String outputFilename = outputFilePrefix + System.currentTimeMillis() + ".jpg";
System.out.println("Thumbnail image name is going to be : =====>" + outputFilename);
ImageIO.write(image, "jpg", new File(outputFilename));
return outputFilename;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public boolean isImageGrabbed() {
return imageGrabbed;
}
}
}
Does anyone know if they have a way to get the same thumbnail of a video just as Windows displays?