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.
That could be interesting for you:
private static MediaCodecInfo selectCodec(String mimeType) {
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++) {
if (types[j].equalsIgnoreCase(mimeType)) {
return codecInfo;
}
}
}
return null;
}
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.
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
.
上一篇: 设备/平板电脑应用所需的视频格式
下一篇: 获得Android设备支持的编解码器