Supported Codecs
从上表上看编码方面:H264仅支持到Main Profile,H265暂时不支持。
但是平台商的部分高端芯片已经支持H264 HP,H265编码。
提供MediaCodec在设备上的支持信息。
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;
}
getCapabilitiesForType added in API level 16
public MediaCodecInfo.CodecCapabilities getCapabilitiesForType (String type)
Enumerates the capabilities of the codec component. Since a single component can support data of a variety of types, the type has to be specified to yield a meaningful result.
Parameters
type String: The MIME type to query
Returns
MediaCodecInfo.CodecCapabilities
设备对MediaCodec支持的信息基本都在这里,比如BitrateMode,Profile等
createFromProfileLevel added in API level 21
public static MediaCodecInfo.CodecCapabilities createFromProfileLevel (String mime, int profile, int level)
Retrieve the codec capabilities for a certain mime type, profile and level. If the type, or profile-level combination is not understood by the framework, it returns null.
In Build.VERSION_CODES.M, calling this method without calling any method of the MediaCodecList class beforehand results in a NullPointerException.
profileLevels
public CodecProfileLevel[] profileLevels
具体定义参见:OMX_Video.h
Profile:
Defined in the OpenMAX IL specs, depending on the type of media this can be OMX_VIDEO_AVCPROFILETYPE
, OMX_VIDEO_H263PROFILETYPE
, OMX_VIDEO_MPEG4PROFILETYPE
, OMX_VIDEO_VP8PROFILETYPE
or OMX_VIDEO_VP9PROFILETYPE
.
OMX_VIDEO_AVCPROFILETYPE
定义如下:
typedef enum OMX_VIDEO_AVCPROFILETYPE {
OMX_VIDEO_AVCProfileBaseline = 0x01, /**< Baseline profile */
OMX_VIDEO_AVCProfileMain = 0x02, /**< Main profile */
OMX_VIDEO_AVCProfileExtended = 0x04, /**< Extended profile */
OMX_VIDEO_AVCProfileHigh = 0x08, /**< High profile */
OMX_VIDEO_AVCProfileHigh10 = 0x10, /**< High 10 profile */
OMX_VIDEO_AVCProfileHigh422 = 0x20, /**< High 4:2:2 profile */
OMX_VIDEO_AVCProfileHigh444 = 0x40, /**< High 4:4:4 profile */
OMX_VIDEO_AVCProfileKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_VIDEO_AVCProfileVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_VIDEO_AVCProfileMax = 0x7FFFFFFF
} OMX_VIDEO_AVCPROFILETYPE;
Level:
Defined in the OpenMAX IL specs, depending on the type of media this can be OMX_VIDEO_AVCLEVELTYPE
, OMX_VIDEO_H263LEVELTYPE
OMX_VIDEO_MPEG4LEVELTYPE
, OMX_VIDEO_VP8LEVELTYPE
or OMX_VIDEO_VP9LEVELTYPE
.
typedef enum OMX_VIDEO_AVCLEVELTYPE {
OMX_VIDEO_AVCLevel1 = 0x01, /**< Level 1 */
OMX_VIDEO_AVCLevel1b = 0x02, /**< Level 1b */
OMX_VIDEO_AVCLevel11 = 0x04, /**< Level 1.1 */
OMX_VIDEO_AVCLevel12 = 0x08, /**< Level 1.2 */
OMX_VIDEO_AVCLevel13 = 0x10, /**< Level 1.3 */
OMX_VIDEO_AVCLevel2 = 0x20, /**< Level 2 */
OMX_VIDEO_AVCLevel21 = 0x40, /**< Level 2.1 */
OMX_VIDEO_AVCLevel22 = 0x80, /**< Level 2.2 */
OMX_VIDEO_AVCLevel3 = 0x100, /**< Level 3 */
OMX_VIDEO_AVCLevel31 = 0x200, /**< Level 3.1 */
OMX_VIDEO_AVCLevel32 = 0x400, /**< Level 3.2 */
OMX_VIDEO_AVCLevel4 = 0x800, /**< Level 4 */
OMX_VIDEO_AVCLevel41 = 0x1000, /**< Level 4.1 */
OMX_VIDEO_AVCLevel42 = 0x2000, /**< Level 4.2 */
OMX_VIDEO_AVCLevel5 = 0x4000, /**< Level 5 */
OMX_VIDEO_AVCLevel51 = 0x8000, /**< Level 5.1 */
OMX_VIDEO_AVCLevel52 = 0x10000, /**< Level 5.2 */
OMX_VIDEO_AVCLevelKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_VIDEO_AVCLevelVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_VIDEO_AVCLevelMax = 0x7FFFFFFF
} OMX_VIDEO_AVCLEVELTYPE;
getEncoderCapabilities added in API level 21
public MediaCodecInfo.EncoderCapabilities getEncoderCapabilities ()
Returns the encoding capabilities or null if this is not an encoder.
Returns
MediaCodecInfo.EncoderCapabilities
getVideoCapabilities added in API level 21
public MediaCodecInfo.VideoCapabilities getVideoCapabilities ()
Returns the video capabilities or null if this is not a video codec.
Returns
MediaCodecInfo.VideoCapabilities
isFormatSupported added in API level 21
Query whether codec supports a given MediaFormat.
Note: On
Build.VERSION_CODES.LOLLIPOP
, format must not contain a frame rate. Use format.setString(MediaFormat.KEY_FRAME_RATE
, null) to clear any existing frame rate setting in the format.
MediaFormat支持情况查看MediaFormat。
只有在API 21及其之后的系统中才支持此项功能。
BITRATE_MODE_CQ
: 0,不控制码率,尽最大可能保证图像质量BITRATE_MODE_VBR
: 1,动态码率BITRATE_MODE_CBR
: 2,固定码率isBitrateModeSupported added in API level 21
boolean isBitrateModeSupported(int mode)
Query whether a bitrate mode is supported.
getComplexityRange added in API level 21
public Range getComplexityRange ()
Returns the supported range of encoder complexity values.
Some codecs may support multiple complexity levels, where higher complexity values use more encoder tools (e.g. perform more intensive calculations) to improve the quality or the compression ratio. Use a lower value to save power and/or time. — 笔者注:瞎哔哔半天,其实返回结果都是0.