diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TranscodingTransformer.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TranscodingTransformer.java
index 8e622c2a9a..d766987aa8 100644
--- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TranscodingTransformer.java
+++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TranscodingTransformer.java
@@ -100,6 +100,7 @@ public final class TranscodingTransformer {
private boolean flattenForSlowMotion;
private String outputMimeType;
@Nullable private String audioMimeType;
+ @Nullable private String videoMimeType;
private TranscodingTransformer.Listener listener;
private Looper looper;
private Clock clock;
@@ -123,6 +124,7 @@ public final class TranscodingTransformer {
this.flattenForSlowMotion = transcodingTransformer.transformation.flattenForSlowMotion;
this.outputMimeType = transcodingTransformer.transformation.outputMimeType;
this.audioMimeType = transcodingTransformer.transformation.audioMimeType;
+ this.videoMimeType = transcodingTransformer.transformation.videoMimeType;
this.listener = transcodingTransformer.listener;
this.looper = transcodingTransformer.looper;
this.clock = transcodingTransformer.clock;
@@ -229,6 +231,33 @@ public final class TranscodingTransformer {
return this;
}
+ /**
+ * Sets the video MIME type of the output. The default value is to use the same MIME type as the
+ * input. Supported values are:
+ *
+ *
+ * - when the container MIME type is {@link MimeTypes#VIDEO_MP4}:
+ *
+ * - {@link MimeTypes#VIDEO_H263}
+ *
- {@link MimeTypes#VIDEO_H264}
+ *
- {@link MimeTypes#VIDEO_H265} from API level 24
+ *
- {@link MimeTypes#VIDEO_MP4V}
+ *
+ * - when the container MIME type is {@link MimeTypes#VIDEO_WEBM}:
+ *
+ * - {@link MimeTypes#VIDEO_VP8}
+ *
- {@link MimeTypes#VIDEO_VP9} from API level 24
+ *
+ *
+ *
+ * @param videoMimeType The MIME type of the video samples in the output.
+ * @return This builder.
+ */
+ public Builder setVideoMimeType(String videoMimeType) {
+ this.videoMimeType = videoMimeType;
+ return this;
+ }
+
/**
* Sets the audio MIME type of the output. The default value is to use the same MIME type as the
* input. Supported values are:
@@ -329,12 +358,10 @@ public final class TranscodingTransformer {
muxerFactory.supportsOutputMimeType(outputMimeType),
"Unsupported output MIME type: " + outputMimeType);
if (audioMimeType != null) {
- checkState(
- muxerFactory.supportsSampleMimeType(audioMimeType, outputMimeType),
- "Unsupported sample MIME type "
- + audioMimeType
- + " for container MIME type "
- + outputMimeType);
+ checkSampleMimeType(audioMimeType);
+ }
+ if (videoMimeType != null) {
+ checkSampleMimeType(videoMimeType);
}
Transformation transformation =
new Transformation(
@@ -343,10 +370,19 @@ public final class TranscodingTransformer {
flattenForSlowMotion,
outputMimeType,
audioMimeType,
- /* videoMimeType= */ null);
+ videoMimeType);
return new TranscodingTransformer(
context, mediaSourceFactory, muxerFactory, transformation, listener, looper, clock);
}
+
+ private void checkSampleMimeType(String sampleMimeType) {
+ checkState(
+ muxerFactory.supportsSampleMimeType(sampleMimeType, outputMimeType),
+ "Unsupported sample MIME type "
+ + sampleMimeType
+ + " for container MIME type "
+ + outputMimeType);
+ }
}
/** A listener for the transformation events. */
diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerBaseRenderer.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerBaseRenderer.java
index 4f2243000d..e0ceb945fc 100644
--- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerBaseRenderer.java
+++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerBaseRenderer.java
@@ -58,7 +58,10 @@ import com.google.android.exoplayer2.util.MimeTypes;
? sampleMimeType
: transformation.audioMimeType))
|| (MimeTypes.isVideo(sampleMimeType)
- && muxerWrapper.supportsSampleMimeType(sampleMimeType))) {
+ && muxerWrapper.supportsSampleMimeType(
+ transformation.videoMimeType == null
+ ? sampleMimeType
+ : transformation.videoMimeType))) {
return RendererCapabilities.create(C.FORMAT_HANDLED);
} else {
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_SUBTYPE);