Transformer.Builder
class Transformer.Builder
A builder for Transformer instances.
Summary
Public functions |
|
|---|---|
Transformer.Builder! |
@CanIgnoreReturnValueAdds a |
Transformer! |
build()Builds a |
Transformer.Builder! |
@CanIgnoreReturnValueLimits how many video frames can be processed at any time by the |
Transformer.Builder! |
Sets whether to use an MP4 edit list for trimming, to instruct players to ignore frames between the key frame before the trim start point, and the trim start point. |
Transformer.Builder! |
Sets whether to attempt to optimize trims from the start of the |
Transformer.Builder! |
Removes all |
Transformer.Builder! |
@CanIgnoreReturnValueRemoves a |
Transformer.Builder! |
@CanIgnoreReturnValueSets the |
Transformer.Builder! |
@CanIgnoreReturnValueSets the audio |
Transformer.Builder! |
@CanIgnoreReturnValueSets the |
Transformer.Builder! |
Sets the |
Transformer.Builder! |
@CanIgnoreReturnValueSets a provider for views to show diagnostic information (if available) during export. |
Transformer.Builder! |
@CanIgnoreReturnValueSets the |
Transformer.Builder! |
Sets whether to ensure that the output file starts on a video frame. |
Transformer.Builder! |
@CanIgnoreReturnValueSets the |
Transformer.Builder! |
@CanIgnoreReturnValueSets the maximum delay allowed between output samples regardless of the track type, or |
Transformer.Builder! |
@CanIgnoreReturnValueSets the |
Transformer.Builder! |
Sets whether to encode portrait videos in portrait orientation. |
Transformer.Builder! |
@CanIgnoreReturnValueSets whether transformer reports diagnostics data to the Android platform. |
Transformer.Builder! |
@CanIgnoreReturnValueSets the |
Transformer.Builder! |
@CanIgnoreReturnValueSets the video |
Public constructors
Public functions
addListener
@CanIgnoreReturnValue
fun addListener(listener: Transformer.Listener!): Transformer.Builder!
Adds a Transformer.Listener to listen to the export events.
This is equivalent to addListener.
| Parameters | |
|---|---|
listener: Transformer.Listener! |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
build
fun build(): Transformer!
Builds a Transformer instance.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If both audio and video have been removed (otherwise the output would not contain any samples). |
java.lang.IllegalStateException |
If the muxer doesn't support the requested audio/video MIME type. |
java.lang.IllegalStateException |
If |
experimentalSetMaxFramesInEncoder
@CanIgnoreReturnValue
fun experimentalSetMaxFramesInEncoder(maxFramesInEncoder: Int): Transformer.Builder!
Limits how many video frames can be processed at any time by the encoder.
A video frame starts encoding when it enters the encoder input surface, and finishes encoding when the corresponding encoder output buffer is released.
The default value is INDEX_UNSET, which means no limit is enforced.
This method is experimental and will be renamed or removed in a future release.
| Parameters | |
|---|---|
maxFramesInEncoder: Int |
The maximum number of frames that the video encoder is allowed to process at a time, or |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If |
experimentalSetMp4EditListTrimEnabled
@CanIgnoreReturnValue
fun experimentalSetMp4EditListTrimEnabled(enabled: Boolean): Transformer.Builder!
Sets whether to use an MP4 edit list for trimming, to instruct players to ignore frames between the key frame before the trim start point, and the trim start point.
This optimization has the following limitations, and will throw an IllegalStateException if they are not met:
- Transformer is configured with any
Muxer.FactorywheresupportsWritingNegativeTimestampsInEditListis false. It is recommended to useInAppMp4Muxer.Factory. - Transformer has to transcode for any reason while trimming (such as if any video effects, apart from 90, 180 and 270 degree rotations are applied while trimming).
This optimization will be ignored in the following cases:
- Transformer input contains multiple assets (i.e. there is more than one
EditedMediaItemin theComposition). - Transformer input contains a single
MediaItembut theclipping configurationis not set.
If players do not respect the edit list the output file will be played from the key frame before the trim start point rather than the requested trim start point.
| Parameters | |
|---|---|
enabled: Boolean |
Whether to enable mp4 edit list trimming. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
experimentalSetTrimOptimizationEnabled
@CanIgnoreReturnValue
fun experimentalSetTrimOptimizationEnabled(enabled: Boolean): Transformer.Builder!
Sets whether to attempt to optimize trims from the start of the EditedMediaItem by transcoding as little of the file as possible and transmuxing the rest.
This optimization has the following limitations:
- Only supported for single-asset (i.e. only one
EditedMediaItemin the wholeComposition) exports of mp4 files. - Not guaranteed to work with any effects.
This process relies on the given EncoderFactory providing the right encoder level and profiles when transcoding, so that the transcoded and transmuxed segments of the file can be stitched together. If the file segments can't be stitched together, Transformer throw away any progress and proceed with unoptimized export instead.
The optimizationResult will indicate whether the optimization was applied.
| Parameters | |
|---|---|
enabled: Boolean |
Whether to enable trim optimization. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
removeAllListeners
@CanIgnoreReturnValue
fun removeAllListeners(): Transformer.Builder!
Removes all listeners.
This is equivalent to removeAllListeners.
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
removeListener
@CanIgnoreReturnValue
fun removeListener(listener: Transformer.Listener!): Transformer.Builder!
Removes a Transformer.Listener.
This is equivalent to removeListener.
| Parameters | |
|---|---|
listener: Transformer.Listener! |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setAssetLoaderFactory
@CanIgnoreReturnValue
fun setAssetLoaderFactory(assetLoaderFactory: AssetLoader.Factory!): Transformer.Builder!
Sets the AssetLoader.Factory to be used to retrieve the samples to export.
The default value is a DefaultAssetLoaderFactory built with a DefaultMediaSourceFactory and a DefaultDecoderFactory.
| Parameters | |
|---|---|
assetLoaderFactory: AssetLoader.Factory! |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setAudioMimeType
@CanIgnoreReturnValue
fun setAudioMimeType(audioMimeType: String!): Transformer.Builder!
Sets the audio MIME type of the output.
If no audio MIME type is passed, the output audio MIME type is the same as the first MediaItem in the Composition.
Supported MIME types are:
If the MIME type is not supported,Transformer will fallback to a supported MIME type and onFallbackApplied will be invoked with the fallback value.
| Parameters | |
|---|---|
audioMimeType: String! |
The MIME type of the audio samples in the output. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If the audio MIME type passed is not an audio |
setAudioMixerFactory
@CanIgnoreReturnValue
fun setAudioMixerFactory(audioMixerFactory: AudioMixer.Factory!): Transformer.Builder!
Sets the AudioMixer.Factory to be used when audio mixing is needed.
The default value is a DefaultAudioMixer.Factory with default values.
| Parameters | |
|---|---|
audioMixerFactory: AudioMixer.Factory! |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setClock
@CanIgnoreReturnValue
@VisibleForTesting
fun setClock(clock: Clock!): Transformer.Builder!
Sets the Clock that will be used by the transformer.
The default value is DEFAULT.
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setDebugViewProvider
@CanIgnoreReturnValue
fun setDebugViewProvider(debugViewProvider: DebugViewProvider!): Transformer.Builder!
Sets a provider for views to show diagnostic information (if available) during export.
This is intended for debugging. The default value is NONE, which doesn't show any debug info.
Not all exports will result in debug views being populated.
| Parameters | |
|---|---|
debugViewProvider: DebugViewProvider! |
Provider for debug views. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setEncoderFactory
@CanIgnoreReturnValue
fun setEncoderFactory(encoderFactory: Codec.EncoderFactory!): Transformer.Builder!
Sets the Codec.EncoderFactory that will be used by the transformer.
The default value is a DefaultEncoderFactory instance.
| Parameters | |
|---|---|
encoderFactory: Codec.EncoderFactory! |
The |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setEnsureFileStartsOnVideoFrameEnabled
@CanIgnoreReturnValue
fun setEnsureFileStartsOnVideoFrameEnabled(enabled: Boolean): Transformer.Builder!
Sets whether to ensure that the output file starts on a video frame.
Any audio samples that are earlier than the first video frame will be dropped. This can make the output of trimming operations more compatible with player implementations that don't show the first video frame until its presentation timestamp.
Ignored when trim optimization or trimming with MP4 edit list is set.
| Parameters | |
|---|---|
enabled: Boolean |
Whether to ensure that the file starts on a video frame. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setLooper
@CanIgnoreReturnValue
fun setLooper(looper: Looper!): Transformer.Builder!
Sets the Looper 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.
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setMaxDelayBetweenMuxerSamplesMs
@CanIgnoreReturnValue
fun setMaxDelayBetweenMuxerSamplesMs(maxDelayBetweenMuxerSamplesMs: Long): Transformer.Builder!
Sets the maximum delay allowed between output samples regardless of the track type, or TIME_UNSET if there is no maximum. The default value is DEFAULT_MAX_DELAY_BETWEEN_MUXER_SAMPLES_MS.
The export will be aborted when no sample is written in
maxDelayBetweenMuxerSamplesMs. Note that there is no guarantee that the export will be aborted exactly at that time.
| Parameters | |
|---|---|
maxDelayBetweenMuxerSamplesMs: Long |
The maximum delay allowed (in microseconds). |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setMuxerFactory
@CanIgnoreReturnValue
fun setMuxerFactory(muxerFactory: Muxer.Factory!): Transformer.Builder!
Sets the Muxer.Factory for muxers that write the media container.
The default value is a DefaultMuxer.Factory.
| Parameters | |
|---|---|
muxerFactory: Muxer.Factory! |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setPortraitEncodingEnabled
@CanIgnoreReturnValue
fun setPortraitEncodingEnabled(enabled: Boolean): Transformer.Builder!
Sets whether to encode portrait videos in portrait orientation.
The default value is false. In this case, portrait videos will be rotated by 90 degrees before being encoded, and metadata will be added to the output file to indicate that the video should be rotated back when played. This is done because encoding landscape videos is more largely supported. Enabling portrait encoding should therefore be done carefully because it is likely to result in more failures.
| Parameters | |
|---|---|
enabled: Boolean |
Whether to encode portrait videos in portrait orientation. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setUsePlatformDiagnostics
@CanIgnoreReturnValue
fun setUsePlatformDiagnostics(usePlatformDiagnostics: Boolean): Transformer.Builder!
Sets whether transformer reports diagnostics data to the Android platform.
If enabled, transformer will use the android.media.metrics.MediaMetricsManager to create an android.media.metrics.EditingSession and forward editing events and performance data to this session. This helps to provide system performance and debugging information for media editing on this device. This data may also be collected by Google if sharing usage and diagnostics data is enabled by the user of the device.
The default value is true.
| Parameters | |
|---|---|
usePlatformDiagnostics: Boolean |
Whether transformer reports diagnostics data to the Android platform. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setVideoFrameProcessorFactory
@CanIgnoreReturnValue
fun setVideoFrameProcessorFactory(
videoFrameProcessorFactory: VideoFrameProcessor.Factory!
): Transformer.Builder!
Sets the VideoFrameProcessor.Factory to be used to create VideoFrameProcessor instances.
The default value is a DefaultVideoFrameProcessor.Factory built with default values.
If passing in a DefaultVideoFrameProcessor.Factory, the caller must not set the texture output.
If exporting a Composition with multiple video sequences, the VideoFrameProcessor.Factory must be a DefaultVideoFrameProcessor.Factory.
| Parameters | |
|---|---|
videoFrameProcessorFactory: VideoFrameProcessor.Factory! |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
setVideoMimeType
@CanIgnoreReturnValue
fun setVideoMimeType(videoMimeType: String!): Transformer.Builder!
Sets the video MIME type of the output.
If no video MIME type is passed, the output video MIME type is the same as the first MediaItem in the Composition.
Supported MIME types are:
VIDEO_H263VIDEO_H264VIDEO_H265from API level 24VIDEO_MP4V
Transformer will fallback to a supported MIME type and onFallbackApplied will be invoked with the fallback value.
| Parameters | |
|---|---|
videoMimeType: String! |
The MIME type of the video samples in the output. |
| Returns | |
|---|---|
Transformer.Builder! |
This builder. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If the video MIME type passed is not a video |