Transformer.Builder


public final class Transformer.Builder


A builder for Transformer instances.

Summary

Public constructors

Builder(Context context)

Creates a builder with default values.

Public methods

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 method 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
@CanIgnoreReturnValue
setFlattenForSlowMotion(boolean flattenForSlowMotion)

This method is deprecated.

Use setFlattenForSlowMotion to flatten the EditedMediaItem passed to start instead.

Transformer.Builder

This method 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
@CanIgnoreReturnValue
setRemoveAudio(boolean removeAudio)

This method is deprecated.

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

Transformer.Builder
@CanIgnoreReturnValue
setRemoveVideo(boolean removeVideo)

This method is deprecated.

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

Transformer.Builder

This method is deprecated.

Use setAudioMimeType, setVideoMimeType and setHdrMode instead.

Transformer.Builder

This method 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

public Builder(Context context)

Creates a builder with default values.

Parameters
Context context

The Context.

Public methods

addListener

@CanIgnoreReturnValue
public Transformer.Builder addListener(Transformer.Listener listener)

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

This is equivalent to addListener.

Parameters
Transformer.Listener listener

A Transformer.Listener.

Returns
Transformer.Builder

This builder.

build

public Transformer build()

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
public Transformer.Builder experimentalSetTrimOptimizationEnabled(boolean enabled)

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
boolean enabled

Whether to enable trim optimization.

Returns
Transformer.Builder

This builder.

removeAllListeners

@CanIgnoreReturnValue
public Transformer.Builder removeAllListeners()

Removes all listeners.

This is equivalent to removeAllListeners.

Returns
Transformer.Builder

This builder.

removeListener

@CanIgnoreReturnValue
public Transformer.Builder removeListener(Transformer.Listener listener)

Removes a Transformer.Listener.

This is equivalent to removeListener.

Parameters
Transformer.Listener listener

A Transformer.Listener.

Returns
Transformer.Builder

This builder.

setAssetLoaderFactory

@CanIgnoreReturnValue
public Transformer.Builder setAssetLoaderFactory(AssetLoader.Factory assetLoaderFactory)

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
AssetLoader.Factory assetLoaderFactory

An AssetLoader.Factory.

Returns
Transformer.Builder

This builder.

setAudioMimeType

@CanIgnoreReturnValue
public Transformer.Builder setAudioMimeType(String audioMimeType)

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
String audioMimeType

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
public Transformer.Builder setAudioMixerFactory(AudioMixer.Factory audioMixerFactory)

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

The default value is a DefaultAudioMixer.Factory with default values.

Parameters
AudioMixer.Factory audioMixerFactory

A AudioMixer.Factory.

Returns
Transformer.Builder

This builder.

setAudioProcessors

@CanIgnoreReturnValue
public Transformer.Builder setAudioProcessors(List<AudioProcessor> audioProcessors)

setDebugViewProvider

@CanIgnoreReturnValue
public Transformer.Builder setDebugViewProvider(DebugViewProvider debugViewProvider)

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
public Transformer.Builder setEncoderFactory(Codec.EncoderFactory encoderFactory)

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

The default value is a DefaultEncoderFactory instance.

Parameters
Codec.EncoderFactory encoderFactory

The Codec.EncoderFactory instance.

Returns
Transformer.Builder

This builder.

setEnsureFileStartsOnVideoFrameEnabled

@CanIgnoreReturnValue
public Transformer.Builder setEnsureFileStartsOnVideoFrameEnabled(boolean enabled)

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
boolean enabled

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

Returns
Transformer.Builder

This builder.

setFlattenForSlowMotion

@CanIgnoreReturnValue
public Transformer.Builder setFlattenForSlowMotion(boolean flattenForSlowMotion)

setListener

@CanIgnoreReturnValue
public Transformer.Builder setListener(Transformer.Listener listener)

setLooper

@CanIgnoreReturnValue
public Transformer.Builder setLooper(Looper looper)

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
public Transformer.Builder setMuxerFactory(Muxer.Factory muxerFactory)

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

The default value is a DefaultMuxer.Factory.

Parameters
Muxer.Factory muxerFactory

A Muxer.Factory.

Returns
Transformer.Builder

This builder.

setRemoveAudio

@CanIgnoreReturnValue
public Transformer.Builder setRemoveAudio(boolean removeAudio)

setRemoveVideo

@CanIgnoreReturnValue
public Transformer.Builder setRemoveVideo(boolean removeVideo)

setTransformationRequest

@CanIgnoreReturnValue
public Transformer.Builder setTransformationRequest(TransformationRequest transformationRequest)

setVideoEffects

@CanIgnoreReturnValue
public Transformer.Builder setVideoEffects(List<Effect> effects)

setVideoFrameProcessorFactory

@CanIgnoreReturnValue
public Transformer.Builder setVideoFrameProcessorFactory(
    VideoFrameProcessor.Factory videoFrameProcessorFactory
)

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
VideoFrameProcessor.Factory videoFrameProcessorFactory

A VideoFrameProcessor.Factory.

Returns
Transformer.Builder

This builder.

setVideoMimeType

@CanIgnoreReturnValue
public Transformer.Builder setVideoMimeType(String videoMimeType)

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
String videoMimeType

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.