Home > Mobile > Access to video thumbnails, the problem of the first frame
Access to video thumbnails, the problem of the first frame
Time:09-24
MetadataRetriever retriever=new MediaMetadataRetriever (); Try { //according to the file path for the thumbnail Retriever. SetDataSource (the fileInfo. GetFile_path ()); //get the first frame picture //Bitmap Bitmap=retriever. GetFrameAtTime (); //get 1 ms frame picture Bitmap Bitmap=retriever. GetFrameAtTime (1000, MediaMetadataRetriever. OPTION_CLOSEST_SYNC); If (bitmap!=null) {
The fileInfo. SetBitmap (bitmap); LogUtils. E (bitmap. GetByteCount ()/1024 + "KB w=" + bitmap. The getWidth () + "h=" + bitmap. GetHeight ());
} else { LogUtils. E (" (bitmap==null); } } the catch (IllegalArgumentException e) { e.printStackTrace(); } the finally { Retriever. Release (); } Bitmap always returns null To switch to FFmpegMediaMetadataRetriever Matrix matrix=new Matrix(); FFmpegMediaMetadataRetriever retriever=new FFmpegMediaMetadataRetriever (); Try {
Retriever. SetDataSource (the fileInfo. GetFile_path ());
//Bitmap Bitmap=retriever. GetFrameAtTime (); //get 1 ms frame picture Bitmap Bitmap=retriever. GetFrameAtTime (1000, FFmpegMediaMetadataRetriever. OPTION_CLOSEST_SYNC); If (bitmap!=null) { Matrix. SetScale (0.1 0.1 f, f); Bitmap bitmap=createBitmap (bitmap, 0, 0, bitmap. The getWidth (), Bitmap. GetHeight (), matrix, true); //1920 x 1080 video about 2 s left and right sides, 3840 * 2160 video was about 8 s The fileInfo. SetBitmap (bitmap); LogUtils. E (bitmap. GetByteCount ()/1024 + "KB w=" + bitmap. The getWidth () + "h=" + bitmap. GetHeight ()); } } the catch (IllegalArgumentException e) { e.printStackTrace(); } the finally { Retriever. Release (); }
Use Glide Glide. With (context). The load (list) get (I)) getFile_path ()). The thumbnail (0.1 f) into (viewHolder. Iv_thumb); 1920 * 1080 can be normal, according to 3840 * 2160 can't display, List to show the filename, the information such as the length, but by FFmpegMediaMetadataRetriever each get a bitmap update item, the effect is completely can't look straight into the There is no other way
CodePudding user response:
From the top, there is no other solution??????
CodePudding user response:
Is the local video? Local video Glide4.0 will not display thumbnails