Commit 2c690618 by kimvde Committed by christosts

Undeprecate startTransformation(MediaItem, String)

This overload is helpful to apps transcoding a MediaItem without edits.

PiperOrigin-RevId: 505987852
parent d5035123
...@@ -212,6 +212,20 @@ public class TransformerAndroidTestRunner { ...@@ -212,6 +212,20 @@ public class TransformerAndroidTestRunner {
} }
/** /**
* Transforms the {@link MediaItem}, saving a summary of the transformation to the application
* cache.
*
* @param testId A unique identifier for the transformer test run.
* @param mediaItem The {@link MediaItem} to transform.
* @return The {@link TransformationTestResult}.
* @throws Exception The cause of the transformation not completing.
*/
public TransformationTestResult run(String testId, MediaItem mediaItem) throws Exception {
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
return run(testId, editedMediaItem);
}
/**
* Transforms the {@link EditedMediaItem}. * Transforms the {@link EditedMediaItem}.
* *
* @param testId An identifier for the test. * @param testId An identifier for the test.
......
...@@ -101,12 +101,11 @@ public class TransformerEndToEndTest { ...@@ -101,12 +101,11 @@ public class TransformerEndToEndTest {
.setEndPositionMs(clippingEndMs) .setEndPositionMs(clippingEndMs)
.build()) .build())
.build(); .build();
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
TransformationTestResult result = TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(/* testId= */ "clippedMedia_completesWithClippedDuration", editedMediaItem); .run(/* testId= */ "clippedMedia_completesWithClippedDuration", mediaItem);
assertThat(result.transformationResult.durationMs).isAtMost(clippingEndMs - clippingStartMs); assertThat(result.transformationResult.durationMs).isAtMost(clippingEndMs - clippingStartMs);
} }
......
...@@ -27,7 +27,6 @@ import androidx.media3.common.C; ...@@ -27,7 +27,6 @@ import androidx.media3.common.C;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
import androidx.media3.transformer.AndroidTestUtil; import androidx.media3.transformer.AndroidTestUtil;
import androidx.media3.transformer.EditedMediaItem;
import androidx.media3.transformer.TransformationException; import androidx.media3.transformer.TransformationException;
import androidx.media3.transformer.TransformationRequest; import androidx.media3.transformer.TransformationRequest;
import androidx.media3.transformer.TransformationTestResult; import androidx.media3.transformer.TransformationTestResult;
...@@ -68,14 +67,12 @@ public class ForceInterpretHdrVideoAsSdrTest { ...@@ -68,14 +67,12 @@ public class ForceInterpretHdrVideoAsSdrTest {
TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR)
.build()) .build())
.build(); .build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Transformed."); Log.i(TAG, "Transformed.");
} catch (TransformationException exception) { } catch (TransformationException exception) {
...@@ -107,14 +104,12 @@ public class ForceInterpretHdrVideoAsSdrTest { ...@@ -107,14 +104,12 @@ public class ForceInterpretHdrVideoAsSdrTest {
TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR)
.build()) .build())
.build(); .build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Transformed."); Log.i(TAG, "Transformed.");
} catch (TransformationException exception) { } catch (TransformationException exception) {
......
...@@ -74,15 +74,13 @@ public class HdrEditingTest { ...@@ -74,15 +74,13 @@ public class HdrEditingTest {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).build(); Transformer transformer = new Transformer.Builder(context).build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
Log.i(TAG, "Transformed."); Log.i(TAG, "Transformed.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_ST2084); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_ST2084);
} catch (TransformationException exception) { } catch (TransformationException exception) {
...@@ -99,15 +97,13 @@ public class HdrEditingTest { ...@@ -99,15 +97,13 @@ public class HdrEditingTest {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).build(); Transformer transformer = new Transformer.Builder(context).build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
Log.i(TAG, "Transformed."); Log.i(TAG, "Transformed.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_HLG); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_HLG);
} catch (TransformationException exception) { } catch (TransformationException exception) {
...@@ -295,10 +291,7 @@ public class HdrEditingTest { ...@@ -295,10 +291,7 @@ public class HdrEditingTest {
Transformer transformer = new Transformer.Builder(context).build(); Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem = MediaItem mediaItem =
MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_1_SECOND_HDR10_VIDEO_SDR_CONTAINER)); MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_1_SECOND_HDR10_VIDEO_SDR_CONTAINER));
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build(); new TransformerAndroidTestRunner.Builder(context, transformer).build().run(testId, mediaItem);
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
} }
private static boolean deviceSupportsHdrEditing(String mimeType, ColorInfo colorInfo) { private static boolean deviceSupportsHdrEditing(String mimeType, ColorInfo colorInfo) {
......
...@@ -75,15 +75,13 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -75,15 +75,13 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
} }
}) })
.build(); .build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
Log.i(TAG, "Tone mapped."); Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) { } catch (TransformationException exception) {
...@@ -121,15 +119,13 @@ public class ToneMapHdrToSdrUsingMediaCodecTest { ...@@ -121,15 +119,13 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
} }
}) })
.build(); .build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
Log.i(TAG, "Tone mapped."); Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) { } catch (TransformationException exception) {
......
...@@ -32,7 +32,6 @@ import androidx.media3.common.util.GlUtil; ...@@ -32,7 +32,6 @@ import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.transformer.AndroidTestUtil; import androidx.media3.transformer.AndroidTestUtil;
import androidx.media3.transformer.EditedMediaItem;
import androidx.media3.transformer.TransformationException; import androidx.media3.transformer.TransformationException;
import androidx.media3.transformer.TransformationRequest; import androidx.media3.transformer.TransformationRequest;
import androidx.media3.transformer.TransformationTestResult; import androidx.media3.transformer.TransformationTestResult;
...@@ -86,14 +85,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest { ...@@ -86,14 +85,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
.setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL) .setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL)
.build()) .build())
.build(); .build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
Log.i(TAG, "Tone mapped."); Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) { } catch (TransformationException exception) {
...@@ -139,14 +136,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest { ...@@ -139,14 +136,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
.setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL) .setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL)
.build()) .build())
.build(); .build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
try { try {
TransformationTestResult transformationTestResult = TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
Log.i(TAG, "Tone mapped."); Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) { } catch (TransformationException exception) {
......
...@@ -60,11 +60,10 @@ public class TransformationTest { ...@@ -60,11 +60,10 @@ public class TransformationTest {
.build(); .build();
MediaItem mediaItem = MediaItem mediaItem =
MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING)); MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING));
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setRequestCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
} }
@Test @Test
...@@ -74,11 +73,8 @@ public class TransformationTest { ...@@ -74,11 +73,8 @@ public class TransformationTest {
Transformer transformer = new Transformer.Builder(context).build(); Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem = MediaItem mediaItem =
MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING)); MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING));
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
// No need to calculate SSIM because no decode/encoding, so input frames match output frames. // No need to calculate SSIM because no decode/encoding, so input frames match output frames.
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer).build().run(testId, mediaItem);
.build()
.run(testId, editedMediaItem);
} }
@Test @Test
...@@ -122,12 +118,11 @@ public class TransformationTest { ...@@ -122,12 +118,11 @@ public class TransformationTest {
.setEncoderFactory(new ForceEncodeEncoderFactory(context)) .setEncoderFactory(new ForceEncodeEncoderFactory(context))
.build(); .build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_REMOTE_4K60_PORTRAIT_URI_STRING)); MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_REMOTE_4K60_PORTRAIT_URI_STRING));
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setRequestCalculateSsim(true) .setRequestCalculateSsim(true)
.setTimeoutSeconds(180) .setTimeoutSeconds(180)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
} }
@Test @Test
...@@ -146,14 +141,12 @@ public class TransformationTest { ...@@ -146,14 +141,12 @@ public class TransformationTest {
new Transformer.Builder(context) new Transformer.Builder(context)
.setEncoderFactory(new ForceEncodeEncoderFactory(context)) .setEncoderFactory(new ForceEncodeEncoderFactory(context))
.build(); .build();
EditedMediaItem editedMediaItem = MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_REMOTE_8K24_URI_STRING));
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_REMOTE_8K24_URI_STRING)))
.build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setRequestCalculateSsim(true) .setRequestCalculateSsim(true)
.setTimeoutSeconds(180) .setTimeoutSeconds(180)
.build() .build()
.run(testId, editedMediaItem); .run(testId, mediaItem);
} }
@Test @Test
......
...@@ -664,7 +664,6 @@ public final class Transformer { ...@@ -664,7 +664,6 @@ public final class Transformer {
* it. * it.
* @param path The path to the output file. * @param path The path to the output file.
* @throws IllegalArgumentException If the path is invalid. * @throws IllegalArgumentException If the path is invalid.
* @throws IllegalArgumentException If the {@link MediaItem} is not supported.
* @throws IllegalStateException If this method is called from the wrong thread. * @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If a transformation is already in progress. * @throws IllegalStateException If a transformation is already in progress.
*/ */
...@@ -673,9 +672,30 @@ public final class Transformer { ...@@ -673,9 +672,30 @@ public final class Transformer {
} }
/** /**
* @deprecated Use {@link #startTransformation(EditedMediaItem, String)} instead. * Starts an asynchronous operation to transform the given {@link MediaItem}.
*
* <p>The transformation state is notified through the {@linkplain Builder#addListener(Listener)
* listener}.
*
* <p>Concurrent transformations on the same Transformer object are not allowed.
*
* <p>If no custom {@link Muxer.Factory} is specified, the output is an MP4 file.
*
* <p>The output can contain at most one video track and one audio track. Other track types are
* ignored. For adaptive bitrate, if no custom {@link AssetLoader.Factory} is specified, the
* highest bitrate video and audio streams are selected.
*
* <p>If encoding the output's video track is needed, the output frames' dimensions will be
* swapped if the height is larger than the width. This is to improve compatibility among
* different device encoders.
*
* @param mediaItem The {@link MediaItem} to transform.
* @param path The path to the output file.
* @throws IllegalArgumentException If the path is invalid.
* @throws IllegalArgumentException If the {@link MediaItem} is not supported.
* @throws IllegalStateException If this method is called from the wrong thread.
* @throws IllegalStateException If a transformation is already in progress.
*/ */
@Deprecated
public void startTransformation(MediaItem mediaItem, String path) { public void startTransformation(MediaItem mediaItem, String path) {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET) if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& flattenForSlowMotion) { && flattenForSlowMotion) {
......
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