Search code examples
androidvideovideo-streamingandroid-mediacodecexoplayer

How to query the Video Capabilities of an Android device?


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

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.


Solution

  • 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

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

    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