如何查询Android设备的视频功能? [英] How to query the Video Capabilities of an Android device?

查看:263
本文介绍了如何查询Android设备的视频功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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));
        }
    }
}

上面的内容给了我,下面的个人资料和级别数字告诉我什么与视频功能有关的东西?

The above gave me this, what does the following number for profile and level tell me anything related to the video capabilities?

{"colorFormats":[21,2130708361],"profileLevels":[{"level":2048,"profile":1},{"level":2048,"profile":2},{"level":2048,"profile":8}],"flags":0}

如果我在上面的代码中取消注释了这两行,它将崩溃,并显示以下错误消息:

If I uncomment these two lines in the above code, it crashes with this error message:

java.lang.NoSuchMethodError: android.media.MediaCodecInfo$CodecCapabilities.getVideoCapabilities

如何查询android设备,以了解视频功能?我想知道设备能够处理的最大视频比特率和视频分辨率.

How can I query the android device, to find out the video capabilities? I'd like to know the max video bitrate and video resolution the device is capable to handle.

推荐答案

我猜您正在运行API<的设备上测试代码. 21吗?在这种情况下, getVideoCapabilies方法仅在运行Android> = 21的设备上可用

I guess that you are testing your code on a device running API < 21? If is the case, the getVideoCapabilies method is available only on devices running Android >= 21

无论如何,要获取比特率和支持的宽度&高度范围(API也== 21 ...嗯,可能与getVideoCapabilies可用性...我不知道:)),您可以使用:

Anyway, to get bitrate and supported width & height Ranges (API >=21 too...Humm may be related to getVideoCapabilies availability... I don't know :) ), you can use :

Range<Integer> bitrateRange = videoCapabilities.getBitrateRange();
Range<Integer> heightRange = videoCapabilities.getSupportedHeights();
Range<Integer> widthRange = videoCapabilities.getSupportedWidths();

您可以看一下我几天前发布的要点,以获得给定编解码器的所有功能(颜色,配置文件和级别是用名称而不是数字打印的,这可能会很有帮助): TestMediaCodecInfoAsyncTask.java

You can take a look at this gist that I published a few days ago to get all capabilities for a given codec (Colors, profiles & levels are printed by names instead of numbers, which could be very helpful): TestMediaCodecInfoAsyncTask.java

这篇关于如何查询Android设备的视频功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆