Class Transformer.Builder
- java.lang.Object
-
- com.google.android.exoplayer2.transformer.Transformer.Builder
-
- Enclosing class:
- Transformer
public static final class Transformer.Builder extends Object
A builder forTransformerinstances.
-
-
Constructor Summary
Constructors Constructor Description Builder()Creates a builder with default values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Transformerbuild()Builds aTransformerinstance.Transformer.BuildersetContext(Context context)Sets theContext.Transformer.BuildersetFlattenForSlowMotion(boolean flattenForSlowMotion)Sets whether the input should be flattened for media containing slow motion markers.Transformer.BuildersetListener(Transformer.Listener listener)Sets theTransformer.Listenerto listen to the transformation events.Transformer.BuildersetLooper(Looper looper)Sets theLooperthat must be used for all calls to the transformer and that is used to call listeners on.Transformer.BuildersetMediaSourceFactory(MediaSourceFactory mediaSourceFactory)Sets theMediaSourceFactoryto be used to retrieve the inputs to transform.Transformer.BuildersetOutputMimeType(String outputMimeType)Sets the MIME type of the output.Transformer.BuildersetRemoveAudio(boolean removeAudio)Sets whether to remove the audio from the output.Transformer.BuildersetRemoveVideo(boolean removeVideo)Sets whether to remove the video from the output.
-
-
-
Method Detail
-
setContext
public Transformer.Builder setContext(Context context)
Sets theContext.This parameter is mandatory.
- Parameters:
context- TheContext.- Returns:
- This builder.
-
setMediaSourceFactory
public Transformer.Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory)
Sets theMediaSourceFactoryto be used to retrieve the inputs to transform. The default value is aDefaultMediaSourceFactorybuilt with the context provided insetContext(Context).- Parameters:
mediaSourceFactory- AMediaSourceFactory.- Returns:
- This builder.
-
setRemoveAudio
public Transformer.Builder setRemoveAudio(boolean removeAudio)
Sets whether to remove the audio from the output. The default value isfalse.The audio and video cannot both be removed because the output would not contain any samples.
- Parameters:
removeAudio- Whether to remove the audio.- Returns:
- This builder.
-
setRemoveVideo
public Transformer.Builder setRemoveVideo(boolean removeVideo)
Sets whether to remove the video from the output. The default value isfalse.The audio and video cannot both be removed because the output would not contain any samples.
- Parameters:
removeVideo- Whether to remove the video.- Returns:
- This builder.
-
setFlattenForSlowMotion
public Transformer.Builder setFlattenForSlowMotion(boolean flattenForSlowMotion)
Sets whether the input should be flattened for media containing slow motion markers. The transformed output is obtained by removing the slow motion metadata and by actually slowing down the parts of the video and audio streams defined in this metadata. The default value forflattenForSlowMotionisfalse.Only Samsung Extension Format (SEF) slow motion metadata type is supported. The transformation has no effect if the input does not contain this metadata type.
For SEF slow motion media, the following assumptions are made on the input:
- The input container format is (unfragmented) MP4.
- The input contains an AVC video elementary stream with temporal SVC.
- The recording frame rate of the video is 120 or 240 fps.
If specifying a
MediaSourceFactoryusingsetMediaSourceFactory(MediaSourceFactory), make sure thatMp4Extractor.FLAG_READ_SEF_DATAis set on theMp4Extractorused. Otherwise, the slow motion metadata will be ignored and the input won't be flattened.- Parameters:
flattenForSlowMotion- Whether to flatten for slow motion.- Returns:
- This builder.
-
setOutputMimeType
public Transformer.Builder setOutputMimeType(String outputMimeType)
Sets the MIME type of the output. The default value isMimeTypes.VIDEO_MP4. Supported values are:MimeTypes.VIDEO_MP4MimeTypes.VIDEO_WEBMfrom API level 21
- Parameters:
outputMimeType- The MIME type of the output.- Returns:
- This builder.
-
setListener
public Transformer.Builder setListener(Transformer.Listener listener)
Sets theTransformer.Listenerto listen to the transformation events.This is equivalent to
Transformer.setListener(Listener).- Parameters:
listener- ATransformer.Listener.- Returns:
- This builder.
-
setLooper
public Transformer.Builder setLooper(Looper looper)
Sets theLooperthat must be used for all calls to the transformer and that is used to call listeners on. The default value is the Looper of the thread that this builder was created on, or if that thread does not have a Looper, the Looper of the application's main thread.- Parameters:
looper- ALooper.- Returns:
- This builder.
-
build
public Transformer build()
Builds aTransformerinstance.- Throws:
IllegalStateException- If theContexthas not been provided.IllegalStateException- If both audio and video have been removed (otherwise the output would not contain any samples).IllegalStateException- If the muxer doesn't support the requested output MIME type.
-
-