From db78a87fdcb095fa6520f3c1bd8b5b419d33de50 Mon Sep 17 00:00:00 2001 From: hschlueter Date: Wed, 13 Jul 2022 17:20:33 +0000 Subject: [PATCH] Use COLOR_Format32bitABGR2101010 for HDR encoder configuration. Also remove VideoEncoderSettings.colorProfile as there are no concrete use cases for customizing this and it clashes with picking the color format automatically based on SDR vs. HDR. PiperOrigin-RevId: 460746987 --- .../transformer/DefaultEncoderFactory.java | 16 +++++++++-- .../transformer/VideoEncoderSettings.java | 28 ------------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java index aabf78e624..90bb6f99af 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java @@ -35,6 +35,7 @@ import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.MediaFormatUtil; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; +import com.google.android.exoplayer2.video.ColorInfo; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; @@ -276,8 +277,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/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoEncoderSettings.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoEncoderSettings.java index c5034dea2f..b5d674f7b8 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoEncoderSettings.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoEncoderSettings.java @@ -39,9 +39,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; @@ -72,7 +69,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; @@ -84,7 +80,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; @@ -95,7 +90,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; @@ -150,21 +144,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}. @@ -219,7 +198,6 @@ public final class VideoEncoderSettings { bitrateMode, profile, level, - colorProfile, iFrameIntervalSeconds, operatingRate, priority, @@ -235,8 +213,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}. */ @@ -251,7 +227,6 @@ public final class VideoEncoderSettings { int bitrateMode, int profile, int level, - int colorProfile, float iFrameIntervalSeconds, int operatingRate, int priority, @@ -260,7 +235,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; @@ -287,7 +261,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 @@ -301,7 +274,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;