zoukankan      html  css  js  c++  java
  • Android 获取视频缩略图

    使用FFmpegMediaMetadataRetriever  github:https://github.com/wseemann/FFmpegMediaMetadataRetriever

    删掉没用的库其实没多大,删掉mips和x86文件夹

    代码:

    private Bitmap getThumbnai(String path){
            FFmpegMediaMetadataRetriever fmmr = new FFmpegMediaMetadataRetriever();
            Bitmap bitmap = null;
            try {
              fmmr.setDataSource(path);
              bitmap = fmmr.getFrameAtTime();
              if (bitmap != null) {
                Bitmap b2 = fmmr
                    .getFrameAtTime(
                        4000000,
                        FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC);
                if (b2 != null) {
                  bitmap = b2;
                }
                if (bitmap.getWidth() > 640) {// 如果图片宽度规格超过640px,则进行压缩
                  bitmap = ThumbnailUtils.extractThumbnail(bitmap,
                      640, 480,
                      ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
                }
              }
            } catch (IllegalArgumentException ex) {
              ex.printStackTrace();
            } finally {
              fmmr.release();
            }
            return bitmap;
        }

    在掉用的时候异步调一下

    new AsyncTask<Void, Void, Bitmap>(){
    
                @Override
                protected Bitmap doInBackground(Void... arg0) {
                    Bitmap b = MainActivity.this.getThumbnai(path);
                    return b;
                }
    
                @Override
                protected void onPostExecute(Bitmap b) {
                    if(b!=null){
                        Log.d("doubi", "b!=null");
                        image.setImageBitmap(b);
                        bar.setVisibility(View.GONE);
                        image.setVisibility(View.VISIBLE);
                        play.setVisibility(View.VISIBLE);
                    }
                }
            }.execute();

    ~~先记录再次,有时间再细研究

  • 相关阅读:
    Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks (Codeforces 832A)
    bzoj 2301 Problem b
    bzoj 1101 [POI2007]Zap
    bzoj 2005 能量采集
    bzoj 2527 Meteors
    bzoj 2724 [Violet 6]蒲公英
    回顾树状数组
    bzoj 3237 连通图
    bzoj 2733 永无乡
    Codeforces 817C Really Big Numbers
  • 原文地址:https://www.cnblogs.com/hanhongmin/p/4149476.html
Copyright © 2011-2022 走看看