use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class AndroidTestUtil method runTransformer.
/**
* Transforms the {@code uriString} with the {@link Transformer}.
*
* @param context The {@link Context}.
* @param testId An identifier for the test.
* @param transformer The {@link Transformer} that performs the transformation.
* @param uriString The uri (as a {@link String}) that will be transformed.
* @param timeoutSeconds The transformer timeout. An assertion confirms this is not exceeded.
* @return The {@link TransformationResult}.
* @throws Exception The cause of the transformation not completing.
*/
public static TransformationResult runTransformer(Context context, String testId, Transformer transformer, String uriString, int timeoutSeconds) throws Exception {
AtomicReference<@NullableType Exception> exceptionReference = new AtomicReference<>();
CountDownLatch countDownLatch = new CountDownLatch(1);
Transformer testTransformer = transformer.buildUpon().addListener(new Transformer.Listener() {
@Override
public void onTransformationCompleted(MediaItem inputMediaItem) {
countDownLatch.countDown();
}
@Override
public void onTransformationError(MediaItem inputMediaItem, TransformationException exception) {
exceptionReference.set(exception);
countDownLatch.countDown();
}
}).build();
Uri uri = Uri.parse(uriString);
File outputVideoFile = createExternalCacheFile(context, /* fileName= */
testId + "-output.mp4");
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
try {
testTransformer.startTransformation(MediaItem.fromUri(uri), outputVideoFile.getAbsolutePath());
} catch (IOException e) {
exceptionReference.set(e);
}
});
assertWithMessage("Transformer timed out after " + timeoutSeconds + " seconds.").that(countDownLatch.await(timeoutSeconds, SECONDS)).isTrue();
@Nullable Exception exception = exceptionReference.get();
if (exception != null) {
throw exception;
}
TransformationResult result = new TransformationResult.Builder(testId).setFileSizeBytes(outputVideoFile.length()).build();
writeTransformationResultToFile(context, result);
return result;
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class RemoveVideoTransformationTest method removeVideoTransform.
@Test
public void removeVideoTransform() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).setRemoveVideo(true).build();
runTransformer(context, /* testId= */
"removeVideoTransform", transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */
120);
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class TransformerEndToEndTest method videoEditing_completesWithConsistentFrameCount.
@Test
public void videoEditing_completesWithConsistentFrameCount() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Matrix transformationMatrix = new Matrix();
transformationMatrix.postTranslate(/* dx= */
.2f, /* dy= */
.1f);
FrameCountingMuxer.Factory muxerFactory = new FrameCountingMuxer.Factory(new FrameworkMuxer.Factory());
Transformer transformer = new Transformer.Builder(context).setTransformationRequest(new TransformationRequest.Builder().setTransformationMatrix(transformationMatrix).build()).setMuxerFactory(muxerFactory).build();
// Result of the following command:
// ffprobe -count_frames -select_streams v:0 -show_entries stream=nb_read_frames sample.mp4
int expectedFrameCount = 30;
runTransformer(context, /* testId= */
"videoEditing_completesWithConsistentFrameCount", transformer, AVC_VIDEO_URI_STRING, /* timeoutSeconds= */
120);
FrameCountingMuxer frameCountingMuxer = checkNotNull(muxerFactory.getLastFrameCountingMuxerCreated());
assertThat(frameCountingMuxer.getFrameCount()).isEqualTo(expectedFrameCount);
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class RemoveAudioTransformationTest method removeAudioTransform.
@Test
public void removeAudioTransform() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).setRemoveAudio(true).build();
runTransformer(context, /* testId= */
"removeAudioTransform", transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */
120);
}
use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.
the class RepeatedTranscodeTransformationTest method repeatedTranscodeNoVideo_givesConsistentLengthOutput.
@Test
public void repeatedTranscodeNoVideo_givesConsistentLengthOutput() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).setRemoveVideo(true).setTransformationRequest(new TransformationRequest.Builder().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= */
"repeatedTranscodeNoVideo_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);
}
Aggregations