Effects: Allow BT2020 colors with SDR transfers

Previously, I assumed that SDR contents must be BT709, and HDR contents must be
BT2020. Turns out BT2020 is just wide-gamut, and SDR contents / transfers may be
represented in BT2020 color spaces.

Relax the check, so that we don't throw when valid BT2020 SMPTE 170M contents
are input into effects.

PiperOrigin-RevId: 526668347
This commit is contained in:
huangdarwin 2023-04-24 17:34:45 +01:00 committed by Ian Baker
parent b11dd106ae
commit 324115f6cf
5 changed files with 45 additions and 5 deletions

View File

@ -1087,8 +1087,8 @@ public final class C {
// LINT.IfChange(color_space)
/**
* Video colorspaces. One of {@link Format#NO_VALUE}, {@link #COLOR_SPACE_BT601}, {@link
* #COLOR_SPACE_BT709} or {@link #COLOR_SPACE_BT2020}.
* Video color spaces, also referred to as color standards. One of {@link Format#NO_VALUE}, {@link
* #COLOR_SPACE_BT601}, {@link #COLOR_SPACE_BT709} or {@link #COLOR_SPACE_BT2020}.
*/
@UnstableApi
@Documented

View File

@ -367,9 +367,6 @@ import java.util.List;
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
} else {
glProgram.setIntUniform("uEnableColorTransfer", enableColorTransfers ? GL_TRUE : GL_FALSE);
checkArgument(
outputColorInfo.colorSpace != C.COLOR_SPACE_BT2020,
"Converting from SDR to HDR is not supported.");
checkArgument(inputColorInfo.colorSpace == outputColorInfo.colorSpace);
checkArgument(
outputColorTransfer == C.COLOR_TRANSFER_SDR

View File

@ -101,6 +101,22 @@ public final class AndroidTestUtil {
.setCodecs("avc1.64000D")
.build();
public static final String MP4_ASSET_BT2020_SDR = "asset:///media/mp4/bt2020-sdr.mp4";
public static final Format MP4_ASSET_BT2020_SDR_FORMAT =
new Format.Builder()
.setSampleMimeType(VIDEO_H264)
.setWidth(3840)
.setHeight(2160)
.setFrameRate(29.822f)
.setColorInfo(
new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT2020)
.setColorRange(C.COLOR_RANGE_LIMITED)
.setColorTransfer(C.COLOR_TRANSFER_SDR)
.build())
.setCodecs("avc1.640033")
.build();
public static final String MP4_ASSET_1080P_5_SECOND_HLG10 = "asset:///media/mp4/hlg-1080p.mp4";
public static final Format MP4_ASSET_1080P_5_SECOND_HLG10_FORMAT =
new Format.Builder()

View File

@ -17,6 +17,8 @@ package androidx.media3.transformer.mh;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_4K60_PORTRAIT_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_4K60_PORTRAIT_URI_STRING;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_BT2020_SDR;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_BT2020_SDR_FORMAT;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_SEF_URI_STRING;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI_STRING;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_WITH_INCREASING_TIMESTAMPS_FORMAT;
@ -253,4 +255,29 @@ public class ExportTest {
.build()
.run(testId, editedMediaItem);
}
@Test
public void exportTranscodeBt2020Sdr() throws Exception {
String testId = TAG + "exportBt2020Sdr";
Context context = ApplicationProvider.getApplicationContext();
if (AndroidTestUtil.skipAndLogIfFormatsUnsupported(
context,
testId,
/* inputFormat= */ MP4_ASSET_BT2020_SDR_FORMAT,
/* outputFormat= */ null)) {
return;
}
Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_BT2020_SDR));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleAndRotateTransformation.Builder().setRotationDegrees(45).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(mediaItem).setEffects(effects).build();
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
}
}