Transformer.Builder


class Transformer.Builder


A builder for Transformer instances.

Summary

Public constructors

Builder(context: Context!)

Creates a builder with default values.

Public functions

Transformer.Builder!

Adds a Transformer.Listener to listen to the export events.

Transformer!

Builds a Transformer instance.

Transformer.Builder!

Limits how many video frames can be processed at any time by the encoder.

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.

Transformer.Builder!

Removes all listeners.

Transformer.Builder!

Removes a Transformer.Listener.

Transformer.Builder!

Sets the AssetLoader.Factory to be used to retrieve the samples to export.

Transformer.Builder!

Sets the audio MIME type of the output.

Transformer.Builder!

Sets the AudioMixer.Factory to be used when audio mixing is needed.

Transformer.Builder!

This function is deprecated.

Set the audio processors in an setEffects, and pass it to start instead.

Transformer.Builder!

Sets a provider for views to show diagnostic information (if available) during export.

Transformer.Builder!

Sets the Codec.EncoderFactory that will be used by the transformer.

Transformer.Builder!

Sets whether to ensure that the output file starts on a video frame.

Transformer.Builder!

This function is deprecated.

Use setFlattenForSlowMotion to flatten the EditedMediaItem passed to start instead.

Transformer.Builder!

This function is deprecated.

Use addListener, removeListener or removeAllListeners instead.

Transformer.Builder!

Sets the Looper that must be used for all calls to the transformer and that is used to call listeners on.

Transformer.Builder!

Sets the maximum delay allowed between output samples regardless of the track type, or TIME_UNSET if there is no maximum.

Transformer.Builder!

Sets the Muxer.Factory for muxers that write the media container.

Transformer.Builder!

Sets whether to encode portrait videos in portrait orientation.

Transformer.Builder!

This function is deprecated.

Use setRemoveAudio to remove the audio from the EditedMediaItem passed to start instead.

Transformer.Builder!

This function is deprecated.

Use setRemoveVideo to remove the video from the EditedMediaItem passed to start instead.

Transformer.Builder!

This function is deprecated.

Use setAudioMimeType, setVideoMimeType and setHdrMode instead.

Transformer.Builder!

This function is deprecated.

Set the video effects in an setEffects, and pass it to start instead.

Transformer.Builder!

Sets the VideoFrameProcessor.Factory to be used to create VideoFrameProcessor instances.

Transformer.Builder!

Sets the video MIME type of the output.

Public constructors

Builder

Builder(context: Context!)

Creates a builder with default values.

Parameters
context: Context!

The Context.

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!

A 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.

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 INDEX_UNSET if no limit is enforced.

Returns
Transformer.Builder!

This builder.

Throws
java.lang.IllegalArgumentException

If maxFramesInEncoder is not equal to INDEX_UNSET and is non-positive.

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 EditedMediaItem in the whole Composition) 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!

A 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 and a DefaultDecoderFactory.

Parameters
assetLoaderFactory: AssetLoader.Factory!

An 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 MIME type.

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!

A AudioMixer.Factory.

Returns
Transformer.Builder!

This builder.

setAudioProcessors

@CanIgnoreReturnValue
fun setAudioProcessors(audioProcessors: (Mutable)List<AudioProcessor!>!): Transformer.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 Codec.EncoderFactory instance.

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 is set.

Parameters
enabled: Boolean

Whether to ensure that the file starts on a video frame.

Returns
Transformer.Builder!

This builder.

setFlattenForSlowMotion

@CanIgnoreReturnValue
fun setFlattenForSlowMotion(flattenForSlowMotion: Boolean): Transformer.Builder!

setListener

@CanIgnoreReturnValue
fun setListener(listener: Transformer.Listener!): Transformer.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.

Parameters
looper: Looper!

A Looper.

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!

A 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.

setRemoveAudio

@CanIgnoreReturnValue
fun setRemoveAudio(removeAudio: Boolean): Transformer.Builder!

setRemoveVideo

@CanIgnoreReturnValue
fun setRemoveVideo(removeVideo: Boolean): Transformer.Builder!

setTransformationRequest

@CanIgnoreReturnValue
fun setTransformationRequest(transformationRequest: TransformationRequest!): Transformer.Builder!

setVideoEffects

@CanIgnoreReturnValue
fun setVideoEffects(effects: (Mutable)List<Effect!>!): Transformer.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 .

Parameters
videoFrameProcessorFactory: VideoFrameProcessor.Factory!

A 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:

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
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 MIME type.