Search in sources :

Example 1 with Transformer

use of androidx.media3.transformer.Transformer in project ExoPlayer by google.

the class TransformerActivity method startTransformation.

@RequiresNonNull({ "playerView", "debugTextView", "informationTextView", "progressIndicator", "transformationStopwatch", "progressViewGroup", "debugFrame" })
private void startTransformation() {
    requestTransformerPermission();
    Intent intent = getIntent();
    Uri uri = checkNotNull(intent.getData());
    try {
        externalCacheFile = createExternalCacheFile("transformer-output.mp4");
        String filePath = externalCacheFile.getAbsolutePath();
        @Nullable Bundle bundle = intent.getExtras();
        Transformer transformer = createTransformer(bundle, filePath);
        transformationStopwatch.start();
        transformer.startTransformation(MediaItem.fromUri(uri), filePath);
        this.transformer = transformer;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    informationTextView.setText(R.string.transformation_started);
    playerView.setVisibility(View.GONE);
    Handler mainHandler = new Handler(getMainLooper());
    ProgressHolder progressHolder = new ProgressHolder();
    mainHandler.post(new Runnable() {

        @Override
        public void run() {
            if (transformer != null && transformer.getProgress(progressHolder) != Transformer.PROGRESS_STATE_NO_TRANSFORMATION) {
                progressIndicator.setProgress(progressHolder.progress);
                informationTextView.setText(getString(R.string.transformation_timer, transformationStopwatch.elapsed(TimeUnit.SECONDS)));
                mainHandler.postDelayed(/* r= */
                this, /* delayMillis= */
                500);
            }
        }
    });
}
Also used : Transformer(com.google.android.exoplayer2.transformer.Transformer) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri) Nullable(androidx.annotation.Nullable) ProgressHolder(com.google.android.exoplayer2.transformer.ProgressHolder) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 2 with Transformer

use of androidx.media3.transformer.Transformer in project ExoPlayer by google.

the class RepeatedTranscodeTransformationTest method repeatedTranscodeNoAudio_givesConsistentLengthOutput.

@Test
public void repeatedTranscodeNoAudio_givesConsistentLengthOutput() throws Exception {
    Context context = ApplicationProvider.getApplicationContext();
    Matrix transformationMatrix = new Matrix();
    transformationMatrix.postTranslate((float) 0.1, (float) 0.1);
    Transformer transformer = new Transformer.Builder(context).setRemoveAudio(true).setTransformationRequest(new TransformationRequest.Builder().setVideoMimeType(MimeTypes.VIDEO_H265).setTransformationMatrix(transformationMatrix).build()).build();
    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.
        AndroidTestUtil.TransformationResult result = runTransformer(context, /* testId= */
        "repeatedTranscodeNoAudio_givesConsistentLengthOutput_" + i, transformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */
        120);
        differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes));
    }
    assertWithMessage("Different transcoding output sizes detected. Sizes: " + differentOutputSizesBytes).that(differentOutputSizesBytes.size()).isEqualTo(1);
}
Also used : Context(android.content.Context) AndroidTestUtil(com.google.android.exoplayer2.transformer.AndroidTestUtil) Matrix(android.graphics.Matrix) Transformer(com.google.android.exoplayer2.transformer.Transformer) AndroidTestUtil.runTransformer(com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer) TransformationRequest(com.google.android.exoplayer2.transformer.TransformationRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Transformer

use of androidx.media3.transformer.Transformer in project ExoPlayer by google.

the class SetTransformationMatrixTransformationTest method setTransformationMatrixTransform.

@Test
public void setTransformationMatrixTransform() throws Exception {
    Context context = ApplicationProvider.getApplicationContext();
    Matrix transformationMatrix = new Matrix();
    transformationMatrix.postTranslate(/* dx= */
    .2f, /* dy= */
    .1f);
    Transformer transformer = new Transformer.Builder(context).setTransformationRequest(new TransformationRequest.Builder().setTransformationMatrix(transformationMatrix).build()).build();
    runTransformer(context, /* testId= */
    "setTransformationMatrixTransform", transformer, REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */
    120);
}
Also used : Context(android.content.Context) Matrix(android.graphics.Matrix) AndroidTestUtil.runTransformer(com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer) Transformer(com.google.android.exoplayer2.transformer.Transformer) Test(org.junit.Test)

Example 4 with Transformer

use of androidx.media3.transformer.Transformer in project ExoPlayer by google.

the class SefTransformationTest method sefTransform.

@Test
public void sefTransform() throws Exception {
    Context context = ApplicationProvider.getApplicationContext();
    Transformer transformer = new Transformer.Builder(context).setTransformationRequest(new TransformationRequest.Builder().setFlattenForSlowMotion(true).build()).build();
    runTransformer(context, /* testId = */
    "sefTransform", transformer, SEF_ASSET_URI_STRING, /* timeoutSeconds= */
    120);
}
Also used : Context(android.content.Context) AndroidTestUtil.runTransformer(com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer) Transformer(com.google.android.exoplayer2.transformer.Transformer) Test(org.junit.Test)

Example 5 with Transformer

use of androidx.media3.transformer.Transformer in project ExoPlayer by google.

the class TransformationTest method transform.

@Test
public void transform() throws Exception {
    Context context = ApplicationProvider.getApplicationContext();
    Transformer transformer = new Transformer.Builder(context).build();
    runTransformer(context, /* testId= */
    "transform", transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */
    120);
}
Also used : Context(android.content.Context) AndroidTestUtil.runTransformer(com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer) Transformer(com.google.android.exoplayer2.transformer.Transformer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)45 MediaItem (androidx.media3.common.MediaItem)29 Context (android.content.Context)18 AndroidTestUtil.runTransformer (androidx.media3.transformer.AndroidTestUtil.runTransformer)10 Transformer (androidx.media3.transformer.Transformer)10 Transformer (com.google.android.exoplayer2.transformer.Transformer)10 Matrix (android.graphics.Matrix)9 AndroidTestUtil.runTransformer (com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer)8 Handler (android.os.Handler)7 HashSet (java.util.HashSet)7 Nullable (androidx.annotation.Nullable)5 IOException (java.io.IOException)5 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)4 Uri (android.net.Uri)3 Message (android.os.Message)3 AndroidTestUtil (androidx.media3.transformer.AndroidTestUtil)3 AndroidTestUtil (com.google.android.exoplayer2.transformer.AndroidTestUtil)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3