EditedMediaItem.Builder
public final class EditedMediaItem.Builder
A builder for EditedMediaItem instances.
Summary
Public constructors
Builder
public Builder(MediaItem mediaItem)
Creates an instance.
For image inputs:
- The
image durationshould always be set. - The values passed into
setRemoveAudio,setRemoveVideoandsetFlattenForSlowMotionwill be ignored. - For multi-picture formats (e.g. gifs), a single image frame from the container is displayed if the
DefaultAssetLoaderFactoryis used.
Public methods
setDurationUs
@CanIgnoreReturnValue
public EditedMediaItem.Builder setDurationUs(@IntRange(from = 1) long durationUs)
Sets the duration in microseconds of the source media represented by the MediaItem.
The provided duration should match the duration of the source media before applying any clipping or speed-changing effects.
Setting the duration is optional in the following cases:
- The
MediaItemrepresents an image. The default image duration set viasetImageDurationMs. - On
Transformer, when theMediaItemhas an intrinsic duration (e.g. encoded video/audio data from an input file).
| Parameters | |
|---|---|
@IntRange(from = 1) long durationUs |
The duration, in microseconds. |
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |
setEffects
@CanIgnoreReturnValue
public EditedMediaItem.Builder setEffects(Effects effects)
Sets the Effects to apply to the MediaItem.
Callers should not interact with underlying audioProcessors.
The default value is EMPTY.
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |
setFlattenForSlowMotion
@CanIgnoreReturnValue
public EditedMediaItem.Builder setFlattenForSlowMotion(boolean flattenForSlowMotion)
Sets whether to flatten the MediaItem if it contains slow motion markers.
The default value is false.
See flattenForSlowMotion for more information about slow motion flattening.
If using an ExoPlayerAssetLoader.Factory with a provided MediaSource.Factory, make sure that 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 MediaItem.ClippingConfiguration is not supported yet.
| Parameters | |
|---|---|
boolean flattenForSlowMotion |
Whether to flatten for slow motion. |
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |
setFrameRate
@CanIgnoreReturnValue
public EditedMediaItem.Builder setFrameRate(@IntRange(from = 0) int frameRate)
Sets the MediaItem frame rate in the output video, in frames per second.
- For inputs that don't have an intrinsic frame rate (e.g., images), this value determines the frame rate of the output 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.
- For inputs that do have an intrinsic frame rate (e.g., video), this value acts as a maximum frame rate. If the intrinsic frame rate is higher than the value set here, frames will be dropped to achieve the specified maximum frame rate in the output. If the intrinsic frame rate is lower, this parameter has no effect. Setting the max frame rate is particularly important when increasing media speed using the
setSpeedAPI. Increasing media speed adjusts video sample timestamps to the new rate, resulting in a higher effective output frame rate. By setting a maximum frame rate, you can prevent the output from having an excessively high frame rate.
No frame rate is set by default.
| Parameters | |
|---|---|
@IntRange(from = 0) int frameRate |
The frame rate, in frames per second. |
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |
setRemoveAudio
@CanIgnoreReturnValue
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 | |
|---|---|
boolean removeAudio |
Whether to remove the audio. |
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |
setRemoveVideo
@CanIgnoreReturnValue
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 | |
|---|---|
boolean removeVideo |
Whether to remove the video. |
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |
setSpeed
@ExperimentalApi
@CanIgnoreReturnValue
public EditedMediaItem.Builder setSpeed(SpeedParameters parameters)
Sets a SpeedParameters instance to control the presentation speed of the EditedMediaItem.
If a SpeedParameters instance is set, speed changing effects are not allowed.
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |
setSpeed
@CanIgnoreReturnValue
public EditedMediaItem.Builder setSpeed(SpeedProvider provider)
Sets a SpeedProvider to control the presentation speed of the EditedMediaItem.
If a SpeedProvider is set, speed changing effects are not allowed.
This method is identical to setSpeed(new SpeedParameters(provider, false)).
The default value is DEFAULT, which represents an unmodified speed.
| Returns | |
|---|---|
EditedMediaItem.Builder |
This builder. |