Composition.Builder


class Composition.Builder


A builder for Composition instances.

Summary

Public constructors

Creates an instance.

Builder(
    sequence: EditedMediaItemSequence!,
    sequences: Array<EditedMediaItemSequence!>!
)

Creates an instance.

Public functions

Composition!

Builds a Composition instance.

Composition.Builder!

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

Composition.Builder!

Sets the Effects to apply to the Composition.

Composition.Builder!

Sets the HdrMode for HDR video input.

Composition.Builder!

Sets whether to transmux the media items' audio tracks.

Composition.Builder!

Sets whether to transmux the media items' video tracks.

Composition.Builder!

Sets the VideoCompositorSettings to apply to the Composition.

Public constructors

Builder

Builder(sequences: (Mutable)List<EditedMediaItemSequence!>!)

Creates an instance.

Parameters
sequences: (Mutable)List<EditedMediaItemSequence!>!

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

Builder

Builder(
    sequence: EditedMediaItemSequence!,
    sequences: Array<EditedMediaItemSequence!>!
)

Creates an instance.

See also
Builder

Public functions

build

fun build(): Composition!

Builds a Composition instance.

experimentalSetForceAudioTrack

@CanIgnoreReturnValue
fun experimentalSetForceAudioTrack(forceAudioTrack: Boolean): Composition.Builder!

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 setAudioMimeType. 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: Boolean

Whether to force an audio track in the output.

Returns
Composition.Builder!

This builder.

setEffects

@CanIgnoreReturnValue
fun setEffects(effects: Effects!): Composition.Builder!

Sets the Effects to apply to the Composition.

The default value is EMPTY.

This only works with the Presentation effect.

Parameters
effects: Effects!

The CompositionEffects.

Returns
Composition.Builder!

This builder.

setHdrMode

@CanIgnoreReturnValue
fun setHdrMode(@Composition.HdrMode hdrMode: Int): Composition.Builder!

Sets the HdrMode for HDR video input.

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

Parameters
@Composition.HdrMode hdrMode: Int

The HdrMode used.

Returns
Composition.Builder!

This builder.

setTransmuxAudio

@CanIgnoreReturnValue
fun setTransmuxAudio(transmuxAudio: Boolean): Composition.Builder!

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

Whether to transmux the audio tracks.

Returns
Composition.Builder!

This builder.

setTransmuxVideo

@CanIgnoreReturnValue
fun setTransmuxVideo(transmuxVideo: Boolean): Composition.Builder!

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 and have the same sample format for that track). Any transcoding effects requested will be ignored.

Parameters
transmuxVideo: Boolean

Whether to transmux the video tracks.

Returns
Composition.Builder!

This builder.

setVideoCompositorSettings

@CanIgnoreReturnValue
fun setVideoCompositorSettings(
    videoCompositorSettings: VideoCompositorSettings!
): Composition.Builder!

Sets the VideoCompositorSettings to apply to the Composition.

The default value is DEFAULT.

Parameters
videoCompositorSettings: VideoCompositorSettings!

The VideoCompositorSettings.

Returns
Composition.Builder!

This builder.