mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Add a parameterized android test for single asset exports.
PiperOrigin-RevId: 644740900
This commit is contained in:
parent
4751b80703
commit
f2305cc05c
3 changed files with 138 additions and 7 deletions
|
|
@ -99,6 +99,7 @@ import java.util.Objects;
|
|||
public abstract static class ItemConfig {
|
||||
public final int frameCount;
|
||||
@Nullable public final Format format;
|
||||
// TODO - b/345483531: Modify output format to account for effects (such as presentation).
|
||||
@Nullable public final Format outputFormat;
|
||||
|
||||
protected final Effects effects;
|
||||
|
|
|
|||
|
|
@ -42,12 +42,11 @@ import org.junit.runners.Parameterized.Parameters;
|
|||
// TODO: b/343362776 - Add tests to assert enough silence is generated.
|
||||
// TODO: b/346289922 - Consider checking frame counts with extractors.
|
||||
// TODO: b/345483531 - Add support for asserting on duration for image only sequences.
|
||||
// TODO: b/345483531 - Split single item export tests into a separate class.
|
||||
// TODO: b/345483531 - Generate all permutations of all combinations of input files.
|
||||
|
||||
/** Parameterized end to end {@linkplain EditedMediaItemSequence sequence} export tests. */
|
||||
/** Parameterized end-to-end test for exporting a {@link EditedMediaItemSequence}. */
|
||||
@RunWith(Parameterized.class)
|
||||
public class ParameterizedInputSequenceExportTest {
|
||||
public final class ParameterizedInputSequenceExportTest {
|
||||
private static final SdrImageItemConfig PNG_ITEM =
|
||||
new SdrImageItemConfig(PNG_ASSET, /* frameCount= */ 34);
|
||||
private static final SdrImageItemConfig JPG_ITEM =
|
||||
|
|
@ -68,22 +67,18 @@ public class ParameterizedInputSequenceExportTest {
|
|||
@Parameters(name = "{0}")
|
||||
public static ImmutableList<SequenceConfig> params() {
|
||||
return ImmutableList.of(
|
||||
new SequenceConfig(PNG_ITEM),
|
||||
new SequenceConfig(PNG_ITEM, PNG_ITEM),
|
||||
new SequenceConfig(PNG_ITEM, JPG_ITEM),
|
||||
new SequenceConfig(PNG_ITEM, BT601_ITEM),
|
||||
new SequenceConfig(PNG_ITEM, BT709_ITEM),
|
||||
new SequenceConfig(JPG_ITEM),
|
||||
new SequenceConfig(JPG_ITEM, PNG_ITEM),
|
||||
new SequenceConfig(JPG_ITEM, JPG_ITEM),
|
||||
new SequenceConfig(JPG_ITEM, BT601_ITEM),
|
||||
new SequenceConfig(JPG_ITEM, BT709_ITEM),
|
||||
new SequenceConfig(BT601_ITEM),
|
||||
new SequenceConfig(BT601_ITEM, PNG_ITEM),
|
||||
new SequenceConfig(BT601_ITEM, JPG_ITEM),
|
||||
new SequenceConfig(BT601_ITEM, BT601_ITEM),
|
||||
new SequenceConfig(BT601_ITEM, BT709_ITEM),
|
||||
new SequenceConfig(BT709_ITEM),
|
||||
new SequenceConfig(BT709_ITEM, PNG_ITEM),
|
||||
new SequenceConfig(BT709_ITEM, JPG_ITEM),
|
||||
new SequenceConfig(BT709_ITEM, BT601_ITEM),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
import static androidx.media3.transformer.AndroidTestUtil.BT601_MP4_ASSET;
|
||||
import static androidx.media3.transformer.AndroidTestUtil.JPG_ASSET;
|
||||
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET;
|
||||
import static androidx.media3.transformer.AndroidTestUtil.PNG_ASSET;
|
||||
import static androidx.media3.transformer.AndroidTestUtil.assumeFormatsSupported;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.effect.Presentation;
|
||||
import androidx.media3.effect.RgbFilter;
|
||||
import androidx.media3.transformer.ParameterizedAndroidTestUtil.ItemConfig;
|
||||
import androidx.media3.transformer.ParameterizedAndroidTestUtil.SdrImageItemConfig;
|
||||
import androidx.media3.transformer.ParameterizedAndroidTestUtil.VideoItemConfig;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.io.File;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
/**
|
||||
* Parameterized end-to-end test for exporting a single {@link MediaItem} or {@link
|
||||
* EditedMediaItem}.
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public final class ParameterizedItemExportAndroidTest {
|
||||
private static final SdrImageItemConfig PNG_ITEM =
|
||||
new SdrImageItemConfig(
|
||||
PNG_ASSET,
|
||||
/* frameRate= */ 34,
|
||||
/* durationUs= */ C.MICROS_PER_SECOND,
|
||||
/* effects= */ Effects.EMPTY);
|
||||
private static final SdrImageItemConfig PNG_ITEM_WITH_EFFECTS =
|
||||
new SdrImageItemConfig(
|
||||
PNG_ASSET,
|
||||
/* frameRate= */ 34,
|
||||
/* durationUs= */ C.MICROS_PER_SECOND,
|
||||
/* effects= */ new Effects(
|
||||
/* audioProcessors= */ ImmutableList.of(),
|
||||
ImmutableList.of(RgbFilter.createGrayscaleFilter())));
|
||||
private static final SdrImageItemConfig JPG_ITEM =
|
||||
new SdrImageItemConfig(
|
||||
JPG_ASSET,
|
||||
/* frameRate= */ 41,
|
||||
/* durationUs= */ C.MICROS_PER_SECOND,
|
||||
/* effects= */ Effects.EMPTY);
|
||||
private static final SdrImageItemConfig JPG_ITEM_WITH_EFFECTS =
|
||||
new SdrImageItemConfig(
|
||||
JPG_ASSET,
|
||||
/* frameRate= */ 41,
|
||||
/* durationUs= */ C.MICROS_PER_SECOND,
|
||||
/* effects= */ new Effects(
|
||||
/* audioProcessors= */ ImmutableList.of(),
|
||||
ImmutableList.of(RgbFilter.createGrayscaleFilter())));
|
||||
private static final VideoItemConfig BT709_ITEM = new VideoItemConfig(MP4_ASSET, Effects.EMPTY);
|
||||
private static final VideoItemConfig BT709_ITEM_WITH_EFFECTS =
|
||||
new VideoItemConfig(
|
||||
MP4_ASSET,
|
||||
new Effects(
|
||||
/* audioProcessors= */ ImmutableList.of(),
|
||||
ImmutableList.of(
|
||||
Presentation.createForWidthAndHeight(
|
||||
480, 360, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP))));
|
||||
private static final VideoItemConfig BT601_ITEM =
|
||||
new VideoItemConfig(BT601_MP4_ASSET, Effects.EMPTY);
|
||||
private static final VideoItemConfig BT601_ITEM_WITH_EFFECTS =
|
||||
new VideoItemConfig(
|
||||
BT601_MP4_ASSET,
|
||||
new Effects(
|
||||
/* audioProcessors= */ ImmutableList.of(),
|
||||
ImmutableList.of(
|
||||
Presentation.createForWidthAndHeight(
|
||||
400, 300, Presentation.LAYOUT_SCALE_TO_FIT_WITH_CROP))));
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static ImmutableList<ItemConfig> params() {
|
||||
return ImmutableList.of(
|
||||
PNG_ITEM,
|
||||
PNG_ITEM_WITH_EFFECTS,
|
||||
JPG_ITEM,
|
||||
JPG_ITEM_WITH_EFFECTS,
|
||||
BT709_ITEM,
|
||||
BT709_ITEM_WITH_EFFECTS,
|
||||
BT601_ITEM,
|
||||
BT601_ITEM_WITH_EFFECTS);
|
||||
}
|
||||
|
||||
@Rule public final TestName testName = new TestName();
|
||||
|
||||
@Parameter public ItemConfig itemConfig;
|
||||
|
||||
@Test
|
||||
public void export_completesWithCorrectFrameCount() throws Exception {
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
String testId = testName.getMethodName();
|
||||
assumeFormatsSupported(context, testId, itemConfig.format, itemConfig.outputFormat);
|
||||
Transformer transformer =
|
||||
new Transformer.Builder(context)
|
||||
.setEncoderFactory(
|
||||
new DefaultEncoderFactory.Builder(context).setEnableFallback(false).build())
|
||||
.build();
|
||||
|
||||
ExportTestResult result =
|
||||
new TransformerAndroidTestRunner.Builder(context, transformer)
|
||||
.build()
|
||||
.run(testId, itemConfig.build());
|
||||
|
||||
assertThat(result.exportResult.videoFrameCount).isEqualTo(itemConfig.frameCount);
|
||||
assertThat(new File(result.filePath).length()).isGreaterThan(0);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue