java获取手机当前帧数_java – 如何在android os中获取视频的帧速率?

MediaExtractor extractor = new MediaExtractor();

int frameRate = 24; //may be default

try {

//Adjust data source as per the requirement if file, URI, etc.

extractor.setDataSource(...);

int numTracks = extractor.getTrackCount();

for (int i = 0; i < numTracks; ++i) {

MediaFormat format = extractor.getTrackFormat(i);

String mime = format.getString(MediaFormat.KEY_MIME);

if (mime.startsWith("video/")) {

if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {

frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);

}

}

}

} catch (IOException e) {

e.printStackTrace();

}finally {

//Release stuff

extractor.release();

}

注意:尝试在工作线程中运行上述代码.

更新1什么是KEY_FRAME_RATE并且可以是可选的

KEY_FRAME_RATE

Added in API level 16

String KEY_FRAME_RATE

A key describing the frame rate of a video format in frames/sec. The associated value is normally an integer when the value is used by the platform, but video codecs also accept float configuration values. Specifically, MediaExtractor provides an integer value corresponding to the frame rate information of the track if specified and non-zero. Otherwise, this key is not present. MediaCodec accepts both float and integer values. This represents the desired operating frame rate if the KEY_OPERATING_RATE is not present and KEY_PRIORITY is 0 (realtime). For video encoders this value corresponds to the intended frame rate, although encoders are expected to support variable frame rate based on buffer timestamp. This key is not used in the MediaCodec input/output formats, nor by MediaMuxer.

常数值:“帧率”

更新2代码检查NPE如果KEY_FRAME_RATE不存在.往上看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值