@UnstableApi
class EncoderUtil


Utility methods for MediaCodec encoders.

Summary

Constants

const Int

A value to indicate the encoding level is not set.

Public functions

synchronized java-static Unit

Clears the cached list of encoders.

java-static String?
findCodecForFormat(format: MediaFormat!, isDecoder: Boolean)

Finds a MediaCodec that supports the MediaFormat, or null if none is found.

java-static Int
findHighestSupportedEncodingLevel(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!,
    profile: Int
)

Finds the highest supported encoding level given a profile.

java-static ImmutableSet<Int!>!
findSupportedEncodingProfiles(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!
)

Returns a set of supported encoding profiles for the given encoder and MIME type.

java-static ImmutableList<Int!>!
getCodecProfilesForHdrFormat(
    mimeType: String!,
    @C.ColorTransfer colorTransfer: 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).

java-static Int
@RequiresApi(value = 23)
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 MIME type.

java-static ImmutableList<Int!>!
getSupportedColorFormats(encoderInfo: MediaCodecInfo!, mimeType: String!)

Returns a list of supported color formats for the given encoder and MIME type.

synchronized java-static ImmutableList<MediaCodecInfo!>!

Returns a list of encoders that support the given mimeType, or an empty list if there is none.

java-static 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.

java-static Range<Int!>!
getSupportedHeights(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!,
    width: Int
)

Returns a Range of supported heights for the given encoder, MIME type and width.

synchronized java-static ImmutableSet<String!>!

Returns a list of MIME types that can be encoded.

java-static Size?
getSupportedResolution(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!,
    width: Int,
    height: Int
)

Finds an encoder's supported resolution from a given resolution.

java-static Pair<Range<Int!>!, Range<Int!>!>!
getSupportedResolutionRanges(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!
)

Returns a Pair of supported width and height ranges for the given encoder and MIME type.

java-static Boolean
isBitrateModeSupported(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!,
    bitrateMode: Int
)

Returns whether the bitrate mode is supported by the encoder.

java-static Boolean
isFeatureSupported(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!,
    featureName: String!
)

Returns whether a given feature is supported.

java-static Boolean
isHardwareAccelerated(encoderInfo: MediaCodecInfo!, mimeType: String!)

Checks if a codec is hardware-accelerated.

java-static Boolean
isSizeSupported(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!,
    width: Int,
    height: Int
)

Returns whether the encoder supports the given resolution.

Constants

LEVEL_UNSET

const val LEVEL_UNSET = -1: Int

A value to indicate the encoding level is not set.

Public functions

clearCachedEncoders

@VisibleForTesting
synchronized java-static fun clearCachedEncoders(): Unit

Clears the cached list of encoders.

findCodecForFormat

java-static fun findCodecForFormat(format: MediaFormat!, isDecoder: Boolean): String?

Finds a MediaCodec that supports the MediaFormat, or null if none is found.

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 encoderInfo.

mimeType: String!

The MIME type.

profile: Int

The encoding profile.

Returns
Int

The highest supported encoding level, as documented in , or LEVEL_UNSET if the profile is not supported.

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.

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

@RequiresApi(value = 23)
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 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, MIME type and width.

Throws
java.lang.IllegalArgumentException

When the width is not in the range of supported widths.

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 MediaCodecInfo of the encoder.

mimeType: String!

The output MIME type.

width: Int

The original width.

height: Int

The original height.

Returns
Size?

A supported resolution, or null if unable to find a fallback.

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

isSizeSupported

java-static fun isSizeSupported(
    encoderInfo: MediaCodecInfo!,
    mimeType: String!,
    width: Int,
    height: Int
): Boolean

Returns whether the encoder supports the given resolution.