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 forTransformer
instances.
-
-
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 Transformer
build()
Builds aTransformer
instance.Transformer.Builder
setContext(Context context)
Sets theContext
.Transformer.Builder
setFlattenForSlowMotion(boolean flattenForSlowMotion)
Sets whether the input should be flattened for media containing slow motion markers.Transformer.Builder
setListener(Transformer.Listener listener)
Sets theTransformer.Listener
to listen to the transformation events.Transformer.Builder
setLooper(Looper looper)
Sets theLooper
that must be used for all calls to the transformer and that is used to call listeners on.Transformer.Builder
setMediaSourceFactory(MediaSourceFactory mediaSourceFactory)
Sets theMediaSourceFactory
to be used to retrieve the inputs to transform.Transformer.Builder
setOutputMimeType(String outputMimeType)
Sets the MIME type of the output.Transformer.Builder
setRemoveAudio(boolean removeAudio)
Sets whether to remove the audio from the output.Transformer.Builder
setRemoveVideo(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 theMediaSourceFactory
to be used to retrieve the inputs to transform. The default value is aDefaultMediaSourceFactory
built 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 forflattenForSlowMotion
isfalse
.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
MediaSourceFactory
usingsetMediaSourceFactory(MediaSourceFactory)
, make sure thatMp4Extractor.FLAG_READ_SEF_DATA
is set on theMp4Extractor
used. 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_MP4
MimeTypes.VIDEO_WEBM
from API level 21
- Parameters:
outputMimeType
- The MIME type of the output.- Returns:
- This builder.
-
setListener
public Transformer.Builder setListener(Transformer.Listener listener)
Sets theTransformer.Listener
to 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 theLooper
that 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 aTransformer
instance.- Throws:
IllegalStateException
- If theContext
has 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.
-
-