Commit 4f6b83e2 by kimvde Committed by christosts

Remove usages of deprecated startTransformation

PiperOrigin-RevId: 503138745
parent 5e9c9ed2
......@@ -68,6 +68,8 @@ import com.google.android.exoplayer2.effect.TextOverlay;
import com.google.android.exoplayer2.effect.TextureOverlay;
import com.google.android.exoplayer2.transformer.DefaultEncoderFactory;
import com.google.android.exoplayer2.transformer.DefaultMuxer;
import com.google.android.exoplayer2.transformer.EditedMediaItem;
import com.google.android.exoplayer2.transformer.Effects;
import com.google.android.exoplayer2.transformer.ProgressHolder;
import com.google.android.exoplayer2.transformer.TransformationException;
import com.google.android.exoplayer2.transformer.TransformationRequest;
......@@ -207,8 +209,9 @@ public final class TransformerActivity extends AppCompatActivity {
MediaItem mediaItem = createMediaItem(bundle, uri);
try {
Transformer transformer = createTransformer(bundle, filePath);
EditedMediaItem editedMediaItem = createEditedMediaItem(mediaItem, bundle);
transformationStopwatch.start();
transformer.startTransformation(mediaItem, filePath);
transformer.startTransformation(editedMediaItem, filePath);
this.transformer = transformer;
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalStateException(e);
......@@ -265,8 +268,7 @@ public final class TransformerActivity extends AppCompatActivity {
"progressViewGroup",
"debugFrame",
})
private Transformer createTransformer(@Nullable Bundle bundle, String filePath)
throws PackageManager.NameNotFoundException {
private Transformer createTransformer(@Nullable Bundle bundle, String filePath) {
Transformer.Builder transformerBuilder = new Transformer.Builder(/* context= */ this);
if (bundle != null) {
TransformationRequest.Builder requestBuilder = new TransformationRequest.Builder();
......@@ -283,29 +285,6 @@ public final class TransformerActivity extends AppCompatActivity {
requestBuilder.setHdrMode(bundle.getInt(ConfigurationActivity.HDR_MODE));
transformerBuilder.setTransformationRequest(requestBuilder.build());
transformerBuilder.setAudioProcessors(createAudioProcessorsFromBundle(bundle));
ImmutableList.Builder<Effect> effectsListBuilder =
new ImmutableList.Builder<Effect>().addAll(createVideoEffectsFromBundle(bundle));
float scaleX = bundle.getFloat(ConfigurationActivity.SCALE_X, /* defaultValue= */ 1);
float scaleY = bundle.getFloat(ConfigurationActivity.SCALE_Y, /* defaultValue= */ 1);
float rotateDegrees =
bundle.getFloat(ConfigurationActivity.ROTATE_DEGREES, /* defaultValue= */ 0);
if (scaleX != 1f || scaleY != 1f || rotateDegrees != 0f) {
effectsListBuilder.add(
new ScaleToFitTransformation.Builder()
.setScale(scaleX, scaleY)
.setRotationDegrees(rotateDegrees)
.build());
}
int resolutionHeight =
bundle.getInt(
ConfigurationActivity.RESOLUTION_HEIGHT, /* defaultValue= */ C.LENGTH_UNSET);
if (resolutionHeight != C.LENGTH_UNSET) {
effectsListBuilder.add(Presentation.createForHeight(resolutionHeight));
}
transformerBuilder.setVideoEffects(effectsListBuilder.build());
transformerBuilder
.setRemoveAudio(bundle.getBoolean(ConfigurationActivity.SHOULD_REMOVE_AUDIO))
.setRemoveVideo(bundle.getBoolean(ConfigurationActivity.SHOULD_REMOVE_VIDEO))
......@@ -358,6 +337,24 @@ public final class TransformerActivity extends AppCompatActivity {
return file;
}
@RequiresNonNull({
"inputCardView",
"outputPlayerView",
"transformationStopwatch",
"progressViewGroup",
})
private EditedMediaItem createEditedMediaItem(MediaItem mediaItem, @Nullable Bundle bundle)
throws PackageManager.NameNotFoundException {
if (bundle == null) {
return new EditedMediaItem(mediaItem);
}
ImmutableList<AudioProcessor> audioProcessors = createAudioProcessorsFromBundle(bundle);
ImmutableList<Effect> videoEffects = createVideoEffectsFromBundle(bundle);
Effects effects = new Effects(audioProcessors, videoEffects);
return new EditedMediaItem(mediaItem, effects);
}
private ImmutableList<AudioProcessor> createAudioProcessorsFromBundle(Bundle bundle) {
@Nullable
boolean[] selectedAudioEffects =
......@@ -519,6 +516,24 @@ public final class TransformerActivity extends AppCompatActivity {
effects.add(overlayEffect);
}
float scaleX = bundle.getFloat(ConfigurationActivity.SCALE_X, /* defaultValue= */ 1);
float scaleY = bundle.getFloat(ConfigurationActivity.SCALE_Y, /* defaultValue= */ 1);
float rotateDegrees =
bundle.getFloat(ConfigurationActivity.ROTATE_DEGREES, /* defaultValue= */ 0);
if (scaleX != 1f || scaleY != 1f || rotateDegrees != 0f) {
effects.add(
new ScaleToFitTransformation.Builder()
.setScale(scaleX, scaleY)
.setRotationDegrees(rotateDegrees)
.build());
}
int resolutionHeight =
bundle.getInt(ConfigurationActivity.RESOLUTION_HEIGHT, /* defaultValue= */ C.LENGTH_UNSET);
if (resolutionHeight != C.LENGTH_UNSET) {
effects.add(Presentation.createForHeight(resolutionHeight));
}
return effects.build();
}
......
......@@ -183,12 +183,26 @@ public class TransformerAndroidTestRunner {
* @throws Exception The cause of the transformation not completing.
*/
public TransformationTestResult run(String testId, MediaItem mediaItem) throws Exception {
return run(testId, new EditedMediaItem(mediaItem));
}
/**
* Transforms the {@link EditedMediaItem}, saving a summary of the transformation to the
* application cache.
*
* @param testId A unique identifier for the transformer test run.
* @param editedMediaItem The {@link EditedMediaItem} to transform.
* @return The {@link TransformationTestResult}.
* @throws Exception The cause of the transformation not completing.
*/
public TransformationTestResult run(String testId, EditedMediaItem editedMediaItem)
throws Exception {
JSONObject resultJson = new JSONObject();
if (inputValues != null) {
resultJson.put("inputValues", JSONObject.wrap(inputValues));
}
try {
TransformationTestResult transformationTestResult = runInternal(testId, mediaItem);
TransformationTestResult transformationTestResult = runInternal(testId, editedMediaItem);
resultJson.put("transformationResult", transformationTestResult.asJsonObject());
if (transformationTestResult.testException != null) {
throw transformationTestResult.testException;
......@@ -208,17 +222,18 @@ public class TransformerAndroidTestRunner {
}
/**
* Transforms the {@link MediaItem}.
* Transforms the {@link EditedMediaItem}.
*
* @param testId An identifier for the test.
* @param mediaItem The {@link MediaItem} to transform.
* @param editedMediaItem The {@link EditedMediaItem} to transform.
* @return The {@link TransformationTestResult}.
* @throws InterruptedException If the thread is interrupted whilst waiting for transformer to
* complete.
* @throws IOException If an error occurs opening the output file for writing.
*/
private TransformationTestResult runInternal(String testId, MediaItem mediaItem)
private TransformationTestResult runInternal(String testId, EditedMediaItem editedMediaItem)
throws InterruptedException, IOException {
MediaItem mediaItem = editedMediaItem.mediaItem;
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& requestCalculateSsim) {
throw new UnsupportedOperationException(
......@@ -293,7 +308,8 @@ public class TransformerAndroidTestRunner {
.runOnMainSync(
() -> {
try {
testTransformer.startTransformation(mediaItem, outputVideoFile.getAbsolutePath());
testTransformer.startTransformation(
editedMediaItem, outputVideoFile.getAbsolutePath());
// Catch all exceptions to report. Exceptions thrown here and not caught will NOT
// propagate.
} catch (Exception e) {
......
......@@ -27,6 +27,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.effect.Presentation;
import com.google.android.exoplayer2.util.Effect;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -44,10 +45,13 @@ public class TransformerEndToEndTest {
public void videoEditing_completesWithConsistentFrameCount() throws Exception {
Transformer transformer =
new Transformer.Builder(context)
.setVideoEffects(ImmutableList.of(Presentation.createForHeight(480)))
.setEncoderFactory(
new DefaultEncoderFactory.Builder(context).setEnableFallback(false).build())
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_URI_STRING));
ImmutableList<Effect> videoEffects = ImmutableList.of(Presentation.createForHeight(480));
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
// Result of the following command:
// ffprobe -count_frames -select_streams v:0 -show_entries stream=nb_read_frames sample.mp4
int expectedFrameCount = 30;
......@@ -55,9 +59,7 @@ public class TransformerEndToEndTest {
TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(
/* testId= */ "videoEditing_completesWithConsistentFrameCount",
MediaItem.fromUri(Uri.parse(MP4_ASSET_URI_STRING)));
.run(/* testId= */ "videoEditing_completesWithConsistentFrameCount", editedMediaItem);
assertThat(result.transformationResult.videoFrameCount).isEqualTo(expectedFrameCount);
}
......@@ -67,18 +69,19 @@ public class TransformerEndToEndTest {
Transformer transformer =
new Transformer.Builder(context)
.setRemoveAudio(true)
.setVideoEffects(ImmutableList.of(Presentation.createForHeight(480)))
.setEncoderFactory(
new DefaultEncoderFactory.Builder(context).setEnableFallback(false).build())
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_URI_STRING));
ImmutableList<Effect> videoEffects = ImmutableList.of(Presentation.createForHeight(480));
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
long expectedDurationMs = 967;
TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(
/* testId= */ "videoOnly_completesWithConsistentDuration",
MediaItem.fromUri(Uri.parse(MP4_ASSET_URI_STRING)));
.run(/* testId= */ "videoOnly_completesWithConsistentDuration", editedMediaItem);
assertThat(result.transformationResult.durationMs).isEqualTo(expectedDurationMs);
}
......
......@@ -31,12 +31,15 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.effect.ScaleToFitTransformation;
import com.google.android.exoplayer2.transformer.EditedMediaItem;
import com.google.android.exoplayer2.transformer.Effects;
import com.google.android.exoplayer2.transformer.EncoderUtil;
import com.google.android.exoplayer2.transformer.TransformationException;
import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.TransformationTestResult;
import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.ColorInfo;
......@@ -79,7 +82,6 @@ public class HdrEditingTest {
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)));
Log.i(TAG, "Transformed.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_ST2084);
return;
} catch (TransformationException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -102,7 +104,6 @@ public class HdrEditingTest {
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)));
Log.i(TAG, "Transformed.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_HLG);
return;
} catch (TransformationException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -121,17 +122,17 @@ public class HdrEditingTest {
return;
}
Transformer transformer =
new Transformer.Builder(context)
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(180).build()))
.build();
Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(180).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)));
.run(testId, editedMediaItem);
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_ST2084);
}
......@@ -145,17 +146,17 @@ public class HdrEditingTest {
return;
}
Transformer transformer =
new Transformer.Builder(context)
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(180).build()))
.build();
Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(180).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)));
.run(testId, editedMediaItem);
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_HLG);
}
......@@ -173,9 +174,6 @@ public class HdrEditingTest {
AtomicBoolean isToneMappingFallbackApplied = new AtomicBoolean();
Transformer transformer =
new Transformer.Builder(context)
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(180).build()))
.addListener(
new Transformer.Listener() {
@Override
......@@ -192,12 +190,17 @@ public class HdrEditingTest {
}
})
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(180).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)));
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertThat(isToneMappingFallbackApplied.get()).isTrue();
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
......@@ -209,7 +212,6 @@ public class HdrEditingTest {
TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED,
TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
assertThat(isFallbackListenerInvoked.get()).isFalse();
return;
}
}
......@@ -227,9 +229,6 @@ public class HdrEditingTest {
AtomicBoolean isToneMappingFallbackApplied = new AtomicBoolean();
Transformer transformer =
new Transformer.Builder(context)
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(180).build()))
.addListener(
new Transformer.Listener() {
@Override
......@@ -246,12 +245,17 @@ public class HdrEditingTest {
}
})
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(180).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)));
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertThat(isToneMappingFallbackApplied.get()).isTrue();
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
......
......@@ -25,10 +25,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.effect.ScaleToFitTransformation;
import com.google.android.exoplayer2.transformer.AndroidTestUtil;
import com.google.android.exoplayer2.transformer.EditedMediaItem;
import com.google.android.exoplayer2.transformer.Effects;
import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.TransformationTestResult;
import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
import com.google.android.exoplayer2.util.Effect;
import com.google.common.collect.ImmutableList;
import java.util.HashSet;
import java.util.Set;
......@@ -48,20 +51,22 @@ public final class RepeatedTranscodeTest {
new TransformerAndroidTestRunner.Builder(
context,
new Transformer.Builder(context)
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(45).build()))
.setEncoderFactory(new AndroidTestUtil.ForceEncodeEncoderFactory(context))
.build())
.build();
MediaItem mediaItem =
MediaItem.fromUri(Uri.parse(AndroidTestUtil.MP4_REMOTE_10_SECONDS_URI_STRING));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(45).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) {
// Use a long video in case an error occurs a while after the start of the video.
TransformationTestResult testResult =
transformerRunner.run(
/* testId= */ "repeatedTranscode_givesConsistentLengthOutput_" + i,
MediaItem.fromUri(Uri.parse(AndroidTestUtil.MP4_REMOTE_10_SECONDS_URI_STRING)));
/* testId= */ "repeatedTranscode_givesConsistentLengthOutput_" + i, editedMediaItem);
differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));
}
......@@ -79,12 +84,15 @@ public final class RepeatedTranscodeTest {
context,
new Transformer.Builder(context)
.setRemoveAudio(true)
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(45).build()))
.setEncoderFactory(new AndroidTestUtil.ForceEncodeEncoderFactory(context))
.build())
.build();
MediaItem mediaItem =
MediaItem.fromUri(Uri.parse(AndroidTestUtil.MP4_REMOTE_10_SECONDS_URI_STRING));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(45).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) {
......@@ -92,7 +100,7 @@ public final class RepeatedTranscodeTest {
TransformationTestResult testResult =
transformerRunner.run(
/* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput_" + i,
MediaItem.fromUri(Uri.parse(AndroidTestUtil.MP4_REMOTE_10_SECONDS_URI_STRING)));
editedMediaItem);
differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));
}
......
......@@ -28,11 +28,14 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.effect.ScaleToFitTransformation;
import com.google.android.exoplayer2.transformer.EditedMediaItem;
import com.google.android.exoplayer2.transformer.Effects;
import com.google.android.exoplayer2.transformer.TransformationException;
import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.TransformationTestResult;
import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.Log;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
......@@ -80,7 +83,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)));
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
return;
} catch (TransformationException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -88,7 +90,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.isAnyOf(
TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED,
TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
return;
}
}
......@@ -125,7 +126,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)));
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
return;
} catch (TransformationException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -133,7 +133,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.isAnyOf(
TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED,
TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
return;
}
}
......@@ -148,9 +147,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformationRequest.Builder()
.setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC)
.build())
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(180).build()))
.addListener(
new Transformer.Listener() {
@Override
......@@ -165,15 +161,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
}
})
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(180).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)));
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
return;
} catch (TransformationException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -181,7 +181,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.isAnyOf(
TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED,
TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
return;
}
}
......@@ -196,9 +195,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
new TransformationRequest.Builder()
.setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC)
.build())
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(180).build()))
.addListener(
new Transformer.Listener() {
@Override
......@@ -213,15 +209,19 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
}
})
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(180).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)));
.run(testId, editedMediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
return;
} catch (TransformationException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
......@@ -229,7 +229,6 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
.isAnyOf(
TransformationException.ERROR_CODE_HDR_ENCODING_UNSUPPORTED,
TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
return;
}
}
}
......@@ -33,10 +33,13 @@ import com.google.android.exoplayer2.effect.ScaleToFitTransformation;
import com.google.android.exoplayer2.transformer.AndroidTestUtil;
import com.google.android.exoplayer2.transformer.AndroidTestUtil.ForceEncodeEncoderFactory;
import com.google.android.exoplayer2.transformer.DefaultEncoderFactory;
import com.google.android.exoplayer2.transformer.EditedMediaItem;
import com.google.android.exoplayer2.transformer.Effects;
import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
import com.google.android.exoplayer2.transformer.VideoEncoderSettings;
import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
......@@ -195,17 +198,16 @@ public class TransformationTest {
String testId = TAG + "_transformFrameRotation";
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer =
new Transformer.Builder(context)
.setVideoEffects(
ImmutableList.of(
new ScaleToFitTransformation.Builder().setRotationDegrees(45).build()))
.build();
Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem =
MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING));
ImmutableList<Effect> videoEffects =
ImmutableList.of(new ScaleToFitTransformation.Builder().setRotationDegrees(45).build());
Effects effects = new Effects(/* audioProcessors= */ ImmutableList.of(), videoEffects);
EditedMediaItem editedMediaItem = new EditedMediaItem(mediaItem, effects);
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(
/* testId= */ testId,
MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING)));
.run(/* testId= */ testId, editedMediaItem);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment