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

View File

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

View File

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

View File

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