Commit 18a15fb9 by huangdarwin Committed by tonihei

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
parent f401d462
...@@ -37,7 +37,7 @@ Transformer transformer = ...@@ -37,7 +37,7 @@ Transformer transformer =
new Transformer.Builder() new Transformer.Builder()
.setContext(context) .setContext(context)
.setRemoveAudio(true) .setRemoveAudio(true)
.setOutputMimeType(MimeTypes.VIDEO_WEBM) .setContainerMimeType(MimeTypes.VIDEO_WEBM)
.setListener(transformerListener) .setListener(transformerListener)
.build(); .build();
// Start the transformation. // Start the transformation.
......
...@@ -100,7 +100,7 @@ public final class TranscodingTransformer { ...@@ -100,7 +100,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;
...@@ -111,7 +111,7 @@ public final class TranscodingTransformer { ...@@ -111,7 +111,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;
...@@ -126,7 +126,7 @@ public final class TranscodingTransformer { ...@@ -126,7 +126,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;
...@@ -258,11 +258,30 @@ public final class TranscodingTransformer { ...@@ -258,11 +258,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. * @return This builder.
* @deprecated Use {@link #setContainerMimeType} instead.
*/ */
@Deprecated
public Builder setOutputMimeType(String outputMimeType) { public Builder setOutputMimeType(String outputMimeType) {
this.outputMimeType = 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 setContainerMimeType(String containerMimeType) {
this.containerMimeType = containerMimeType;
return this; return this;
} }
...@@ -377,7 +396,7 @@ public final class TranscodingTransformer { ...@@ -377,7 +396,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() {
...@@ -390,8 +409,8 @@ public final class TranscodingTransformer { ...@@ -390,8 +409,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);
} }
...@@ -404,7 +423,7 @@ public final class TranscodingTransformer { ...@@ -404,7 +423,7 @@ public final class TranscodingTransformer {
removeVideo, removeVideo,
flattenForSlowMotion, flattenForSlowMotion,
outputHeight, outputHeight,
outputMimeType, containerMimeType,
audioMimeType, audioMimeType,
videoMimeType); videoMimeType);
return new TranscodingTransformer( return new TranscodingTransformer(
...@@ -413,11 +432,11 @@ public final class TranscodingTransformer { ...@@ -413,11 +432,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);
} }
} }
...@@ -540,7 +559,7 @@ public final class TranscodingTransformer { ...@@ -540,7 +559,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));
} }
/** /**
...@@ -571,7 +590,7 @@ public final class TranscodingTransformer { ...@@ -571,7 +590,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) {
...@@ -581,7 +600,7 @@ public final class TranscodingTransformer { ...@@ -581,7 +600,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(
......
...@@ -28,7 +28,7 @@ import androidx.annotation.Nullable; ...@@ -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; ...@@ -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;
} }
......
...@@ -95,7 +95,7 @@ public final class Transformer { ...@@ -95,7 +95,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;
...@@ -103,7 +103,7 @@ public final class Transformer { ...@@ -103,7 +103,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;
...@@ -117,7 +117,7 @@ public final class Transformer { ...@@ -117,7 +117,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;
...@@ -216,11 +216,30 @@ public final class Transformer { ...@@ -216,11 +216,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. * @return This builder.
* @deprecated Use {@link #setContainerMimeType} instead.
*/ */
@Deprecated
public Builder setOutputMimeType(String outputMimeType) { public Builder setOutputMimeType(String outputMimeType) {
this.outputMimeType = 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 setContainerMimeType(String containerMimeType) {
this.containerMimeType = containerMimeType;
return this; return this;
} }
...@@ -283,7 +302,7 @@ public final class Transformer { ...@@ -283,7 +302,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);
...@@ -295,15 +314,15 @@ public final class Transformer { ...@@ -295,15 +314,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(
...@@ -428,7 +447,7 @@ public final class Transformer { ...@@ -428,7 +447,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));
} }
/** /**
...@@ -459,7 +478,7 @@ public final class Transformer { ...@@ -459,7 +478,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) {
...@@ -469,7 +488,7 @@ public final class Transformer { ...@@ -469,7 +488,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(
......
...@@ -30,10 +30,10 @@ import org.junit.runner.RunWith; ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment