mirror of
https://github.com/androidx/media.git
synced 2025-05-14 02:59:52 +08:00
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 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:
|
||||
*
|
||||
* <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
|
||||
* 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. */
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user