Android MediaCodec参数笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiyanlgu/article/details/80929845

1. Supported media formats

Supported Codecs

Codec Support Table

从上表上看编码方面:H264仅支持到Main Profile,H265暂时不支持。
但是平台商的部分高端芯片已经支持H264 HP,H265编码。

2. MediaCodecInfo

提供MediaCodec在设备上的支持信息。

获取MediaCodecInfo:

 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

3. CodecCapabilities

设备对MediaCodec支持的信息基本都在这里,比如BitrateMode,Profile等

3.1 createFromProfileLevel

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.

3.2 profileLevels

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定义如下:

  • 1 : AVCProfileBaseline, AVCLevel1
  • 2 : AVCProfileMain
  • 8 : AVCProfileHigh
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;

3.3 getEncoderCapabilities

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

3.4 getVideoCapabilities

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

3.5 isFormatSupported

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。

3. EncoderCapabilities

只有在API 21及其之后的系统中才支持此项功能。

3.1 BirateMode

  • 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<Integer> 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.

4.VideoCapabilities

主要用于检查宽高,FPS,Bitrate的设置是否合理。
这里写图片描述

5.MediaFormat

MediaFormat Support

6.参考文献

猜你喜欢

转载自blog.csdn.net/xiyanlgu/article/details/80929845
今日推荐