从视频中取出关键帧保存图片

从视频中取出关键帧保存图片


        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) {

            }


        });

猜你喜欢

转载自blog.csdn.net/Android_LeeJiaLun/article/details/108326234
今日推荐