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