Android 获取系统编解码器
媒体编解码器 官网说明。
通过 MediaCodecInfo
拿到解码器信息:
getName()
:获取编解码器名字。isEncoder()
:如果是编码器返回 true 。如果是编码器,返回 false 。isHardwareAccelerated()
:如果是硬解码返回 true 。isVendor()
:如果编解码器由设备供应商提供,则返回 true;如果由 Android 平台提供,则返回 false。getSupportedTypes()
:获取支持的媒体类型。
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
private void MediaCodecInfo(){
MediaCodecList list = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
list = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
MediaCodecInfo[] supportCodes = list.getCodecInfos();
if (null != supportCodes && supportCodes.length > 0) {
for (MediaCodecInfo info : supportCodes){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
StringBuilder strTypes = new StringBuilder();
String[] types = info.getSupportedTypes();
for (int j = 0; j < types.length; j++) {
strTypes.append(types[j]).append(",");
}
Log.d(TAG , "[MainActivity] -- MediaCodecInfo -- "
+ "find MediaCodecInfo " + info.getName()
+ " , isEncoder:" + info.isEncoder()
+ " , isHardwareAccelerated:" + info.isHardwareAccelerated()
+ " , isVendor:" + info.isVendor()
+ " , supportedTypes:" + strTypes);
}
}
}
}
}
模拟器运行结果,
find MediaCodecInfo OMX.google.aac.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/mp4a-latm,
find MediaCodecInfo OMX.google.amrnb.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/3gpp,
find MediaCodecInfo OMX.google.amrwb.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/amr-wb,
find MediaCodecInfo OMX.google.flac.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/flac,
find MediaCodecInfo OMX.google.g711.alaw.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/g711-alaw,
find MediaCodecInfo OMX.google.g711.mlaw.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/g711-mlaw,
find MediaCodecInfo OMX.google.gsm.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/gsm,
find MediaCodecInfo OMX.google.mp3.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/mpeg,
find MediaCodecInfo OMX.google.opus.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/opus,
find MediaCodecInfo OMX.google.raw.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/raw,
find MediaCodecInfo OMX.google.vorbis.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/vorbis,
find MediaCodecInfo OMX.google.aac.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/mp4a-latm,
find MediaCodecInfo OMX.google.amrnb.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/3gpp,
find MediaCodecInfo OMX.google.amrwb.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/amr-wb,
find MediaCodecInfo OMX.google.flac.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/flac,
find MediaCodecInfo OMX.google.h264.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/avc,
find MediaCodecInfo OMX.google.h263.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/3gpp,
find MediaCodecInfo OMX.google.hevc.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/hevc,
find MediaCodecInfo OMX.google.mpeg4.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/mp4v-es,
find MediaCodecInfo OMX.google.vp8.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/x-vnd.on2.vp8,
find MediaCodecInfo OMX.google.vp9.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/x-vnd.on2.vp9,
find MediaCodecInfo OMX.google.h264.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/avc,
find MediaCodecInfo OMX.google.h263.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/3gpp,
find MediaCodecInfo OMX.google.mpeg4.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/mp4v-es,
find MediaCodecInfo OMX.google.vp8.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/x-vnd.on2.vp8,
find MediaCodecInfo OMX.google.vp9.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/x-vnd.on2.vp9,
真机运行结果,
find MediaCodecInfo OMX.google.aac.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/mp4a-latm,
find MediaCodecInfo OMX.google.amrnb.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/3gpp,
find MediaCodecInfo OMX.google.amrwb.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/amr-wb,
find MediaCodecInfo OMX.google.flac.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/flac,
find MediaCodecInfo OMX.google.g711.alaw.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/g711-alaw,
find MediaCodecInfo OMX.google.g711.mlaw.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/g711-mlaw,
find MediaCodecInfo OMX.google.mp3.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/mpeg,
find MediaCodecInfo OMX.google.opus.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/opus,
find MediaCodecInfo OMX.google.raw.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/raw,
find MediaCodecInfo OMX.google.vorbis.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/vorbis,
find MediaCodecInfo OMX.google.aac.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/mp4a-latm,
find MediaCodecInfo OMX.google.amrnb.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/3gpp,
find MediaCodecInfo OMX.google.amrwb.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/amr-wb,
find MediaCodecInfo OMX.google.flac.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:audio/flac,
find MediaCodecInfo OMX.MS.AC3.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/ac3,audio/ac3p,audio/eac3,
find MediaCodecInfo OMX.MS.AC4.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/ac4,
find MediaCodecInfo OMX.MS.ADPCM.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/x-adpcm-ima,audio/x-adpcm-ms,
find MediaCodecInfo OMX.MS.DRA.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/vnd.dra,
find MediaCodecInfo OMX.MS.FLAC.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/flac,
find MediaCodecInfo OMX.MS.AAC.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/mp4a-latm-hw,
find MediaCodecInfo OMX.MS.MP1.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/mpeg-L1,
find MediaCodecInfo OMX.MS.MP2.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/mpeg-L2,
find MediaCodecInfo OMX.MS.MP3.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/mpeg,
find MediaCodecInfo OMX.MS.OPUS.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/opus,
find MediaCodecInfo OMX.MS.Passthrough.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/passthrough,
find MediaCodecInfo OMX.MS.VORBIS.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:audio/vorbis,
find MediaCodecInfo OMX.MS.AV1.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/av01,
find MediaCodecInfo OMX.MS.AVC.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/avc,
find MediaCodecInfo OMX.MS.AVS.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/avs,
find MediaCodecInfo OMX.MS.AVS2.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/avs2,
find MediaCodecInfo OMX.MS.FLV.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/flv,
find MediaCodecInfo OMX.MS.H263.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/3gpp,
find MediaCodecInfo OMX.MS.HEVC.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/hevc,
find MediaCodecInfo OMX.MS.MJPG.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/x-motion-jpeg,
find MediaCodecInfo OMX.MS.MPEG2.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/mpeg2,
find MediaCodecInfo OMX.MS.M4V.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/mp4v-es,
find MediaCodecInfo OMX.MS.VC1.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/VC1,
find MediaCodecInfo OMX.MS.VP8.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/x-vnd.on2.vp8,
find MediaCodecInfo OMX.MS.VP9.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/x-vnd.on2.vp9,
find MediaCodecInfo OMX.MS.WMV3.Decoder , isEncoder:false , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/x-ms-wmv,
find MediaCodecInfo OMX.MS.AVC.Encoder , isEncoder:true , isHardwareAccelerated:true , isVendor:true , supportedTypes:video/avc,
find MediaCodecInfo OMX.google.h263.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/3gpp,
find MediaCodecInfo OMX.google.mpeg4.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/mp4v-es,
find MediaCodecInfo OMX.google.vp8.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/x-vnd.on2.vp8,
find MediaCodecInfo OMX.google.vp9.decoder , isEncoder:false , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/x-vnd.on2.vp9,
find MediaCodecInfo OMX.google.h264.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/avc,
find MediaCodecInfo OMX.google.h263.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/3gpp,
find MediaCodecInfo OMX.google.mpeg4.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/mp4v-es,
find MediaCodecInfo OMX.google.vp8.encoder , isEncoder:true , isHardwareAccelerated:false , isVendor:false , supportedTypes:video/x-vnd.on2.vp8,