diff --git a/library/common/src/main/java/com/google/android/exoplayer2/video/ColorInfo.java b/library/common/src/main/java/com/google/android/exoplayer2/video/ColorInfo.java index cfb9321dce..b16c996f3f 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/video/ColorInfo.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/video/ColorInfo.java @@ -32,6 +32,15 @@ import org.checkerframework.dataflow.qual.Pure; /** Stores color info. */ public final class ColorInfo implements Bundleable { + + /** Color info representing SDR BT.709 limited range, which is a common SDR video color format. */ + public static final ColorInfo SDR_BT709_LIMITED = + new ColorInfo( + C.COLOR_SPACE_BT709, + C.COLOR_RANGE_LIMITED, + C.COLOR_TRANSFER_SDR, + /* hdrStaticInfo= */ null); + /** * Returns the {@link C.ColorSpace} corresponding to the given ISO color primary code, as per * table A.7.21.1 in Rec. ITU-T T.832 (03/2009), or {@link Format#NO_VALUE} if no mapping can be diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java index e5168219dc..9e57188122 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java @@ -384,6 +384,11 @@ import org.checkerframework.dataflow.qual.Pure; } boolean isInputToneMapped = ColorInfo.isHdr(inputFormat.colorInfo) && !isHdrEditingEnabled(); + // When tone-mapping HDR to SDR is enabled, assume we get BT.709 to avoid having the encoder + // populate default color info, which depends on the resolution. + // TODO(b/237674316): Get the color info from the decoder output media format instead. + ColorInfo outputColorInfo = + isInputToneMapped ? ColorInfo.SDR_BT709_LIMITED : inputFormat.colorInfo; Format requestedEncoderFormat = new Format.Builder() .setWidth(requestedWidth) @@ -391,7 +396,7 @@ import org.checkerframework.dataflow.qual.Pure; .setRotationDegrees(0) .setFrameRate(inputFormat.frameRate) .setSampleMimeType(requestedOutputMimeType) - .setColorInfo(isInputToneMapped ? null : inputFormat.colorInfo) + .setColorInfo(outputColorInfo) .build(); encoder =