diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java index 51d4d15782..b41e4e99ea 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/DefaultEncoderFactory.java @@ -30,6 +30,7 @@ import android.media.MediaFormat; import android.util.Pair; import android.util.Size; import androidx.annotation.Nullable; +import androidx.media3.common.ColorInfo; import androidx.media3.common.Format; import androidx.media3.common.MimeTypes; import androidx.media3.common.util.Log; @@ -278,8 +279,19 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { } MediaFormatUtil.maybeSetColorInfo(mediaFormat, encoderSupportedFormat.colorInfo); - mediaFormat.setInteger( - MediaFormat.KEY_COLOR_FORMAT, supportedVideoEncoderSettings.colorProfile); + if (Util.SDK_INT >= 31 && ColorInfo.isHdr(format.colorInfo)) { + if (EncoderUtil.getSupportedColorFormats(encoderInfo, mimeType) + .contains(MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010)) { + mediaFormat.setInteger( + MediaFormat.KEY_COLOR_FORMAT, + MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010); + } else { + throw createTransformationException(format); + } + } else { + mediaFormat.setInteger( + MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface); + } if (Util.SDK_INT >= 25) { mediaFormat.setFloat( diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoEncoderSettings.java b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoEncoderSettings.java index 536e9fdb1c..d8c42784d1 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoEncoderSettings.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoEncoderSettings.java @@ -41,9 +41,6 @@ public final class VideoEncoderSettings { /** A value for various fields to indicate that the field's value is unknown or not applicable. */ public static final int NO_VALUE = Format.NO_VALUE; - /** The default encoding color profile. */ - public static final int DEFAULT_COLOR_PROFILE = - MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface; /** The default I-frame interval in seconds. */ public static final float DEFAULT_I_FRAME_INTERVAL_SECONDS = 1.0f; @@ -74,7 +71,6 @@ public final class VideoEncoderSettings { private @BitrateMode int bitrateMode; private int profile; private int level; - private int colorProfile; private float iFrameIntervalSeconds; private int operatingRate; private int priority; @@ -86,7 +82,6 @@ public final class VideoEncoderSettings { this.bitrateMode = BITRATE_MODE_VBR; this.profile = NO_VALUE; this.level = NO_VALUE; - this.colorProfile = DEFAULT_COLOR_PROFILE; this.iFrameIntervalSeconds = DEFAULT_I_FRAME_INTERVAL_SECONDS; this.operatingRate = NO_VALUE; this.priority = NO_VALUE; @@ -97,7 +92,6 @@ public final class VideoEncoderSettings { this.bitrateMode = videoEncoderSettings.bitrateMode; this.profile = videoEncoderSettings.profile; this.level = videoEncoderSettings.level; - this.colorProfile = videoEncoderSettings.colorProfile; this.iFrameIntervalSeconds = videoEncoderSettings.iFrameIntervalSeconds; this.operatingRate = videoEncoderSettings.operatingRate; this.priority = videoEncoderSettings.priority; @@ -152,21 +146,6 @@ public final class VideoEncoderSettings { return this; } - /** - * Sets {@link VideoEncoderSettings#colorProfile}. The default value is {@link - * #DEFAULT_COLOR_PROFILE}. - * - *

The value must be one of the {@code COLOR_*} constants defined in {@link - * MediaCodecInfo.CodecCapabilities}. - * - * @param colorProfile The {@link VideoEncoderSettings#colorProfile}. - * @return This builder. - */ - public Builder setColorProfile(int colorProfile) { - this.colorProfile = colorProfile; - return this; - } - /** * Sets {@link VideoEncoderSettings#iFrameIntervalSeconds}. The default value is {@link * #DEFAULT_I_FRAME_INTERVAL_SECONDS}. @@ -221,7 +200,6 @@ public final class VideoEncoderSettings { bitrateMode, profile, level, - colorProfile, iFrameIntervalSeconds, operatingRate, priority, @@ -237,8 +215,6 @@ public final class VideoEncoderSettings { public final int profile; /** The encoding level. */ public final int level; - /** The encoding color profile. */ - public final int colorProfile; /** The encoding I-Frame interval in seconds. */ public final float iFrameIntervalSeconds; /** The encoder {@link MediaFormat#KEY_OPERATING_RATE operating rate}. */ @@ -253,7 +229,6 @@ public final class VideoEncoderSettings { int bitrateMode, int profile, int level, - int colorProfile, float iFrameIntervalSeconds, int operatingRate, int priority, @@ -262,7 +237,6 @@ public final class VideoEncoderSettings { this.bitrateMode = bitrateMode; this.profile = profile; this.level = level; - this.colorProfile = colorProfile; this.iFrameIntervalSeconds = iFrameIntervalSeconds; this.operatingRate = operatingRate; this.priority = priority; @@ -289,7 +263,6 @@ public final class VideoEncoderSettings { && bitrateMode == that.bitrateMode && profile == that.profile && level == that.level - && colorProfile == that.colorProfile && iFrameIntervalSeconds == that.iFrameIntervalSeconds && operatingRate == that.operatingRate && priority == that.priority @@ -303,7 +276,6 @@ public final class VideoEncoderSettings { result = 31 * result + bitrateMode; result = 31 * result + profile; result = 31 * result + level; - result = 31 * result + colorProfile; result = 31 * result + Float.floatToIntBits(iFrameIntervalSeconds); result = 31 * result + operatingRate; result = 31 * result + priority;