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
This commit is contained in:
hschlueter 2022-07-13 17:20:33 +00:00 committed by Rohit Singh
parent adc50515e9
commit 7954eeb3c2
2 changed files with 14 additions and 30 deletions

View File

@ -30,6 +30,7 @@ import android.media.MediaFormat;
import android.util.Pair; import android.util.Pair;
import android.util.Size; import android.util.Size;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
@ -278,8 +279,19 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
} }
MediaFormatUtil.maybeSetColorInfo(mediaFormat, encoderSupportedFormat.colorInfo); MediaFormatUtil.maybeSetColorInfo(mediaFormat, encoderSupportedFormat.colorInfo);
if (Util.SDK_INT >= 31 && ColorInfo.isHdr(format.colorInfo)) {
if (EncoderUtil.getSupportedColorFormats(encoderInfo, mimeType)
.contains(MediaCodecInfo.CodecCapabilities.COLOR_Format32bitABGR2101010)) {
mediaFormat.setInteger( mediaFormat.setInteger(
MediaFormat.KEY_COLOR_FORMAT, supportedVideoEncoderSettings.colorProfile); 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) { if (Util.SDK_INT >= 25) {
mediaFormat.setFloat( mediaFormat.setFloat(

View File

@ -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. */ /** 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; 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. */ /** The default I-frame interval in seconds. */
public static final float DEFAULT_I_FRAME_INTERVAL_SECONDS = 1.0f; public static final float DEFAULT_I_FRAME_INTERVAL_SECONDS = 1.0f;
@ -74,7 +71,6 @@ public final class VideoEncoderSettings {
private @BitrateMode int bitrateMode; private @BitrateMode int bitrateMode;
private int profile; private int profile;
private int level; private int level;
private int colorProfile;
private float iFrameIntervalSeconds; private float iFrameIntervalSeconds;
private int operatingRate; private int operatingRate;
private int priority; private int priority;
@ -86,7 +82,6 @@ public final class VideoEncoderSettings {
this.bitrateMode = BITRATE_MODE_VBR; this.bitrateMode = BITRATE_MODE_VBR;
this.profile = NO_VALUE; this.profile = NO_VALUE;
this.level = NO_VALUE; this.level = NO_VALUE;
this.colorProfile = DEFAULT_COLOR_PROFILE;
this.iFrameIntervalSeconds = DEFAULT_I_FRAME_INTERVAL_SECONDS; this.iFrameIntervalSeconds = DEFAULT_I_FRAME_INTERVAL_SECONDS;
this.operatingRate = NO_VALUE; this.operatingRate = NO_VALUE;
this.priority = NO_VALUE; this.priority = NO_VALUE;
@ -97,7 +92,6 @@ public final class VideoEncoderSettings {
this.bitrateMode = videoEncoderSettings.bitrateMode; this.bitrateMode = videoEncoderSettings.bitrateMode;
this.profile = videoEncoderSettings.profile; this.profile = videoEncoderSettings.profile;
this.level = videoEncoderSettings.level; this.level = videoEncoderSettings.level;
this.colorProfile = videoEncoderSettings.colorProfile;
this.iFrameIntervalSeconds = videoEncoderSettings.iFrameIntervalSeconds; this.iFrameIntervalSeconds = videoEncoderSettings.iFrameIntervalSeconds;
this.operatingRate = videoEncoderSettings.operatingRate; this.operatingRate = videoEncoderSettings.operatingRate;
this.priority = videoEncoderSettings.priority; this.priority = videoEncoderSettings.priority;
@ -152,21 +146,6 @@ public final class VideoEncoderSettings {
return this; return this;
} }
/**
* Sets {@link VideoEncoderSettings#colorProfile}. The default value is {@link
* #DEFAULT_COLOR_PROFILE}.
*
* <p>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 * Sets {@link VideoEncoderSettings#iFrameIntervalSeconds}. The default value is {@link
* #DEFAULT_I_FRAME_INTERVAL_SECONDS}. * #DEFAULT_I_FRAME_INTERVAL_SECONDS}.
@ -221,7 +200,6 @@ public final class VideoEncoderSettings {
bitrateMode, bitrateMode,
profile, profile,
level, level,
colorProfile,
iFrameIntervalSeconds, iFrameIntervalSeconds,
operatingRate, operatingRate,
priority, priority,
@ -237,8 +215,6 @@ public final class VideoEncoderSettings {
public final int profile; public final int profile;
/** The encoding level. */ /** The encoding level. */
public final int level; public final int level;
/** The encoding color profile. */
public final int colorProfile;
/** The encoding I-Frame interval in seconds. */ /** The encoding I-Frame interval in seconds. */
public final float iFrameIntervalSeconds; public final float iFrameIntervalSeconds;
/** The encoder {@link MediaFormat#KEY_OPERATING_RATE operating rate}. */ /** The encoder {@link MediaFormat#KEY_OPERATING_RATE operating rate}. */
@ -253,7 +229,6 @@ public final class VideoEncoderSettings {
int bitrateMode, int bitrateMode,
int profile, int profile,
int level, int level,
int colorProfile,
float iFrameIntervalSeconds, float iFrameIntervalSeconds,
int operatingRate, int operatingRate,
int priority, int priority,
@ -262,7 +237,6 @@ public final class VideoEncoderSettings {
this.bitrateMode = bitrateMode; this.bitrateMode = bitrateMode;
this.profile = profile; this.profile = profile;
this.level = level; this.level = level;
this.colorProfile = colorProfile;
this.iFrameIntervalSeconds = iFrameIntervalSeconds; this.iFrameIntervalSeconds = iFrameIntervalSeconds;
this.operatingRate = operatingRate; this.operatingRate = operatingRate;
this.priority = priority; this.priority = priority;
@ -289,7 +263,6 @@ public final class VideoEncoderSettings {
&& bitrateMode == that.bitrateMode && bitrateMode == that.bitrateMode
&& profile == that.profile && profile == that.profile
&& level == that.level && level == that.level
&& colorProfile == that.colorProfile
&& iFrameIntervalSeconds == that.iFrameIntervalSeconds && iFrameIntervalSeconds == that.iFrameIntervalSeconds
&& operatingRate == that.operatingRate && operatingRate == that.operatingRate
&& priority == that.priority && priority == that.priority
@ -303,7 +276,6 @@ public final class VideoEncoderSettings {
result = 31 * result + bitrateMode; result = 31 * result + bitrateMode;
result = 31 * result + profile; result = 31 * result + profile;
result = 31 * result + level; result = 31 * result + level;
result = 31 * result + colorProfile;
result = 31 * result + Float.floatToIntBits(iFrameIntervalSeconds); result = 31 * result + Float.floatToIntBits(iFrameIntervalSeconds);
result = 31 * result + operatingRate; result = 31 * result + operatingRate;
result = 31 * result + priority; result = 31 * result + priority;