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);
}
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();
}
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();
}
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));
}
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);
}
Aggregations