1# Obtaining Supported Codecs 2 3Different devices support different codecs. Before invoking or configuring a codec, you need to query the codec specifications supported. 4 5You can call the native APIs provided by the **AVCapability** module to check whether related capabilities are supported. 6 7## How to Develop 8 9Read [AVCapability](../reference/native-apis/_a_v_capability.md) for the API reference. 10 111. Obtain a codec capability instance. 12 13 ```c 14 // Obtain a codec capability instance based on the MIME type and encoder flag. 15 OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_VIDEO_AVC, false); 16 17 // Obtain a codec capability instance based on the MIME type, encoder flag, and software/hardware type. 18 OH_AVCapability *capability = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, false, SOFTWARE); 19 ``` 20 212. Query the specifications provided by the codec capability instance. 22 ```c 23 // Check whether the codec capability instance describes a hardware codec. 24 bool isHardware = OH_AVCapability_IsHardware(capability); 25 26 // Obtain the codec name of the codec capability instance. 27 const char *codecName = OH_AVCapability_GetName(capability); 28 29 // Obtain the maximum number of instances supported by the codec capability instance. 30 int32_t maxSupportedInstances = OH_AVCapability_GetMaxSupportedInstances(capability); 31 32 // Obtain the bit rate range supported by the encoder. 33 OH_AVRange bitrateRange; 34 int32_t ret = OH_AVCapability_GetEncoderBitrateRange(capability, &bitrateRange); 35 if (ret != AV_ERR_OK) { 36 // Exception processing. 37 } 38 39 // Check whether the codec capability instance supports a specific bit rate mode. 40 bool isEncoderBitrateModeSupported = OH_AVCapability_IsEncoderBitrateModeSupported(capability, BITRATE_MODE_CBR); 41 42 // Obtain the quality range supported by the encoder. 43 OH_AVRange qualityRange; 44 int32_t ret = OH_AVCapability_GetEncoderQualityRange(capability, &qualityRange); 45 if (ret != AV_ERR_OK) { 46 // Exception processing. 47 } 48 49 // Obtain the complexity range supported by the encoder. 50 OH_AVRange complexityRange; 51 int32_t ret = OH_AVCapability_GetEncoderComplexityRange(capability, &complexityRange); 52 if (ret != AV_ERR_OK) { 53 // Exception processing. 54 } 55 56 // Obtain the supported audio sampling rates. 57 const int32_t *sampleRates; 58 uint32_t sampleRateNum = 0; 59 int32_t ret = OH_AVCapability_GetAudioSupportedSampleRates(capability, &sampleRates, &sampleRateNum); 60 if (ret != AV_ERR_OK) { 61 // Exception processing. 62 } 63 64 // Obtain the number of audio channels supported. 65 OH_AVRange channelCountRange; 66 int32_t ret = OH_AVCapability_GetAudioChannelCountRange(capability, &channelCountRange); 67 if (ret != AV_ERR_OK) { 68 // Exception processing. 69 } 70 71 // Obtain the width alignment value supported. 72 int32_t widthAlignment; 73 int32_t ret = OH_AVCapability_GetVideoWidthAlignment(capability, &widthAlignment); 74 if (ret != AV_ERR_OK) { 75 // Exception processing. 76 } 77 78 // Obtain the height alignment value supported. 79 int32_t heightAlignment; 80 int32_t ret = OH_AVCapability_GetVideoHeightAlignment(capability, &heightAlignment); 81 if (ret != AV_ERR_OK) { 82 // Exception processing. 83 } 84 85 // Obtain the width range when the height is 1080. 86 OH_AVRange widthRange; 87 int32_t ret = OH_AVCapability_GetVideoWidthRangeForHeight(capability, 1080, &widthRange); 88 if (ret != AV_ERR_OK) { 89 // Exception processing. 90 } 91 92 // Obtain the height range when the width is 1920. 93 OH_AVRange heightRange; 94 int32_t ret = OH_AVCapability_GetVideoHeightRangeForWidth(capability, 1920, &heightRange); 95 if (ret != AV_ERR_OK) { 96 // Exception processing. 97 } 98 99 // Obtain the width range supported. 100 OH_AVRange widthRange; 101 int32_t ret = OH_AVCapability_GetVideoWidthRange(capability, &widthRange); 102 if (ret != AV_ERR_OK) { 103 // Exception processing. 104 } 105 106 // Obtain the height range supported. 107 OH_AVRange heightRange; 108 int32_t ret = OH_AVCapability_GetVideoWidthRange(capability, &heightRange); 109 if (ret != AV_ERR_OK) { 110 // Exception processing. 111 } 112 113 // Check whether the codec capability instance supports the 1080p resolution. 114 bool isVideoSizeSupported = OH_AVCapability_IsVideoSizeSupported(capability, 1920, 1080); 115 116 // Obtain the video frame rate range supported. 117 OH_AVRange frameRateRange; 118 int32_t ret = OH_AVCapability_GetVideoFrameRateRange(capability, &frameRateRange); 119 if (ret != AV_ERR_OK) { 120 // Exception processing. 121 } 122 123 // Obtain the video frame rate range when the resolution is 1920 x 1080. 124 OH_AVRange frameRateRange; 125 int32_t ret = OH_AVCapability_GetVideoFrameRateRangeForSize(capability, 1920, 1080, &frameRateRange); 126 if (ret != AV_ERR_OK) { 127 // Exception processing. 128 } 129 130 // Check whether the codec capability instance supports the scenario where the resolution is 1080p and the frame rate is 30 fps. 131 bool areVideoSizeAndFrameRateSupported = OH_AVCapability_AreVideoSizeAndFrameRateSupported(capability, 1920, 1080, 30); 132 133 // Obtain the supported color formats and the number of supported color formats. 134 const int32_t *pixFormats; 135 uint32_t pixFormatNum = 0; 136 int32_t ret = OH_AVCapability_GetVideoSupportedPixelFormats(capability, &pixFormats, &pixFormatNum); 137 if (ret != AV_ERR_OK) { 138 // Exception processing. 139 } 140 141 // Obtain the profiles supported. 142 const int32_t *profiles; 143 uint32_t profileNum = 0; 144 int32_t ret = OH_AVCapability_GetSupportedProfiles(capability, &profiles, &profileNum); 145 if (ret != AV_ERR_OK) { 146 // Exception processing. 147 } 148 149 // Obtain the level range of a specific profile. 150 const int32_t *levels; 151 uint32_t levelNum = 0; 152 int32_t ret = OH_AVCapability_GetSupportedLevelsForProfile(capability, 0, &levels, &levelNum); 153 154 // Check whether the codec capability instance supports the combination of a profile and level. 155 bool areProfileAndLevelSupported = OH_AVCapability_AreProfileAndLevelSupported(capability, AVC_PROFILE_BASELINE, 1); 156 ``` 157