GithubHelp home page GithubHelp logo

xiandanin / mediametadataretrievercompat Goto Github PK

View Code? Open in Web Editor NEW
123.0 7.0 21.0 64.32 MB

多媒体元数据兼容方案 - 支持获取图片、视频、音频文件的媒体信息、视频图片缩略图

License: MIT License

Java 100.00%
mediametadataretrievercompat mediametadataretriever video thumbnail frame

mediametadataretrievercompat's Introduction

效果

     图片         音频          视频         自定义

示例APK:example-debug.apk

Gradle

//必选
implementation 'in.xiandan.mmrc:media-metadata-retriever-compat:1.2.0'

//可选,需要Exif支持时必选
implementation 'com.android.support:exifinterface:28.0.0'
//可选,需要FFmpeg支持时必选,全平台约24M
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'

//只保留v7a,可降低至3M
ndk {
    abiFilters 'armeabi-v7a'
}

数据源类型

datasource 中预设了一些DataSource,以提供不同的输入源,如果需要自定义数据源,可implements DataSource或参考其它数据源

设置数据源

设置数据源的操作建议放在子线程

MediaMetadataRetrieverCompat mmrc = new MediaMetadataRetrieverCompat();

//设置数据源
mmrc.setDataSource(source);
//设置数据源或抛出异常
mmrc.setDataSourceOrThrow(source);
//设置数据源或抛出异常 并指定检索器
mmrc.setDataSourceOrThrow(source, AndroidMediaMetadataRetrieverFactory.class);

获取Metadata信息

final String width = mmrc.extractMetadata(MediaMetadataKey.WIDTH);

//将值转换为int
final int width = mmrc.extractMetadataInt(MediaMetadataKey.WIDTH, 0);

//将值转换为float
final float width = mmrc.extractMetadataFloat(MediaMetadataKey.WIDTH, 0f);

//将值转换为long
final long width = mmrc.extractMetadataLong(MediaMetadataKey.WIDTH, 0L);

...

获取缩略图

取帧是耗时操作,需要放在子线程,视频有4种取帧方式

//最接近timeUs的关键帧 - 仅视频
MediaMetadataKey.OPTION_CLOSEST_SYNC

//最接近timeUs的帧,不一定是关键帧(性能开销较大) - 仅视频
MediaMetadataKey.OPTION_CLOSEST

//早于timeUs的关键帧 - 仅视频
MediaMetadataKey.OPTION_PREVIOUS_SYNC

//晚于timeUs的关键帧 - 仅视频
MediaMetadataKey.OPTION_NEXT_SYNC
//获取第一帧原尺寸图片
mmrc.getFrameAtTime();

//获取指定毫秒的原尺寸图片 注意这里传的毫秒不再是微秒
mmrc.getFrameAtTime(0, MediaMetadataKey.OPTION_CLOSEST_SYNC);

//获取指定毫秒的缩略图,并基于指定宽高缩放,输出的Bitmap不一定是指定宽高
mmrc.getScaledFrameAtTime(0, MediaMetadataKey.OPTION_CLOSEST_SYNC, 300, 300);

//获取指定毫秒的缩略图,并按指定宽高缩放裁剪,输出的Bitmap一定是指定宽高
mmrc.getCenterCropFrameAtTime(0, MediaMetadataKey.OPTION_CLOSEST_SYNC, 300, 300);

全局配置

//创建一个新的配置构造器
MediaMetadataConfig.newBuilder()
        .setCustomDataSourceCallback(new MediaMetadataConfig.CustomDataSourceCallback() {
            @Override
            public void setCustomDataSource(IMediaMetadataRetriever retriever, DataSource source) {
                //当设置了自定义数据源时 会回调
            }
        })
        //添加格式检查器
        .addFileFormatChecker(new CustomFormatChecker())
        //添加自定义检索器
        .addCustomRetrieverFactory(new SVGMediaMetadataRetrieverFactory())
        .addCustomRetrieverFactory(new CustomMediaMetadataRetrieverFactory())
        .build()
        //应用配置
        .apply();

自定义检索器

custom 演示了以SVG文件为例如何自定义检索器

MediaMetadataConfig.newBuilder()
        .addFileFormatChecker(new CustomFormatChecker())
        .addCustomRetrieverFactory(new SVGMediaMetadataRetrieverFactory())
        .build()
        .apply();

相关资料

fresco/imageformat
FFmpegMediaMetadataRetriever
MediaMetadataRetriever
ImageDecoder
ExifInterface

mediametadataretrievercompat's People

Contributors

xiandanin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mediametadataretrievercompat's Issues

Fails to work on InputStream

InputStreamSource(source.inputStream()) where my source is

source: BufferedSource,

fails. I mean the input streamsource creation works, but can't get any frames afterwards.

java.lang.IllegalStateException: Failed to decode frame at 2000 microseconds.

不兼容最新版NDK

Androidstudio 添加依赖以后,使用最新版NDK编译不过
NDK版本:17.1
报错
Error:Execution failed for task ':example:transformNativeLibsWithStripDebugSymbolForDebug'.
A problem occurred starting process 'command '/Users/yh/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64/bin/mips64el-linux-android-strip''

ndk目录下darwin-x86_64/ 之后的子目录没有bin/mips64el-linux-android-strip
使用NDK 16就可以编译过

Licence?

Hi,

can you please include the licence? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.