Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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://developer.android.com/guide/appendix/media-formats.html and there seem to be devices supporting additional codec not listed there.

like image 955
Marcus Wolschon Avatar asked Aug 03 '12 07:08

Marcus Wolschon


People also ask

Which audio codec is best for Android?

AAC. AAC stands for Advanced Audio Codec and is a standard codec on iPhones and iPads. It is supported by Android devices and laptops too and with 320 kilobits/ second at 24-bit and 96KHz quality of AAC is very interesting.

How do I fix unsupported video format on Android?

The easiest way to fix not supported audio or video codec error on Android is using the VLC Media Player app. VLC comes with extended codecs to play files such as MKV, MOV, WMV, etc.

Does H 264 work on Android?

Device implementations must support dynamic video resolution and frame rate switching through the standard Android APIs within the same stream for all VP8, VP9, H. 264, and H. 265 codecs in real time and up to the maximum resolution supported by each codec on the device.


2 Answers

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

 fun getCodecForMimeType(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
            }
        }
    }
    
    return null
}
like image 82
anro Avatar answered Oct 18 '22 21:10

anro


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.

like image 36
tasy5kg Avatar answered Oct 18 '22 21:10

tasy5kg