diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java index f623365fce..d756dbffe4 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationRequest.java @@ -54,7 +54,7 @@ public final class TransformationRequest { } private Builder(TransformationRequest transformationRequest) { - this.transformationMatrix = transformationRequest.transformationMatrix; + this.transformationMatrix = new Matrix(transformationRequest.transformationMatrix); this.flattenForSlowMotion = transformationRequest.flattenForSlowMotion; this.outputHeight = transformationRequest.outputHeight; this.audioMimeType = transformationRequest.audioMimeType; @@ -84,7 +84,7 @@ public final class TransformationRequest { // TODO(b/213198690): Consider changing how transformationMatrix is applied, so that // dimensions will be from -1 to 1 on both x and y axes, but transformations will be applied // in a predictable manner. - this.transformationMatrix = transformationMatrix; + this.transformationMatrix = new Matrix(transformationMatrix); return this; } diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java index 0ad61f8dee..0158e70a60 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java @@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Util.SDK_INT; import android.content.Context; +import android.graphics.Matrix; import android.media.MediaCodec; import android.media.MediaFormat; import androidx.annotation.Nullable; @@ -87,18 +88,19 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ? inputFormatAspectRatio : 1.0f / inputFormatAspectRatio; + Matrix transformationMatrix = new Matrix(transformationRequest.transformationMatrix); // Scale frames by input aspect ratio, to account for FrameEditor's square normalized device // coordinates (-1 to 1) and preserve frame relative dimensions during transformations // (ex. rotations). After this scaling, transformationMatrix operations operate on a rectangle // for x from -displayAspectRatio to displayAspectRatio, and y from -1 to 1 - transformationRequest.transformationMatrix.preScale(displayAspectRatio, 1); - transformationRequest.transformationMatrix.postScale(1.0f / displayAspectRatio, 1); + transformationMatrix.preScale(displayAspectRatio, 1); + transformationMatrix.postScale(1.0f / displayAspectRatio, 1); // The decoder rotates videos to their intended display orientation. The frameEditor rotates // them back for improved encoder compatibility. // TODO(b/201293185): After fragment shader transformations are implemented, put // postRotate in a later vertex shader. - transformationRequest.transformationMatrix.postRotate(outputRotationDegrees); + transformationMatrix.postRotate(outputRotationDegrees); encoder = encoderFactory.createForVideoEncoding( @@ -113,17 +115,18 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; .build()); if (inputFormat.height != outputHeight || inputFormat.width != outputWidth - || !transformationRequest.transformationMatrix.isIdentity()) { + || !transformationMatrix.isIdentity()) { frameEditor = FrameEditor.create( context, outputWidth, outputHeight, inputFormat.pixelWidthHeightRatio, - transformationRequest.transformationMatrix, + transformationMatrix, /* outputSurface= */ checkNotNull(encoder.getInputSurface()), debugViewProvider); } + decoder = decoderFactory.createForVideoDecoding( inputFormat,