public final class

Composition.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.media3.transformer.Composition.Builder

Overview

A builder for Composition instances.

Summary

Constructors
publicBuilder(EditedMediaItemSequence sequence, EditedMediaItemSequence sequences[])

Creates an instance.

publicBuilder(java.util.List<EditedMediaItemSequence> sequences)

Creates an instance.

Methods
public Compositionbuild()

Builds a Composition instance.

public Composition.BuilderexperimentalSetForceAudioTrack(boolean forceAudioTrack)

Sets whether the output file should always contain an audio track.

public Composition.BuilderexperimentalSetRetainHdrFromUltraHdrImage(boolean retainHdrFromUltraHdrImage)

Sets whether to use produce an HDR output video from Ultra HDR image input.

public Composition.BuildersetEffects(Effects effects)

Sets the Effects to apply to the Composition.

public Composition.BuildersetHdrMode(int hdrMode)

Sets the Composition.HdrMode for HDR video input.

public Composition.BuildersetTransmuxAudio(boolean transmuxAudio)

Sets whether to transmux the media items' audio tracks.

public Composition.BuildersetTransmuxVideo(boolean transmuxVideo)

Sets whether to transmux the media items' video tracks.

public Composition.BuildersetVideoCompositorSettings(VideoCompositorSettings videoCompositorSettings)

Sets the VideoCompositorSettings to apply to the Composition.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(EditedMediaItemSequence sequence, EditedMediaItemSequence sequences[])

Creates an instance.

See also: Composition.Builder.Builder(List)

public Builder(java.util.List<EditedMediaItemSequence> sequences)

Creates an instance.

Parameters:

sequences: The EditedMediaItemSequence instances to compose. The list must be non empty. See Composition.sequences for more details.

Methods

public Composition.Builder setVideoCompositorSettings(VideoCompositorSettings videoCompositorSettings)

Sets the VideoCompositorSettings to apply to the Composition.

The default value is VideoCompositorSettings.DEFAULT.

Parameters:

videoCompositorSettings: The VideoCompositorSettings.

Returns:

This builder.

public Composition.Builder setEffects(Effects effects)

Sets the Effects to apply to the Composition.

The default value is Effects.EMPTY.

This only works with the Presentation effect.

Parameters:

effects: The Composition Effects.

Returns:

This builder.

public Composition.Builder experimentalSetForceAudioTrack(boolean forceAudioTrack)

Sets whether the output file should always contain an audio track.

The default value is false.

  • If false:
    • If the Composition export doesn't produce any audio at timestamp 0, but produces audio later on, the export is aborted.
    • If the Composition doesn't produce any audio during the entire export, the output won't contain any audio.
    • If the Composition export produces audio at timestamp 0, the output will contain an audio track.
  • If true, the output will always contain an audio track.
If the output contains an audio track, silent audio will be generated for the segments where the Composition export doesn't produce any audio.

The MIME type of the output's audio track can be set using Transformer.Builder.setAudioMimeType(String). The sample rate and channel count can be set by passing relevant AudioProcessor instances to the Composition.

Forcing an audio track and requesting audio transmuxing are not allowed together because generating silence requires transcoding.

This method is experimental and may be removed or changed without warning.

Parameters:

forceAudioTrack: Whether to force an audio track in the output.

Returns:

This builder.

public Composition.Builder setTransmuxAudio(boolean transmuxAudio)

Sets whether to transmux the media items' audio tracks.

The default value is false.

If the Composition contains one MediaItem, the value set is ignored. The audio track will only be transcoded if necessary.

If the input Composition contains multiple media items, all the audio tracks are transcoded by default. They are all transmuxed if transmuxAudio is true. Transmuxed tracks must be compatible (typically, all the MediaItem instances containing the track to transmux are concatenated in a single EditedMediaItemSequence and have the same sample format for that track). Any transcoding effects requested will be ignored.

Requesting audio transmuxing and forcing an audio track are not allowed together because generating silence requires transcoding.

Parameters:

transmuxAudio: Whether to transmux the audio tracks.

Returns:

This builder.

public Composition.Builder setTransmuxVideo(boolean transmuxVideo)

Sets whether to transmux the media items' video tracks.

The default value is false.

If the Composition contains one MediaItem, the value set is ignored. The video track will only be transcoded if necessary.

If the input Composition contains multiple media items, all the video tracks are transcoded by default. They are all transmuxed if transmuxVideo is true. Transmuxed tracks must be compatible (typically, all the MediaItem instances containing the track to transmux are concatenated in a single EditedMediaItemSequence and have the same sample format for that track). Any transcoding effects requested will be ignored.

Parameters:

transmuxVideo: Whether to transmux the video tracks.

Returns:

This builder.

public Composition.Builder setHdrMode(int hdrMode)

Sets the Composition.HdrMode for HDR video input.

The default value is Composition.HDR_MODE_KEEP_HDR. Apps that need to tone-map HDR to SDR should generally prefer Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL over Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC, because its behavior is likely to be more consistent across devices.

Parameters:

hdrMode: The Composition.HdrMode used.

Returns:

This builder.

public Composition.Builder experimentalSetRetainHdrFromUltraHdrImage(boolean retainHdrFromUltraHdrImage)

Sets whether to use produce an HDR output video from Ultra HDR image input.

If the Composition.HdrMode is Composition.HDR_MODE_KEEP_HDR, then setting this to true applies the recovery map (i.e. the gainmap) to the base image to produce HDR video frames. This is automatically overridden to true, if the first asset is a HDR video.

The output video will have the same color encoding as the first EditedMediaItem the sequence. If the Ultra HDR image is first in the sequence, output video will default to BT2020 HLG full range colors.

Ignored if Composition.HdrMode is not Composition.HDR_MODE_KEEP_HDR.

Supported on API 34+, by some device and HDR format combinations. Ignored if unsupported by device or API level.

The default value is false.

Parameters:

retainHdrFromUltraHdrImage: Whether to use produce an HDR output video from Ultra HDR image input.

Returns:

This builder.

public Composition build()

Builds a Composition instance.