EncoderUtil
@UnstableApi
class EncoderUtil
Utility methods for MediaCodec encoders.
Summary
Constants |
|
|---|---|
const Int |
LEVEL_UNSET = -1A value to indicate the encoding level is not set. |
Public functions |
|
|---|---|
synchronized java-static Unit |
Clears the cached list of encoders. |
java-static Int |
findHighestSupportedEncodingLevel(Finds the highest supported encoding level given a profile. |
java-static ImmutableSet<Int!>! |
findSupportedEncodingProfiles(Returns a |
java-static Int |
getClosestSupportedSampleRate(Returns the sample rate supported by the provided |
java-static ImmutableList<Int!>! |
getCodecProfilesForHdrFormat(Returns the |
java-static Int |
getMaxSupportedInstances(encoderInfo: MediaCodecInfo!, mimeType: String!)Returns the number of max number of the supported concurrent codec instances. |
java-static Range<Int!>! |
getSupportedBitrateRange(encoderInfo: MediaCodecInfo!, mimeType: String!)Returns the range of supported bitrates for the given |
java-static ImmutableList<Int!>! |
getSupportedColorFormats(encoderInfo: MediaCodecInfo!, mimeType: String!)Returns a |
synchronized java-static ImmutableList<MediaCodecInfo!>! |
getSupportedEncoders(mimeType: String!)Returns a list of |
java-static ImmutableList<MediaCodecInfo!>! |
getSupportedEncodersForHdrEditing(mimeType: String!, colorInfo: ColorInfo?)Returns a list of |
java-static Range<Int!>! |
getSupportedHeights(Returns a |
synchronized java-static ImmutableSet<String!>! |
Returns a list of |
java-static Size? |
getSupportedResolution(Finds an |
java-static Pair<Range<Int!>!, Range<Int!>!>! |
getSupportedResolutionRanges(Returns a |
java-static Boolean |
isBitrateModeSupported(Returns whether the bitrate mode is supported by the encoder. |
java-static Boolean |
isFeatureSupported(Returns whether a given feature is supported. |
java-static Boolean |
isHardwareAccelerated(encoderInfo: MediaCodecInfo!, mimeType: String!)Checks if a |
java-static Boolean |
@RequiresApi(value = 33)Returns whether HDR editing with the given |
java-static Boolean |
isSizeSupported(Returns whether the |
Constants
Public functions
clearCachedEncoders
@VisibleForTesting
synchronized java-static fun clearCachedEncoders(): Unit
Clears the cached list of encoders.
findHighestSupportedEncodingLevel
java-static fun findHighestSupportedEncodingLevel(
encoderInfo: MediaCodecInfo!,
mimeType: String!,
profile: Int
): Int
Finds the highest supported encoding level given a profile.
| Parameters | |
|---|---|
encoderInfo: MediaCodecInfo! |
The |
mimeType: String! |
The |
profile: Int |
The encoding profile. |
| Returns | |
|---|---|
Int |
The highest supported encoding level, as documented in |
findSupportedEncodingProfiles
java-static fun findSupportedEncodingProfiles(
encoderInfo: MediaCodecInfo!,
mimeType: String!
): ImmutableSet<Int!>!
Returns a set of supported encoding profiles for the given encoder and MIME type.
getClosestSupportedSampleRate
java-static fun getClosestSupportedSampleRate(
encoderInfo: MediaCodecInfo!,
mimeType: String!,
requestedSampleRate: Int
): Int
Returns the sample rate supported by the provided encoder that is closest to the provided sample rate for a given audio MIME type.
getCodecProfilesForHdrFormat
java-static fun getCodecProfilesForHdrFormat(
mimeType: String!,
@C.ColorTransfer colorTransfer: Int
): ImmutableList<Int!>!
Returns the profile constants that can be used to encode the given HDR format, if supported by the device (this method does not check device capabilities). If multiple profiles are returned, they are ordered by expected level of compatibility, with the most widely compatible profile first.
getMaxSupportedInstances
java-static fun getMaxSupportedInstances(encoderInfo: MediaCodecInfo!, mimeType: String!): Int
Returns the number of max number of the supported concurrent codec instances.
getSupportedBitrateRange
java-static fun getSupportedBitrateRange(encoderInfo: MediaCodecInfo!, mimeType: String!): Range<Int!>!
Returns the range of supported bitrates for the given video MIME type.
getSupportedColorFormats
java-static fun getSupportedColorFormats(encoderInfo: MediaCodecInfo!, mimeType: String!): ImmutableList<Int!>!
Returns a list of supported color formats for the given encoder and MIME type.
getSupportedEncoders
synchronized java-static fun getSupportedEncoders(mimeType: String!): ImmutableList<MediaCodecInfo!>!
Returns a list of encoders that support the given mimeType, or an empty list if there is none.
getSupportedEncodersForHdrEditing
java-static fun getSupportedEncodersForHdrEditing(mimeType: String!, colorInfo: ColorInfo?): ImmutableList<MediaCodecInfo!>!
Returns a list of encoders that support HDR editing for the given mimeType and ColorInfo, or an empty list if the format is unknown or not supported for HDR encoding.
getSupportedHeights
java-static fun getSupportedHeights(
encoderInfo: MediaCodecInfo!,
mimeType: String!,
width: Int
): Range<Int!>!
Returns a Range of supported heights for the given encoder, video MIME type and width.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
When the width is not in the range of |
getSupportedMimeTypes
synchronized java-static fun getSupportedMimeTypes(): ImmutableSet<String!>!
Returns a list of MIME types that can be encoded.
getSupportedResolution
java-static fun getSupportedResolution(
encoderInfo: MediaCodecInfo!,
mimeType: String!,
width: Int,
height: Int
): Size?
Finds an encoder's supported resolution from a given resolution.
The input resolution is returned, if it (after aligning to the encoder's requirement) is supported by the encoder.
The resolution will be adjusted to be within the encoder's range of supported resolutions, and will be aligned to the encoder's alignment requirement. The adjustment process takes into account the original aspect ratio. But the fixed resolution may not preserve the original aspect ratio, depending on the encoder's required size alignment.
| Parameters | |
|---|---|
encoderInfo: MediaCodecInfo! |
The |
mimeType: String! |
The output |
width: Int |
The original width. |
height: Int |
The original height. |
| Returns | |
|---|---|
Size? |
A |
getSupportedResolutionRanges
java-static fun getSupportedResolutionRanges(
encoderInfo: MediaCodecInfo!,
mimeType: String!
): Pair<Range<Int!>!, Range<Int!>!>!
Returns a Pair of supported width and height ranges for the given encoder and video MIME type.
isBitrateModeSupported
java-static fun isBitrateModeSupported(
encoderInfo: MediaCodecInfo!,
mimeType: String!,
bitrateMode: Int
): Boolean
Returns whether the bitrate mode is supported by the encoder.
isFeatureSupported
java-static fun isFeatureSupported(
encoderInfo: MediaCodecInfo!,
mimeType: String!,
featureName: String!
): Boolean
Returns whether a given feature is supported.
isHardwareAccelerated
java-static fun isHardwareAccelerated(encoderInfo: MediaCodecInfo!, mimeType: String!): Boolean
Checks if a codec is hardware-accelerated.
isHdrEditingSupported
@RequiresApi(value = 33)
java-static fun isHdrEditingSupported(
mediaCodecInfo: MediaCodecInfo!,
mimeType: String!,
colorInfo: ColorInfo!
): Boolean
Returns whether HDR editing with the given color transfer is supported by the given encoder.
| Parameters | |
|---|---|
mediaCodecInfo: MediaCodecInfo! |
The encoder. |
mimeType: String! |
The MIME type of the video stream. |
colorInfo: ColorInfo! |
The color info. |
isSizeSupported
java-static fun isSizeSupported(
encoderInfo: MediaCodecInfo!,
mimeType: String!,
width: Int,
height: Int
): Boolean
Returns whether the encoder supports the given resolution for a specific video MIME type.