从视频中取出关键帧保存图片
ThreadUtils.executeBySingle(new ThreadUtils.SimpleTask<String>() {
@Nullable
@Override
public String doInBackground() throws Throwable {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(file.getAbsolutePath());
Bitmap result = mmr.getFrameAtTime(0, MediaMetadataRetriever.OPTION_CLOSEST);
mmr.release();
if (result != null) {
Bitmap bitmap = ThumbnailUtils.extractThumbnail(result, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
if (bitmap != null) {
return FileUtil.saveBitmap(context, bitmap, AlbumUtil.getFileThumbPath(file.getName()));
}
}
return null;
}
@Override
public void onSuccess(@Nullable String result) {
}
});