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!

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 , 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!

Set 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 Muxer.Factory for muxers that write the media container.

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 EditedMediaItem, 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.

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!

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

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.

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.

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.