Search in sources :

Example 26 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class RepeatedTranscodeTransformationTest method repeatedTranscode_givesConsistentLengthOutput.

@Test
public void repeatedTranscode_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).setTransformationRequest(new TransformationRequest.Builder().setVideoMimeType(MimeTypes.VIDEO_H265).setTransformationMatrix(transformationMatrix).setAudioMimeType(MimeTypes.AUDIO_AMR_NB).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= */
        "repeatedTranscode_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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerActivity method createTransformer.

@RequiresNonNull({ "playerView", "debugTextView", "informationTextView", "transformationStopwatch", "progressViewGroup", "debugFrame" })
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();
        requestBuilder.setFlattenForSlowMotion(bundle.getBoolean(ConfigurationActivity.SHOULD_FLATTEN_FOR_SLOW_MOTION));
        @Nullable String audioMimeType = bundle.getString(ConfigurationActivity.AUDIO_MIME_TYPE);
        if (audioMimeType != null) {
            requestBuilder.setAudioMimeType(audioMimeType);
        }
        @Nullable String videoMimeType = bundle.getString(ConfigurationActivity.VIDEO_MIME_TYPE);
        if (videoMimeType != null) {
            requestBuilder.setVideoMimeType(videoMimeType);
        }
        int resolutionHeight = bundle.getInt(ConfigurationActivity.RESOLUTION_HEIGHT, /* defaultValue= */
        C.LENGTH_UNSET);
        if (resolutionHeight != C.LENGTH_UNSET) {
            requestBuilder.setResolution(resolutionHeight);
        }
        Matrix transformationMatrix = getTransformationMatrix(bundle);
        if (!transformationMatrix.isIdentity()) {
            requestBuilder.setTransformationMatrix(transformationMatrix);
        }
        requestBuilder.experimental_setEnableHdrEditing(bundle.getBoolean(ConfigurationActivity.ENABLE_HDR_EDITING));
        transformerBuilder.setTransformationRequest(requestBuilder.build()).setRemoveAudio(bundle.getBoolean(ConfigurationActivity.SHOULD_REMOVE_AUDIO)).setRemoveVideo(bundle.getBoolean(ConfigurationActivity.SHOULD_REMOVE_VIDEO));
    }
    return transformerBuilder.addListener(new Transformer.Listener() {

        @Override
        public void onTransformationCompleted(MediaItem mediaItem) {
            TransformerActivity.this.onTransformationCompleted(filePath);
        }

        @Override
        public void onTransformationError(MediaItem mediaItem, TransformationException exception) {
            TransformerActivity.this.onTransformationError(exception);
        }
    }).setDebugViewProvider(new DemoDebugViewProvider()).build();
}
Also used : TransformationException(com.google.android.exoplayer2.transformer.TransformationException) Transformer(com.google.android.exoplayer2.transformer.Transformer) TransformationRequest(com.google.android.exoplayer2.transformer.TransformationRequest) Matrix(android.graphics.Matrix) MediaItem(com.google.android.exoplayer2.MediaItem) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 28 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method getProgress_unknownDuration_returnsConsistentStates.

@Test
public void getProgress_unknownDuration_returnsConsistentStates() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_UNKNOWN_DURATION);
    AtomicInteger previousProgressState = new AtomicInteger(PROGRESS_STATE_WAITING_FOR_AVAILABILITY);
    AtomicBoolean foundInconsistentState = new AtomicBoolean();
    Handler progressHandler = new Handler(Looper.myLooper()) {

        @Override
        public void handleMessage(Message msg) {
            @Transformer.ProgressState int progressState = transformer.getProgress(progressHolder);
            switch(previousProgressState.get()) {
                case PROGRESS_STATE_WAITING_FOR_AVAILABILITY:
                    break;
                case PROGRESS_STATE_UNAVAILABLE:
                case // See [Internal: b/176145097].
                PROGRESS_STATE_AVAILABLE:
                    if (progressState == PROGRESS_STATE_WAITING_FOR_AVAILABILITY) {
                        foundInconsistentState.set(true);
                        return;
                    }
                    break;
                case PROGRESS_STATE_NO_TRANSFORMATION:
                    if (progressState != PROGRESS_STATE_NO_TRANSFORMATION) {
                        foundInconsistentState.set(true);
                        return;
                    }
                    break;
                default:
                    throw new IllegalStateException();
            }
            previousProgressState.set(progressState);
            sendEmptyMessage(0);
        }
    };
    transformer.startTransformation(mediaItem, outputPath);
    progressHandler.sendEmptyMessage(0);
    TransformerTestRunner.runUntilCompleted(transformer);
    assertThat(foundInconsistentState.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Message(android.os.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MediaItem(com.google.android.exoplayer2.MediaItem) Handler(android.os.Handler) Test(org.junit.Test)

Example 29 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_successiveTransformations_completesSuccessfully.

@Test
public void startTransformation_successiveTransformations_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
    // Transform first media item.
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    Files.delete(Paths.get(outputPath));
    // Transform second media item.
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO));
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 30 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_withAudioMuxerFormatFallback_completesSuccessfully.

@Test
public void startTransformation_withAudioMuxerFormatFallback_completesSuccessfully() throws Exception {
    Transformer.Listener mockListener = mock(Transformer.Listener.class);
    TransformationRequest originalTransformationRequest = new TransformationRequest.Builder().build();
    TransformationRequest fallbackTransformationRequest = new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build();
    Transformer transformer = createTransformerBuilder().addListener(mockListener).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_MUXER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_UNSUPPORTED_BY_MUXER + ".fallback"));
    verify(mockListener, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 MediaItem (com.google.android.exoplayer2.MediaItem)29 Context (android.content.Context)10 AndroidTestUtil.runTransformer (com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer)10 Transformer (com.google.android.exoplayer2.transformer.Transformer)10 Handler (android.os.Handler)6 Matrix (android.graphics.Matrix)5 IOException (java.io.IOException)4 Message (android.os.Message)3 Nullable (androidx.annotation.Nullable)3 AndroidTestUtil (com.google.android.exoplayer2.transformer.AndroidTestUtil)3 HashSet (java.util.HashSet)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Uri (android.net.Uri)2 HandlerThread (android.os.HandlerThread)2 TransformationRequest (com.google.android.exoplayer2.transformer.TransformationRequest)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2