Transformer: Rename setOutputMimeType() to setContainerMimeType().

This mime type is technically for the Muxer, and determines
the container used. In the context of the transformer, this can
be thought of more as a container mime type, to avoid confusion
with the video mime type and audio mime type.

Deprecates setOutputMimeType().

PiperOrigin-RevId: 410530707
This commit is contained in:
huangdarwin 2021-11-17 16:08:53 +00:00 committed by Ian Baker
parent f527fb729c
commit 46e3337bbb
4 changed files with 71 additions and 33 deletions

View File

@ -102,7 +102,7 @@ public final class TranscodingTransformer {
private boolean removeVideo;
private boolean flattenForSlowMotion;
private int outputHeight;
private String outputMimeType;
private String containerMimeType;
@Nullable private String audioMimeType;
@Nullable private String videoMimeType;
private TranscodingTransformer.Listener listener;
@ -113,7 +113,7 @@ public final class TranscodingTransformer {
public Builder() {
muxerFactory = new FrameworkMuxer.Factory();
outputHeight = Transformation.NO_VALUE;
outputMimeType = MimeTypes.VIDEO_MP4;
containerMimeType = MimeTypes.VIDEO_MP4;
listener = new Listener() {};
looper = Util.getCurrentOrMainLooper();
clock = Clock.DEFAULT;
@ -128,7 +128,7 @@ public final class TranscodingTransformer {
this.removeVideo = transcodingTransformer.transformation.removeVideo;
this.flattenForSlowMotion = transcodingTransformer.transformation.flattenForSlowMotion;
this.outputHeight = transcodingTransformer.transformation.outputHeight;
this.outputMimeType = transcodingTransformer.transformation.outputMimeType;
this.containerMimeType = transcodingTransformer.transformation.containerMimeType;
this.audioMimeType = transcodingTransformer.transformation.audioMimeType;
this.videoMimeType = transcodingTransformer.transformation.videoMimeType;
this.listener = transcodingTransformer.listener;
@ -260,11 +260,30 @@ public final class TranscodingTransformer {
* <li>{@link MimeTypes#VIDEO_WEBM} from API level 21
* </ul>
*
* @param outputMimeType The MIME type of the output.
* @param outputMimeType The MIME type of the container.
* @return This builder.
* @deprecated Use {@link #setContainerMimeType} instead.
*/
@Deprecated
public Builder setOutputMimeType(String outputMimeType) {
this.containerMimeType = outputMimeType;
return this;
}
/**
* Sets the MIME type of the output container. The default value is {@link MimeTypes#VIDEO_MP4}.
* Supported values are:
*
* <ul>
* <li>{@link MimeTypes#VIDEO_MP4}
* <li>{@link MimeTypes#VIDEO_WEBM} from API level 21
* </ul>
*
* @param containerMimeType The MIME type of the container.
* @return This builder.
*/
public Builder setOutputMimeType(String outputMimeType) {
this.outputMimeType = outputMimeType;
public Builder setContainerMimeType(String containerMimeType) {
this.containerMimeType = containerMimeType;
return this;
}
@ -379,7 +398,7 @@ public final class TranscodingTransformer {
* @throws IllegalStateException If the {@link Context} has not been provided.
* @throws IllegalStateException If both audio and video have been removed (otherwise the output
* would not contain any samples).
* @throws IllegalStateException If the muxer doesn't support the requested output MIME type.
* @throws IllegalStateException If the muxer doesn't support the requested container MIME type.
* @throws IllegalStateException If the muxer doesn't support the requested audio MIME type.
*/
public TranscodingTransformer build() {
@ -392,8 +411,8 @@ public final class TranscodingTransformer {
mediaSourceFactory = new DefaultMediaSourceFactory(context, defaultExtractorsFactory);
}
checkState(
muxerFactory.supportsOutputMimeType(outputMimeType),
"Unsupported output MIME type: " + outputMimeType);
muxerFactory.supportsOutputMimeType(containerMimeType),
"Unsupported container MIME type: " + containerMimeType);
if (audioMimeType != null) {
checkSampleMimeType(audioMimeType);
}
@ -406,7 +425,7 @@ public final class TranscodingTransformer {
removeVideo,
flattenForSlowMotion,
outputHeight,
outputMimeType,
containerMimeType,
audioMimeType,
videoMimeType);
return new TranscodingTransformer(
@ -415,11 +434,11 @@ public final class TranscodingTransformer {
private void checkSampleMimeType(String sampleMimeType) {
checkState(
muxerFactory.supportsSampleMimeType(sampleMimeType, outputMimeType),
muxerFactory.supportsSampleMimeType(sampleMimeType, containerMimeType),
"Unsupported sample MIME type "
+ sampleMimeType
+ " for container MIME type "
+ outputMimeType);
+ containerMimeType);
}
}
@ -542,7 +561,7 @@ public final class TranscodingTransformer {
* @throws IOException If an error occurs opening the output file for writing.
*/
public void startTransformation(MediaItem mediaItem, String path) throws IOException {
startTransformation(mediaItem, muxerFactory.create(path, transformation.outputMimeType));
startTransformation(mediaItem, muxerFactory.create(path, transformation.containerMimeType));
}
/**
@ -573,7 +592,7 @@ public final class TranscodingTransformer {
public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor)
throws IOException {
startTransformation(
mediaItem, muxerFactory.create(parcelFileDescriptor, transformation.outputMimeType));
mediaItem, muxerFactory.create(parcelFileDescriptor, transformation.containerMimeType));
}
private void startTransformation(MediaItem mediaItem, Muxer muxer) {
@ -583,7 +602,7 @@ public final class TranscodingTransformer {
}
MuxerWrapper muxerWrapper =
new MuxerWrapper(muxer, muxerFactory, transformation.outputMimeType);
new MuxerWrapper(muxer, muxerFactory, transformation.containerMimeType);
this.muxerWrapper = muxerWrapper;
DefaultTrackSelector trackSelector = new DefaultTrackSelector(context);
trackSelector.setParameters(

View File

@ -28,7 +28,7 @@ import androidx.annotation.Nullable;
public final boolean removeVideo;
public final boolean flattenForSlowMotion;
public final int outputHeight;
public final String outputMimeType;
public final String containerMimeType;
@Nullable public final String audioMimeType;
@Nullable public final String videoMimeType;
@ -37,14 +37,14 @@ import androidx.annotation.Nullable;
boolean removeVideo,
boolean flattenForSlowMotion,
int outputHeight,
String outputMimeType,
String containerMimeType,
@Nullable String audioMimeType,
@Nullable String videoMimeType) {
this.removeAudio = removeAudio;
this.removeVideo = removeVideo;
this.flattenForSlowMotion = flattenForSlowMotion;
this.outputHeight = outputHeight;
this.outputMimeType = outputMimeType;
this.containerMimeType = containerMimeType;
this.audioMimeType = audioMimeType;
this.videoMimeType = videoMimeType;
}

View File

@ -97,7 +97,7 @@ public final class Transformer {
private boolean removeAudio;
private boolean removeVideo;
private boolean flattenForSlowMotion;
private String outputMimeType;
private String containerMimeType;
private Transformer.Listener listener;
private Looper looper;
private Clock clock;
@ -105,7 +105,7 @@ public final class Transformer {
/** Creates a builder with default values. */
public Builder() {
muxerFactory = new FrameworkMuxer.Factory();
outputMimeType = MimeTypes.VIDEO_MP4;
containerMimeType = MimeTypes.VIDEO_MP4;
listener = new Listener() {};
looper = Util.getCurrentOrMainLooper();
clock = Clock.DEFAULT;
@ -119,7 +119,7 @@ public final class Transformer {
this.removeAudio = transformer.transformation.removeAudio;
this.removeVideo = transformer.transformation.removeVideo;
this.flattenForSlowMotion = transformer.transformation.flattenForSlowMotion;
this.outputMimeType = transformer.transformation.outputMimeType;
this.containerMimeType = transformer.transformation.containerMimeType;
this.listener = transformer.listener;
this.looper = transformer.looper;
this.clock = transformer.clock;
@ -218,11 +218,30 @@ public final class Transformer {
* <li>{@link MimeTypes#VIDEO_WEBM} from API level 21
* </ul>
*
* @param outputMimeType The MIME type of the output.
* @param outputMimeType The MIME type of the container.
* @return This builder.
* @deprecated Use {@link #setContainerMimeType} instead.
*/
@Deprecated
public Builder setOutputMimeType(String outputMimeType) {
this.containerMimeType = outputMimeType;
return this;
}
/**
* Sets the MIME type of the output container. The default value is {@link MimeTypes#VIDEO_MP4}.
* Supported values are:
*
* <ul>
* <li>{@link MimeTypes#VIDEO_MP4}
* <li>{@link MimeTypes#VIDEO_WEBM} from API level 21
* </ul>
*
* @param containerMimeType The MIME type of the output.
* @return This builder.
*/
public Builder setOutputMimeType(String outputMimeType) {
this.outputMimeType = outputMimeType;
public Builder setContainerMimeType(String containerMimeType) {
this.containerMimeType = containerMimeType;
return this;
}
@ -285,7 +304,7 @@ public final class Transformer {
* @throws IllegalStateException If the {@link Context} has not been provided.
* @throws IllegalStateException If both audio and video have been removed (otherwise the output
* would not contain any samples).
* @throws IllegalStateException If the muxer doesn't support the requested output MIME type.
* @throws IllegalStateException If the muxer doesn't support the requested container MIME type.
*/
public Transformer build() {
checkStateNotNull(context);
@ -297,15 +316,15 @@ public final class Transformer {
mediaSourceFactory = new DefaultMediaSourceFactory(context, defaultExtractorsFactory);
}
checkState(
muxerFactory.supportsOutputMimeType(outputMimeType),
"Unsupported output MIME type: " + outputMimeType);
muxerFactory.supportsOutputMimeType(containerMimeType),
"Unsupported container MIME type: " + containerMimeType);
Transformation transformation =
new Transformation(
removeAudio,
removeVideo,
flattenForSlowMotion,
/* outputHeight= */ Transformation.NO_VALUE,
outputMimeType,
containerMimeType,
/* audioMimeType= */ null,
/* videoMimeType= */ null);
return new Transformer(
@ -430,7 +449,7 @@ public final class Transformer {
* @throws IOException If an error occurs opening the output file for writing.
*/
public void startTransformation(MediaItem mediaItem, String path) throws IOException {
startTransformation(mediaItem, muxerFactory.create(path, transformation.outputMimeType));
startTransformation(mediaItem, muxerFactory.create(path, transformation.containerMimeType));
}
/**
@ -461,7 +480,7 @@ public final class Transformer {
public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor)
throws IOException {
startTransformation(
mediaItem, muxerFactory.create(parcelFileDescriptor, transformation.outputMimeType));
mediaItem, muxerFactory.create(parcelFileDescriptor, transformation.containerMimeType));
}
private void startTransformation(MediaItem mediaItem, Muxer muxer) {
@ -471,7 +490,7 @@ public final class Transformer {
}
MuxerWrapper muxerWrapper =
new MuxerWrapper(muxer, muxerFactory, transformation.outputMimeType);
new MuxerWrapper(muxer, muxerFactory, transformation.containerMimeType);
this.muxerWrapper = muxerWrapper;
DefaultTrackSelector trackSelector = new DefaultTrackSelector(context);
trackSelector.setParameters(

View File

@ -30,10 +30,10 @@ import org.junit.runner.RunWith;
public class TransformerBuilderTest {
@Test
public void setOutputMimeType_unsupportedMimeType_throws() {
public void setContainerMimeType_unsupportedMimeType_throws() {
assertThrows(
IllegalStateException.class,
() -> new Transformer.Builder().setOutputMimeType(MimeTypes.VIDEO_FLV).build());
() -> new Transformer.Builder().setContainerMimeType(MimeTypes.VIDEO_FLV).build());
}
@Test