public final class

EditedMediaItem.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.media3.transformer.EditedMediaItem.Builder

Overview

A builder for EditedMediaItem instances.

Summary

Constructors
publicBuilder(MediaItem mediaItem)

Creates an instance.

Methods
public EditedMediaItembuild()

Builds an EditedMediaItem instance.

public EditedMediaItem.BuildersetDurationUs(long durationUs)

Sets the MediaItem duration in the output, in microseconds.

public EditedMediaItem.BuildersetEffects(Effects effects)

Sets the Effects to apply to the MediaItem.

public EditedMediaItem.BuildersetFlattenForSlowMotion(boolean flattenForSlowMotion)

Sets whether to flatten the MediaItem if it contains slow motion markers.

public EditedMediaItem.BuildersetFrameRate(int frameRate)

Sets the MediaItem frame rate in the output video, in frames per second.

public EditedMediaItem.BuildersetRemoveAudio(boolean removeAudio)

Sets whether to remove the audio from the MediaItem.

public EditedMediaItem.BuildersetRemoveVideo(boolean removeVideo)

Sets whether to remove the video from the MediaItem.

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

Constructors

public Builder(MediaItem mediaItem)

Creates an instance.

For image inputs, the values passed into EditedMediaItem.Builder.setRemoveAudio(boolean), EditedMediaItem.Builder.setRemoveVideo(boolean) and EditedMediaItem.Builder.setFlattenForSlowMotion(boolean) will be ignored. For multi-picture formats (e.g. gifs), a single image frame from the container is displayed if the DefaultAssetLoaderFactory is used.

Parameters:

mediaItem: The MediaItem on which transformations are applied.

Methods

public EditedMediaItem.Builder setRemoveAudio(boolean removeAudio)

Sets whether to remove the audio from the MediaItem.

The default value is false.

The audio and video cannot both be removed because the output would not contain any samples.

Parameters:

removeAudio: Whether to remove the audio.

Returns:

This builder.

public EditedMediaItem.Builder setRemoveVideo(boolean removeVideo)

Sets whether to remove the video from the MediaItem.

The default value is false.

The audio and video cannot both be removed because the output would not contain any samples.

Parameters:

removeVideo: Whether to remove the video.

Returns:

This builder.

public EditedMediaItem.Builder setFlattenForSlowMotion(boolean flattenForSlowMotion)

Sets whether to flatten the MediaItem if it contains slow motion markers.

The default value is false.

See EditedMediaItem.Builder.flattenForSlowMotion for more information about slow motion flattening.

If using an ExoPlayerAssetLoader.Factory with a provided , make sure that Mp4Extractor.FLAG_READ_SEF_DATA is set on the Mp4Extractor used. Otherwise, the slow motion metadata will be ignored and the input won't be flattened.

Slow motion flattening is only supported when the Composition contains exactly one MediaItem.

Using slow motion flattening together with is not supported yet.

Parameters:

flattenForSlowMotion: Whether to flatten for slow motion.

Returns:

This builder.

public EditedMediaItem.Builder setDurationUs(long durationUs)

Sets the MediaItem duration in the output, in microseconds.

For export, this should be set for inputs that don't have an intrinsic duration (e.g. images). It will be ignored for inputs that do have an intrinsic duration (e.g. video).

This should always be set for preview.

If clipping is applied, this should be the duration before clipping.

The default value is the MediaItem's .

Parameters:

durationUs: The duration, in microseconds.

Returns:

This builder.

public EditedMediaItem.Builder setFrameRate(int frameRate)

Sets the MediaItem frame rate in the output video, in frames per second.

This should be set for inputs that don't have an intrinsic frame rate (e.g., images). It will be ignored for inputs that do have an intrinsic frame rate (e.g., video).

For images, the frame rate depends on factors such as desired look, output format requirement, and whether the content is static or dynamic (e.g., animation). However, 30 fps is suitable for most use cases.

No frame rate is set by default.

Parameters:

frameRate: The frame rate, in frames per second.

Returns:

This builder.

public EditedMediaItem.Builder setEffects(Effects effects)

Sets the Effects to apply to the MediaItem.

Callers should not interact with underlying Effects.audioProcessors.

The default value is Effects.EMPTY.

Parameters:

effects: The Effects to apply.

Returns:

This builder.

public EditedMediaItem build()

Builds an EditedMediaItem instance.