diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/Presentation.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/Presentation.java index d0b5f675fb..9c82e156e6 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/Presentation.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/Presentation.java @@ -127,7 +127,7 @@ public final class Presentation implements MatrixTransformation { * Creates a new {@link Presentation} instance. * *

The output frame will have the given height. Width will scale to preserve the input aspect - * ratio. + * ratio. For example, a 1920x1440 video can be scaled to 640x480 by passing a height of 480. * * @param height The height of the output frame, in pixels. */ 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 aecf3ac3e0..d72bdf4693 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 @@ -23,6 +23,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import androidx.annotation.IntDef; import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -128,29 +129,6 @@ public final class TransformationRequest { this.hdrMode = transformationRequest.hdrMode; } - /** - * Sets the output resolution using the output height of the displayed video. - * - *

Output width of the displayed video will scale to preserve the video's aspect ratio after - * other transformations. - * - *

For example, a 1920x1440 video can be scaled to 640x480 by calling setResolution(480). - * - *

The default value, {@link C#LENGTH_UNSET}, leaves the width and height unchanged. - * - *

Note that the output encoded video's dimensions may be swapped from the displayed video's - * dimensions, if the displayed video's height > width. This is to improve compatibility among - * different device encoders. - * - * @param outputHeight The output height of the displayed video, in pixels. - * @return This builder. - */ - @CanIgnoreReturnValue - public Builder setResolution(int outputHeight) { - this.outputHeight = outputHeight; - return this; - } - /** * Sets the video MIME type of the output. * @@ -247,6 +225,13 @@ public final class TransformationRequest { return this; } + @CanIgnoreReturnValue + // TODO(b/255953153): remove this method once fallback has been refactored. + /* package */ Builder setResolution(int outputHeight) { + this.outputHeight = outputHeight; + return this; + } + /** Builds a {@link TransformationRequest} instance. */ public TransformationRequest build() { return new TransformationRequest(outputHeight, audioMimeType, videoMimeType, hdrMode); @@ -254,9 +239,18 @@ public final class TransformationRequest { } /** - * The requested height of the output video, or {@link C#LENGTH_UNSET} if inferred from the input. + * The requested height of the output video. * - * @see Builder#setResolution(int) + *

This field is + * + *

*/ public final int outputHeight; /** diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java index 913eb63223..caf18fc63d 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java @@ -496,8 +496,8 @@ public final class Transformer { } /** - * Called when fallback to an alternative {@link TransformationRequest} is necessary to comply - * with muxer or device constraints. + * Called when falling back to an alternative {@link TransformationRequest} or changing the + * video frames' resolution is necessary to comply with muxer or device constraints. * * @param inputMediaItem The {@link MediaItem} for which the transformation is requested. * @param originalTransformationRequest The unsupported {@link TransformationRequest} used when @@ -658,6 +658,10 @@ public final class Transformer { * ignored. For adaptive bitrate, if no custom {@link AssetLoader.Factory} is specified, the * highest bitrate video and audio streams are selected. * + *

If encoding the output's video track is needed, the output frames' dimensions will be + * swapped if the height is larger than the width. This is to improve compatibility among + * different device encoders. + * * @param editedMediaItem The {@link MediaItem} to transform, with the transformations to apply to * it. * @param path The path to the output file. @@ -684,6 +688,10 @@ public final class Transformer { * ignored. For adaptive bitrate, if no custom {@link AssetLoader.Factory} is specified, the * highest bitrate video and audio streams are selected. * + *

If encoding the output's video track is needed, the output frames' dimensions will be + * swapped if the height is larger than the width. This is to improve compatibility among + * different device encoders. + * * @param editedMediaItem The {@link MediaItem} to transform, with the transformations to apply to * it. * @param parcelFileDescriptor A readable and writable {@link ParcelFileDescriptor} of the output. 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 5e7c4df0b4..bd071d617f 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 @@ -33,7 +33,6 @@ import androidx.annotation.VisibleForTesting; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; -import com.google.android.exoplayer2.effect.Presentation; import com.google.android.exoplayer2.util.Consumer; import com.google.android.exoplayer2.util.DebugViewProvider; import com.google.android.exoplayer2.util.Effect; @@ -125,18 +124,6 @@ import org.checkerframework.dataflow.qual.Pure; encoderOutputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); - // The decoder rotates encoded frames for display by inputFormat.rotationDegrees. - int decodedWidth = - (inputFormat.rotationDegrees % 180 == 0) ? inputFormat.width : inputFormat.height; - int decodedHeight = - (inputFormat.rotationDegrees % 180 == 0) ? inputFormat.height : inputFormat.width; - - ImmutableList.Builder effectsListBuilder = - new ImmutableList.Builder().addAll(effects); - if (transformationRequest.outputHeight != C.LENGTH_UNSET) { - effectsListBuilder.add(Presentation.createForHeight(transformationRequest.outputHeight)); - } - encoderWrapper = new EncoderWrapper( encoderFactory, @@ -165,7 +152,7 @@ import org.checkerframework.dataflow.qual.Pure; frameProcessor = frameProcessorFactory.create( context, - effectsListBuilder.build(), + effects, debugViewProvider, frameProcessorInputColor, frameProcessorOutputColor, @@ -212,6 +199,11 @@ import org.checkerframework.dataflow.qual.Pure; throw TransformationException.createForFrameProcessingException( e, TransformationException.ERROR_CODE_FRAME_PROCESSING_FAILED); } + // The decoder rotates encoded frames for display by inputFormat.rotationDegrees. + int decodedWidth = + (inputFormat.rotationDegrees % 180 == 0) ? inputFormat.width : inputFormat.height; + int decodedHeight = + (inputFormat.rotationDegrees % 180 == 0) ? inputFormat.height : inputFormat.width; firstFrameInfo = new FrameInfo.Builder(decodedWidth, decodedHeight) .setPixelWidthHeightRatio(inputFormat.pixelWidthHeightRatio)