Allow video MIME type to be set in TranscodingTransformer.
Also check that the output video MIME type is supported with the given container MIME type in `TranscodingTransformer` and `TransformerBaseRenderer`. PiperOrigin-RevId: 405645362
This commit is contained in:
parent
98200c2692
commit
8545a8b35f
@ -100,6 +100,7 @@ public final class TranscodingTransformer {
|
|||||||
private boolean flattenForSlowMotion;
|
private boolean flattenForSlowMotion;
|
||||||
private String outputMimeType;
|
private String outputMimeType;
|
||||||
@Nullable private String audioMimeType;
|
@Nullable private String audioMimeType;
|
||||||
|
@Nullable private String videoMimeType;
|
||||||
private TranscodingTransformer.Listener listener;
|
private TranscodingTransformer.Listener listener;
|
||||||
private Looper looper;
|
private Looper looper;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
@ -123,6 +124,7 @@ public final class TranscodingTransformer {
|
|||||||
this.flattenForSlowMotion = transcodingTransformer.transformation.flattenForSlowMotion;
|
this.flattenForSlowMotion = transcodingTransformer.transformation.flattenForSlowMotion;
|
||||||
this.outputMimeType = transcodingTransformer.transformation.outputMimeType;
|
this.outputMimeType = transcodingTransformer.transformation.outputMimeType;
|
||||||
this.audioMimeType = transcodingTransformer.transformation.audioMimeType;
|
this.audioMimeType = transcodingTransformer.transformation.audioMimeType;
|
||||||
|
this.videoMimeType = transcodingTransformer.transformation.videoMimeType;
|
||||||
this.listener = transcodingTransformer.listener;
|
this.listener = transcodingTransformer.listener;
|
||||||
this.looper = transcodingTransformer.looper;
|
this.looper = transcodingTransformer.looper;
|
||||||
this.clock = transcodingTransformer.clock;
|
this.clock = transcodingTransformer.clock;
|
||||||
@ -229,6 +231,33 @@ public final class TranscodingTransformer {
|
|||||||
return this;
|
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:
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>when the container MIME type is {@link MimeTypes#VIDEO_MP4}:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link MimeTypes#VIDEO_H263}
|
||||||
|
* <li>{@link MimeTypes#VIDEO_H264}
|
||||||
|
* <li>{@link MimeTypes#VIDEO_H265} from API level 24
|
||||||
|
* <li>{@link MimeTypes#VIDEO_MP4V}
|
||||||
|
* </ul>
|
||||||
|
* <li>when the container MIME type is {@link MimeTypes#VIDEO_WEBM}:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link MimeTypes#VIDEO_VP8}
|
||||||
|
* <li>{@link MimeTypes#VIDEO_VP9} from API level 24
|
||||||
|
* </ul>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @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
|
* Sets the audio MIME type of the output. The default value is to use the same MIME type as the
|
||||||
* input. Supported values are:
|
* input. Supported values are:
|
||||||
@ -329,12 +358,10 @@ public final class TranscodingTransformer {
|
|||||||
muxerFactory.supportsOutputMimeType(outputMimeType),
|
muxerFactory.supportsOutputMimeType(outputMimeType),
|
||||||
"Unsupported output MIME type: " + outputMimeType);
|
"Unsupported output MIME type: " + outputMimeType);
|
||||||
if (audioMimeType != null) {
|
if (audioMimeType != null) {
|
||||||
checkState(
|
checkSampleMimeType(audioMimeType);
|
||||||
muxerFactory.supportsSampleMimeType(audioMimeType, outputMimeType),
|
}
|
||||||
"Unsupported sample MIME type "
|
if (videoMimeType != null) {
|
||||||
+ audioMimeType
|
checkSampleMimeType(videoMimeType);
|
||||||
+ " for container MIME type "
|
|
||||||
+ outputMimeType);
|
|
||||||
}
|
}
|
||||||
Transformation transformation =
|
Transformation transformation =
|
||||||
new Transformation(
|
new Transformation(
|
||||||
@ -343,10 +370,19 @@ public final class TranscodingTransformer {
|
|||||||
flattenForSlowMotion,
|
flattenForSlowMotion,
|
||||||
outputMimeType,
|
outputMimeType,
|
||||||
audioMimeType,
|
audioMimeType,
|
||||||
/* videoMimeType= */ null);
|
videoMimeType);
|
||||||
return new TranscodingTransformer(
|
return new TranscodingTransformer(
|
||||||
context, mediaSourceFactory, muxerFactory, transformation, listener, looper, clock);
|
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. */
|
/** A listener for the transformation events. */
|
||||||
|
@ -58,7 +58,10 @@ import com.google.android.exoplayer2.util.MimeTypes;
|
|||||||
? sampleMimeType
|
? sampleMimeType
|
||||||
: transformation.audioMimeType))
|
: transformation.audioMimeType))
|
||||||
|| (MimeTypes.isVideo(sampleMimeType)
|
|| (MimeTypes.isVideo(sampleMimeType)
|
||||||
&& muxerWrapper.supportsSampleMimeType(sampleMimeType))) {
|
&& muxerWrapper.supportsSampleMimeType(
|
||||||
|
transformation.videoMimeType == null
|
||||||
|
? sampleMimeType
|
||||||
|
: transformation.videoMimeType))) {
|
||||||
return RendererCapabilities.create(C.FORMAT_HANDLED);
|
return RendererCapabilities.create(C.FORMAT_HANDLED);
|
||||||
} else {
|
} else {
|
||||||
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_SUBTYPE);
|
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_SUBTYPE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user