一,通过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(安卓)获取当前语言的方法1
  2. Android应用程序获取ROOT权限的方法(android中如何通过代码检测
  3. android 银联支付接入报nullexception异常
  4. android 获取wifi 信号质量
  5. android获取mac地址
  6. android intent 传递对象需要序列化实现Parcelable接口
  7. android 获取网络IP地址
  8. NPM 和webpack 的基础使用
  9. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程

随机推荐

  1. Android(安卓)报错:AGPBI:MethodHandle.in
  2. android系统信息获取
  3. Android欢迎界面的创建方法
  4. view-ListView学习
  5. [置顶] Android资源文件分析
  6. Android(安卓)- Animation(二)
  7. Android去掉标题栏和全屏
  8. Android之创建实时文件夹
  9. Android当中的SeekBar与iOS中的UISlider
  10. Android(安卓)布局详解 -二相对布局(Relat