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.

有帮助吗?

解决方案

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

其他提示

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
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top