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 {
}
/**
* 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}.
*
* @param testId An identifier for the test.
......
......@@ -101,12 +101,11 @@ public class TransformerEndToEndTest {
.setEndPositionMs(clippingEndMs)
.build())
.build();
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(/* testId= */ "clippedMedia_completesWithClippedDuration", editedMediaItem);
.run(/* testId= */ "clippedMedia_completesWithClippedDuration", mediaItem);
assertThat(result.transformationResult.durationMs).isAtMost(clippingEndMs - clippingStartMs);
}
......
......@@ -27,7 +27,6 @@ import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.Log;
import androidx.media3.transformer.AndroidTestUtil;
import androidx.media3.transformer.EditedMediaItem;
import androidx.media3.transformer.TransformationException;
import androidx.media3.transformer.TransformationRequest;
import androidx.media3.transformer.TransformationTestResult;
......@@ -68,14 +67,12 @@ public class ForceInterpretHdrVideoAsSdrTest {
TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR)
.build())
.build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Transformed.");
} catch (TransformationException exception) {
......@@ -107,14 +104,12 @@ public class ForceInterpretHdrVideoAsSdrTest {
TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR)
.build())
.build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
Log.i(TAG, "Transformed.");
} catch (TransformationException exception) {
......
......@@ -74,15 +74,13 @@ public class HdrEditingTest {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
Log.i(TAG, "Transformed.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_ST2084);
} catch (TransformationException exception) {
......@@ -99,15 +97,13 @@ public class HdrEditingTest {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
Log.i(TAG, "Transformed.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_HLG);
} catch (TransformationException exception) {
......@@ -295,10 +291,7 @@ public class HdrEditingTest {
Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem =
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, editedMediaItem);
new TransformerAndroidTestRunner.Builder(context, transformer).build().run(testId, mediaItem);
}
private static boolean deviceSupportsHdrEditing(String mimeType, ColorInfo colorInfo) {
......
......@@ -75,15 +75,13 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
}
})
.build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) {
......@@ -121,15 +119,13 @@ public class ToneMapHdrToSdrUsingMediaCodecTest {
}
})
.build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) {
......
......@@ -32,7 +32,6 @@ import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import androidx.media3.transformer.AndroidTestUtil;
import androidx.media3.transformer.EditedMediaItem;
import androidx.media3.transformer.TransformationException;
import androidx.media3.transformer.TransformationRequest;
import androidx.media3.transformer.TransformationTestResult;
......@@ -86,14 +85,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
.setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL)
.build())
.build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_5_SECOND_HLG10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) {
......@@ -139,14 +136,12 @@ public class ToneMapHdrToSdrUsingOpenGlTest {
.setHdrMode(TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL)
.build())
.build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10));
try {
TransformationTestResult transformationTestResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
Log.i(TAG, "Tone mapped.");
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) {
......
......@@ -60,11 +60,10 @@ public class TransformationTest {
.build();
MediaItem mediaItem =
MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING));
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
new TransformerAndroidTestRunner.Builder(context, transformer)
.setRequestCalculateSsim(true)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
}
@Test
......@@ -74,11 +73,8 @@ public class TransformationTest {
Transformer transformer = new Transformer.Builder(context).build();
MediaItem mediaItem =
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.
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(testId, editedMediaItem);
new TransformerAndroidTestRunner.Builder(context, transformer).build().run(testId, mediaItem);
}
@Test
......@@ -122,12 +118,11 @@ public class TransformationTest {
.setEncoderFactory(new ForceEncodeEncoderFactory(context))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_REMOTE_4K60_PORTRAIT_URI_STRING));
EditedMediaItem editedMediaItem = new EditedMediaItem.Builder(mediaItem).build();
new TransformerAndroidTestRunner.Builder(context, transformer)
.setRequestCalculateSsim(true)
.setTimeoutSeconds(180)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
}
@Test
......@@ -146,14 +141,12 @@ public class TransformationTest {
new Transformer.Builder(context)
.setEncoderFactory(new ForceEncodeEncoderFactory(context))
.build();
EditedMediaItem editedMediaItem =
new EditedMediaItem.Builder(MediaItem.fromUri(Uri.parse(MP4_REMOTE_8K24_URI_STRING)))
.build();
MediaItem mediaItem = MediaItem.fromUri(Uri.parse(MP4_REMOTE_8K24_URI_STRING));
new TransformerAndroidTestRunner.Builder(context, transformer)
.setRequestCalculateSsim(true)
.setTimeoutSeconds(180)
.build()
.run(testId, editedMediaItem);
.run(testId, mediaItem);
}
@Test
......
......@@ -664,7 +664,6 @@ public final class Transformer {
* it.
* @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.
*/
......@@ -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) {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& 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