下面列出了android.media.MediaCodec# getCodecInfo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static boolean trySetProfileAndLevel(MediaCodec codec, String mime, MediaFormat format, int profileInt, int levelInt) {
MediaCodecInfo codecInfo = codec.getCodecInfo();
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mime);
MediaCodecInfo.CodecProfileLevel[] profileLevels = capabilities.profileLevels;
if (profileLevels == null) {
return false;
}
for (MediaCodecInfo.CodecProfileLevel level : profileLevels) {
if (level.profile == profileInt) {
if (level.level == levelInt) {
format.setInteger(MediaFormat.KEY_PROFILE, profileInt);
format.setInteger(MediaFormat.KEY_LEVEL, levelInt);
return true;
}
}
}
return false;
}
/**
* Returns true if the given codec supports adaptive playback (dynamic resolution change).
* @param mediaCodec the codec.
* @param mime MIME type that corresponds to the codec creation.
* @return true if this codec and mime type combination supports adaptive playback.
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean codecSupportsAdaptivePlayback(MediaCodec mediaCodec, String mime) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || mediaCodec == null) {
return false;
}
try {
MediaCodecInfo info = mediaCodec.getCodecInfo();
if (info.isEncoder()) {
return false;
}
if (isAdaptivePlaybackBlacklisted(mime)) {
return false;
}
MediaCodecInfo.CodecCapabilities capabilities = info.getCapabilitiesForType(mime);
return (capabilities != null)
&& capabilities.isFeatureSupported(
MediaCodecInfo.CodecCapabilities.FEATURE_AdaptivePlayback);
} catch (IllegalArgumentException e) {
Log.e(TAG, "Cannot retrieve codec information", e);
}
return false;
}
public static int getMaxSupportBitrate(MediaCodec codec, String mime) {
try {
MediaCodecInfo codecInfo = codec.getCodecInfo();
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mime);
Integer maxBitrate = capabilities.getVideoCapabilities().getBitrateRange().getUpper();
return maxBitrate;
} catch (Exception e) {
CL.e(e);
return -1;
}
}