Question

Right now I am creating thumbnail using below method-

 Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
                    MediaStore.Images.Thumbnails.MICRO_KIND);

This method is working fine, The problem is I am getting thumbnail from the beginning of the video (Might be from 00:00 or 00:01).

My Ques is, Can I get Thumbnail from specified position(Let's say 00:05)? Thanks.

Was it helpful?

Solution

Yes you can by below way..

MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
   retriever.setDataSource(filePath);
   //here 5 means frame at the 5th sec.
    bitmap = retriever.getFrameAtTime(5);
    } catch (Exception ex) {
   // Assume this is a corrupt video file
}

For more info check it MediaMetadataRetriever

OTHER TIPS

FFmpegMediaMetadataRetriever will accomplish what you want and it works with API 7+:

FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
try {
    retriever.setDataSource(filePath);
    //here 5 means frame at the 5th sec.
    bitmap = retriever.getFrameAtTime(5);
} catch (Exception ex) {
    // Assume this is a corrupt video file
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top