Created
July 27, 2016 08:12
-
-
Save kaedea/eaf5ba2f74d274fb064654c690b1452b to your computer and use it in GitHub Desktop.
get MediaCodecInfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
public void testMediaCodecInfo() { | |
// list media codec | |
int numCodec = MediaCodecList.getCodecCount(); | |
for (int i = 0; i < numCodec; i++) { | |
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i); | |
Log.i(TAG, "[kaede][testMediaCodecInfo]" + | |
"=================================== " + codecInfo.getName() + " ==================================="); | |
boolean isEncoder = codecInfo.isEncoder(); | |
Log.d(TAG, "isEncoder = " + isEncoder); | |
// print encoder codec info | |
if (isEncoder) { | |
// list codec support media types | |
String[] types = codecInfo.getSupportedTypes(); | |
for (String type : types) { | |
Log.d(TAG, "codecInfo.getSupportedTypes = " + type); | |
// get capabilities of the given media type of the current codec | |
MediaCodecInfo.CodecCapabilities capabilitiesForType = codecInfo.getCapabilitiesForType(type); | |
Log.d(TAG, "default format = " + capabilitiesForType.getDefaultFormat().toString()); | |
// get video capabilities | |
Log.d(TAG, "video capabilities :"); | |
MediaCodecInfo.VideoCapabilities videoCapabilities = capabilitiesForType.getVideoCapabilities(); | |
if (videoCapabilities != null) { | |
Log.v(TAG, "BitrateRange = " + videoCapabilities.getBitrateRange()); | |
Log.v(TAG, "SupportedHeights = " + videoCapabilities.getSupportedHeights()); | |
Log.v(TAG, "SupportedWidths = " + videoCapabilities.getSupportedWidths()); | |
Log.v(TAG, "HeightAlignment = " + videoCapabilities.getHeightAlignment()); | |
Log.v(TAG, "Width Alignment = " + videoCapabilities.getWidthAlignment()); | |
// check if the given media type support certain heights, such 360px | |
boolean isSupported = videoCapabilities.getSupportedHeights().contains(360); | |
Log.d(TAG, "check if the given media type support certain heights, such 360px, " + | |
"isSupported = " + isSupported); | |
if (isSupported) { | |
Log.v(TAG, "SupportedWidthsFor(360) = " + videoCapabilities.getSupportedWidthsFor(360)); | |
Log.v(TAG, "SupportedFrameRatesFor(x,360) = " | |
+ videoCapabilities.getSupportedFrameRatesFor( | |
videoCapabilities.getSupportedWidthsFor(360).getUpper(), 360)); | |
} | |
} | |
// get profile & level capabilities | |
Log.d(TAG, " videoCapabilities profile levels:"); | |
for (int k = 0; k < capabilitiesForType.profileLevels.length; k++) { | |
Log.v(TAG, "profile = " + capabilitiesForType.profileLevels[k].profile); | |
Log.v(TAG, "level = " + capabilitiesForType.profileLevels[k].level); | |
} | |
} | |
} | |
Log.i(TAG, | |
"==================================================================================================="); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
获取当前设备支持的视频硬编码格式