一,通过Android系统自带的类获取:

1.  public staticBitmapcreateVideoThumbnail(String filePath,int kind){
   
Bitmap bitmap = null;
   
MediaMetadataRetriever retriever = newMediaMetadataRetriever();
   
try {
       
if (filePath.startsWith("http://")
               
|| filePath.startsWith("https://")
               
|| filePath.startsWith("widevine://")) {
           
retriever.setDataSource(filePath,newHashtable());
       
}else {
           
retriever.setDataSource(filePath);
        }
        bitmap =retriever.getFrameAtTime(-1);
   
} catch (IllegalArgumentExceptionex) {
       
// Assume this is a corrupt video file
       
ex.printStackTrace();
   
} catch (RuntimeExceptionex) {
       
// Assume this is a corrupt video file.
       
ex.printStackTrace();
   
} finally {
       
try {
           
retriever.release();
        } catch (RuntimeExceptionex) {
           
// Ignore failures while cleaning up.
           
ex.printStackTrace();
       
}
    }

    if (bitmap==null)returnnull;

   
if (kind== MediaStore.Images.Thumbnails.MINI_KIND) {
       
// Scale down the bitmap if it's too large.
       
int width= bitmap.getWidth();
       
int height= bitmap.getHeight();
       
int max =Math.max(width, height);
      
 if(max >512) {
           
float scale=512f / max;
           
int w =Math.round(scale * width);
           
int h =Math.round(scale * height);
           
bitmap = Bitmap.createScaledBitmap(bitmap,w, h, true);
       
}
    } else if (kind== MediaStore.Images.Thumbnails.MICRO_KIND) {
       
bitmap = ThumbnailUtils.extractThumbnail(bitmap,
                96,
               
96,
               
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
   
}
    return bitmap;
}


1.      根据视频文件的路径,我们可以通过android自带的MediaMetadataRetriever类获取到视频文件的缩略图,支持的视频文件格式为:mkv,mp4等。支持的视频文件格式比较局限,因此我选择使用MediaMetadataRetriever的拓展类:FFmepgMediaMetadataRetriever来取更多格式的视频文件缩略图。

2.      下载prebuilt-aars.zip压缩包,解压后得到fmmr.aar文件(与jar文件类似),将fmmr.aar文件添加到项目中,即可创建FFmepgMediaMetadataRetriever对象,并获取到视频文件缩略图


方案二:

//创建FFmpegMediaMetadataRetriever对象 FFmpegMediaMetadataRetriever mm=new FFmpegMediaMetadataRetriever();
try    //获取视频文件数据    mm.setDataSource(path);
//获取文件缩略图    Bitmap bitmap=mm.getFrameAtTime();    }catch (Exception e){}finally {    mm.release();}

参考:https://github.com/wseemann/FFmpegMediaMetadataRetriever/

参考:http://blog.csdn.net/zhiyahan/article/details/51793319

个人Demo:https://github.com/15008049860/FFmepg





更多相关文章

  1. android intent 传递对象需要序列化实现Parcelable接口
  2. Android MIME类型与文件后缀名匹配部分
  3. android 文件存储
  4. android 文字或者图片生成.pdf文件
  5. android文件解析InputStream问题解决
  6. Android学习 数据存储之_文件存储
  7. Android Mediacodec H.265文件播放
  8. android 获取音乐文件的内置专辑图片
  9. Android 文件存储及常见问题解决

随机推荐

  1. 内存优化三
  2. 【Android】ViewFlipper的使用
  3. android实现RecyclerView上拉加载,下拉更
  4. andorid底部菜单导航
  5. 1.3 History of Android(安卓)Plug-in Pr
  6. Android(安卓)activity‘s life cycle
  7. android TextView 分散对齐(两端对齐)
  8. Android编程权威指南之Activity的抽象类
  9. 将获取的html源代码格式化输出
  10. Bullet physics 先粘过来后期翻译