Class EncoderUtil

  • public final class EncoderUtil
    extends Object
    Utility methods for MediaCodec encoders.
    • Method Detail

      • getSupportedEncoders

        public static ImmutableList<MediaCodecInfo> getSupportedEncoders​(String mimeType)
        Returns a list of encoders that support the given mimeType, or an empty list if there is none.
      • getClosestSupportedResolution

        public static Pair<Integer,​Integer> getClosestSupportedResolution​(MediaCodecInfo encoderInfo,
                                                                                String mimeType,
                                                                                int width,
                                                                                int height)
        Finds the encoder's closest supported resolution from the given resolution.

        The input resolution is returned, if it is supported by the encoder.

        The resolution will be clamped to the encoder's range of supported resolutions, and adjusted to the encoder's size alignment. 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.

        encoderInfo - The MediaCodecInfo of the encoder.
        mimeType - The output MIME type.
        width - The original width.
        height - The original height.
        A Pair of width and height, or null if unable to find a fix.
      • isProfileLevelSupported

        public static boolean isProfileLevelSupported​(MediaCodecInfo encoderInfo,
                                                      String mimeType,
                                                      int profile,
                                                      int level)
        Returns whether the encoder supports the given profile and level.
      • getClosestSupportedBitrate

        public static int getClosestSupportedBitrate​(MediaCodecInfo encoderInfo,
                                                     String mimeType,
                                                     int bitrate)
        Finds the encoder's closest supported bitrate from the given bitrate.