-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frame Extractor HDR: tone map to SDR
Support extracting frames from HDR input by tone mapping to SDR (BT.709). ExperimentalFrameExtractor must be public because HDR tests live in a different package. PiperOrigin-RevId: 699994112
- Loading branch information
1 parent
0d8f1d5
commit bb20eb4
Showing
3 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ransformer/src/androidTest/java/androidx/media3/transformer/mh/FrameExtractorHdrTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package androidx.media3.transformer.mh; | ||
|
||
import static androidx.media3.test.utils.BitmapPixelTestUtil.maybeSaveTestBitmap; | ||
import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmap; | ||
import static androidx.media3.test.utils.TestUtil.assertBitmapsAreSimilar; | ||
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_COLOR_TEST_1080P_HLG10; | ||
import static androidx.media3.transformer.mh.HdrCapabilitiesUtil.assumeDeviceSupportsOpenGlToneMapping; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import androidx.media3.common.MediaItem; | ||
import androidx.media3.transformer.ExperimentalFrameExtractor; | ||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestName; | ||
import org.junit.runner.RunWith; | ||
|
||
/** End-to-end HDR instrumentation test for {@link ExperimentalFrameExtractor}. */ | ||
@RunWith(AndroidJUnit4.class) | ||
public class FrameExtractorHdrTest { | ||
// This file is generated on a Pixel 7, because the emulator isn't able to decode HLG to generate | ||
// this file. | ||
private static final String TONE_MAP_HLG_TO_SDR_PNG_ASSET_PATH = | ||
"test-generated-goldens/sample_mp4_first_frame/electrical_colors/tone_map_hlg_to_sdr.png"; | ||
private static final long TIMEOUT_SECONDS = 10; | ||
private static final float PSNR_THRESHOLD = 25f; | ||
|
||
@Rule public final TestName testName = new TestName(); | ||
|
||
private final Context context = ApplicationProvider.getApplicationContext(); | ||
|
||
private String testId; | ||
private @MonotonicNonNull ExperimentalFrameExtractor frameExtractor; | ||
|
||
@Before | ||
public void setUpTestId() { | ||
testId = testName.getMethodName(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
if (frameExtractor != null) { | ||
frameExtractor.release(); | ||
} | ||
} | ||
|
||
@Test | ||
public void extractFrame_oneFrameHlg_returnsToneMappedFrame() throws Exception { | ||
assumeDeviceSupportsOpenGlToneMapping(testId, MP4_ASSET_COLOR_TEST_1080P_HLG10.videoFormat); | ||
frameExtractor = | ||
new ExperimentalFrameExtractor( | ||
context, | ||
new ExperimentalFrameExtractor.Configuration.Builder().build(), | ||
MediaItem.fromUri(MP4_ASSET_COLOR_TEST_1080P_HLG10.uri), | ||
/* effects= */ ImmutableList.of()); | ||
|
||
ListenableFuture<ExperimentalFrameExtractor.Frame> frameFuture = | ||
frameExtractor.getFrame(/* positionMs= */ 0); | ||
ExperimentalFrameExtractor.Frame frame = frameFuture.get(TIMEOUT_SECONDS, SECONDS); | ||
Bitmap actualBitmap = frame.bitmap; | ||
Bitmap expectedBitmap = readBitmap(TONE_MAP_HLG_TO_SDR_PNG_ASSET_PATH); | ||
maybeSaveTestBitmap(testId, /* bitmapLabel= */ "actual", actualBitmap, /* path= */ null); | ||
|
||
assertThat(frame.presentationTimeMs).isEqualTo(0); | ||
assertBitmapsAreSimilar(expectedBitmap, actualBitmap, PSNR_THRESHOLD); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters