Class TranscodingTransformer.Builder
- java.lang.Object
-
- com.google.android.exoplayer2.transformer.TranscodingTransformer.Builder
-
- Enclosing class:
- TranscodingTransformer
public static final class TranscodingTransformer.Builder extends Object
A builder forTranscodingTransformerinstances.
-
-
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 TranscodingTransformerbuild()Builds aTranscodingTransformerinstance.TranscodingTransformer.BuildersetAudioMimeType(String audioMimeType)Sets the audio MIME type of the output.TranscodingTransformer.BuildersetContext(Context context)Sets theContext.TranscodingTransformer.BuildersetFlattenForSlowMotion(boolean flattenForSlowMotion)Sets whether the input should be flattened for media containing slow motion markers.TranscodingTransformer.BuildersetListener(TranscodingTransformer.Listener listener)Sets theTranscodingTransformer.Listenerto listen to the transformation events.TranscodingTransformer.BuildersetLooper(Looper looper)Sets theLooperthat must be used for all calls to the transcoding transformer and that is used to call listeners on.TranscodingTransformer.BuildersetMediaSourceFactory(MediaSourceFactory mediaSourceFactory)Sets theMediaSourceFactoryto be used to retrieve the inputs to transform.TranscodingTransformer.BuildersetOutputMimeType(String outputMimeType)Sets the MIME type of the output.TranscodingTransformer.BuildersetRemoveAudio(boolean removeAudio)Sets whether to remove the audio from the output.TranscodingTransformer.BuildersetRemoveVideo(boolean removeVideo)Sets whether to remove the video from the output.TranscodingTransformer.BuildersetVideoMimeType(String videoMimeType)Sets the video MIME type of the output.
-
-
-
Method Detail
-
setContext
public TranscodingTransformer.Builder setContext(Context context)
Sets theContext.This parameter is mandatory.
- Parameters:
context- TheContext.- Returns:
- This builder.
-
setMediaSourceFactory
public TranscodingTransformer.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 TranscodingTransformer.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 TranscodingTransformer.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 TranscodingTransformer.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 TranscodingTransformer.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.
-
setVideoMimeType
public TranscodingTransformer.Builder setVideoMimeType(String videoMimeType)
Sets the video MIME type of the output. The default value is to use the same MIME type as the input. Supported values are:- when the container MIME type is
MimeTypes.VIDEO_MP4:MimeTypes.VIDEO_H263MimeTypes.VIDEO_H264MimeTypes.VIDEO_H265from API level 24MimeTypes.VIDEO_MP4V
- when the container MIME type is
MimeTypes.VIDEO_WEBM:MimeTypes.VIDEO_VP8MimeTypes.VIDEO_VP9from API level 24
- Parameters:
videoMimeType- The MIME type of the video samples in the output.- Returns:
- This builder.
- when the container MIME type is
-
setAudioMimeType
public TranscodingTransformer.Builder setAudioMimeType(String audioMimeType)
Sets the audio MIME type of the output. The default value is to use the same MIME type as the input. Supported values are:- when the container MIME type is
MimeTypes.VIDEO_MP4: - when the container MIME type is
MimeTypes.VIDEO_WEBM:
- Parameters:
audioMimeType- The MIME type of the audio samples in the output.- Returns:
- This builder.
- when the container MIME type is
-
setListener
public TranscodingTransformer.Builder setListener(TranscodingTransformer.Listener listener)
Sets theTranscodingTransformer.Listenerto listen to the transformation events.This is equivalent to
TranscodingTransformer.setListener(Listener).- Parameters:
listener- ATranscodingTransformer.Listener.- Returns:
- This builder.
-
setLooper
public TranscodingTransformer.Builder setLooper(Looper looper)
Sets theLooperthat must be used for all calls to the transcoding 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 TranscodingTransformer build()
Builds aTranscodingTransformerinstance.- 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.IllegalStateException- If the muxer doesn't support the requested audio MIME type.
-
-