public void getCodecInfo() {
int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (!codecInfo.isEncoder()) {
continue;
}
String[] types = codecInfo.getSupportedTypes();
for (int j = 0; j < types.length; j++) {
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(types[j]);
Log.d("CodecCapabilities", new Gson().toJson(capabilities));
//MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
//Log.d("videoCapabilities", new Gson().toJson(videoCapabilities));
}
}
}
上面给了我这个,下面的配置文件和级别的数字告诉我任何与视频功能相关的信息?
{"colorFormats":[21,2130708361],"profileLevels":[{"level":2048,"profile":1},{"level":2048,"profile":2},{"level":2048,"profile":8}],"flags":0}
如果我取消对上述代码中这两行的注释,它将崩溃,并显示以下错误消息:
java.lang.NoSuchMethodError: android.media.MediaCodecInfo$CodecCapabilities.getVideoCapabilities
如何查询android设备,以了解视频功能?我想知道这台设备能够处理的最大视频比特率和视频分辨率。
发布于 2018-08-03 06:07:22
我猜你是在一个运行API < 21的设备上测试你的代码?如果是这种情况,则getVideoCapabilies method is available only on devices running Android >= 21
无论如何,要获得码率和支持的宽度和高度Ranges ( >=21 too...Humm接口可能与getVideoCapabilies可用性有关...我不知道:) ),你可以使用:
Range<Integer> bitrateRange = videoCapabilities.getBitrateRange();
Range<Integer> heightRange = videoCapabilities.getSupportedHeights();
Range<Integer> widthRange = videoCapabilities.getSupportedWidths();
你可以看看我几天前发布的这个要点,以获得给定编解码器的所有功能(颜色、配置文件和级别是按名称而不是数字打印的,这可能非常有用):TestMediaCodecInfoAsyncTask.java
https://stackoverflow.com/questions/51660817
复制相似问题