Skip to content Skip to sidebar Skip to footer

Get Supported Codec For Android Device

Is there a way to ask an Android device what audio and video Codecs it supports for encoding? I found devices that do not support some of the codecs listed as mandatory in http://d

Solution 1:

That could be interesting for you:

privatestatic MediaCodecInfo selectCodec(String mimeType) {
     intnumCodecs= MediaCodecList.getCodecCount();
     for (inti=0; i < numCodecs; i++) {
         MediaCodecInfocodecInfo= MediaCodecList.getCodecInfoAt(i);

         if (!codecInfo.isEncoder()) {
             continue;
         }

         String[] types = codecInfo.getSupportedTypes();
         for (intj=0; j < types.length; j++) {
             if (types[j].equalsIgnoreCase(mimeType)) {
                 return codecInfo;
             }
         }
     }
     returnnull;
 }

Found it here. AS you can see you get the number of installed codecs with MediaCodecList.getCodecCount();. With MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i); you get information about a specific codec out of the list. codecInfo.getName() for example tells you title/name of the codec.

Solution 2:

Is there a way to ask an Android device what audio and video Codecs it supports for encoding?

I really wish there were, but there is not, at least through ICS.

Jelly Bean offers a MediaCodec class. While it does not have a "give me a list of supported codecs", it does have createEncoderByType(), where you pass in a MIME type. Presumably, that will throw a RuntimeException or return null if your desired MIME type is not supported. And I cannot promise that just because MediaCodec reports that an encoder is available that it is guaranteed to work from, say, MediaRecorder.

Solution 3:

Here is an updated code based on Jonson's answer, written in Kotlin and not using deprecated methods:

fungetCodecForMimeType(mimeType: String): MediaCodecInfo? {
    val mediaCodecList = MediaCodecList(MediaCodecList.REGULAR_CODECS)
    val codecInfos = mediaCodecList.codecInfos
    for (i in codecInfos.indices) {
        val codecInfo = codecInfos[i]
        
        if (!codecInfo.isEncoder) {
            continue
        }
        
        val types = codecInfo.supportedTypes
        for (j in types.indices) {
            if (types[j].equals(mimeType, ignoreCase = true)) {
                return codecInfo
            }
        }
    }
    
    returnnull
}

Solution 4:

The simplest way is using

MediaCodecList(MediaCodecList.ALL_CODECS).codecInfos

It returns a array of all encoders and decoders available on your devices like this image.

And then, you can use filter to query the specific encoders and decoders you are looking for. For example:

MediaCodecList(MediaCodecList.ALL_CODECS).codecInfos.filter {
    it.isEncoder && it.supportedTypes[0].startsWith("video")
}

This returns all available video encoders.

Post a Comment for "Get Supported Codec For Android Device"