# Composition

Artifact: [androidx.media3:media3-transformer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/transformer/Composition.java+class:androidx.media3.transformer.Composition)

*** ** * ** ***


```
@UnstableApi
public final class Composition
```

<br />

*** ** * ** ***

A composition of `https://developer.android.com/reference/androidx/media3/common/MediaItem` instances, with transformations to apply to them.

The `https://developer.android.com/reference/androidx/media3/common/MediaItem` instances can be concatenated or mixed. `https://developer.android.com/reference/androidx/media3/transformer/Effects` can be applied to individual `https://developer.android.com/reference/androidx/media3/common/MediaItem` instances, as well as to the composition.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/transformer/Composition.Builder` A builder for `https://developer.android.com/reference/androidx/media3/transformer/Composition` instances. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/transformer/Composition.HdrMode` The strategy to use to transcode or edit High Dynamic Range (HDR) input video. |

| ### Constants |
|---|---|
| `static final int` | `@https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR() = 3` Interpret HDR input as SDR, likely with a washed out look. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_KEEP_HDR() = 0` Processes HDR input as HDR, to generate HDR output. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC() = 1` Tone map HDR input to SDR before processing, to generate SDR output, using the `https://developer.android.com/reference/android/media/MediaCodec.html` decoder tone-mapper. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL() = 2` Tone map HDR input to SDR before processing, to generate SDR output, using an OpenGL tone-mapper. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `@https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi https://developer.android.com/reference/androidx/media3/transformer/Composition#KEY_COMPOSITION() = "KEY_COMPOSITION"` Metadata key for storing a `Composition` in `https://developer.android.com/reference/androidx/media3/common/video/Frame#getMetadata()`. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `@https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi https://developer.android.com/reference/androidx/media3/transformer/Composition#KEY_COMPOSITION_ITEM_INDEX() = "KEY_COMPOSITION_ITEM_INDEX"` Metadata key for storing the media item index in the `sequences` (identified by `https://developer.android.com/reference/androidx/media3/effect/DefaultGlFrameProcessor#KEY_COMPOSITION_SEQUENCE_INDEX()`). |

| ### Public fields |
|---|---|
| `final https://developer.android.com/reference/androidx/media3/transformer/Effects` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#effects()` The `https://developer.android.com/reference/androidx/media3/transformer/Effects` to apply to the composition. |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#forceAudioTrack()` **This field is deprecated.** Use `https://developer.android.com/reference/androidx/media3/transformer/EditedMediaItemSequence.Builder#Builder(java.util.Set<java.lang.Integer>)` to set the track types of the sequence, and `trackTypes.contains(C.TRACK_TYPE_AUDIO)` to check for the presence of an audio track. <br /> |
| `final int` | `@https://developer.android.com/reference/androidx/media3/transformer/Composition.HdrMode https://developer.android.com/reference/androidx/media3/transformer/Composition#hdrMode()` The `https://developer.android.com/reference/androidx/media3/transformer/Composition.HdrMode` specifying how to handle HDR input video. |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#retainHdrFromUltraHdrImage()` Sets whether to use produce an HDR output video from Ultra HDR image input. |
| `final https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/androidx/media3/transformer/EditedMediaItemSequence>` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#sequences()` The `https://developer.android.com/reference/androidx/media3/transformer/EditedMediaItemSequence` instances to compose. |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#transmuxAudio()` Whether to transmux the `https://developer.android.com/reference/androidx/media3/common/MediaItem` audio tracks. |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#transmuxVideo()` Whether to transmux the `https://developer.android.com/reference/androidx/media3/common/MediaItem` video tracks. |
| `final https://developer.android.com/reference/androidx/media3/common/VideoCompositorSettings` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#videoCompositorSettings()` The `https://developer.android.com/reference/androidx/media3/common/VideoCompositorSettings` to apply to the composition. |
| `final https://developer.android.com/reference/androidx/media3/transformer/VideoFrameAggregationParameters` | `@https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi https://developer.android.com/reference/androidx/media3/transformer/Composition#videoFrameAggregationParameters()` The `https://developer.android.com/reference/androidx/media3/transformer/VideoFrameAggregationParameters` to apply to the composition. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/transformer/Composition#toString()()` |

## Constants

### HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR

```
@ExperimentalApi
public static final int HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR = 3
```

Interpret HDR input as SDR, likely with a washed out look.

This is much more widely supported than `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_KEEP_HDR()`, `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC()`, and `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL()`. However, as HDR transfer functions and metadata will be ignored, contents will be displayed incorrectly, likely with a washed out look.

Using this API may lead to codec errors before API 29.

Use of this flag may result in `ERROR_CODE_DECODING_FORMAT_UNSUPPORTED`.

This field is experimental, and will be renamed or removed in a future release.

### HDR_MODE_KEEP_HDR

```
public static final int HDR_MODE_KEEP_HDR = 0
```

Processes HDR input as HDR, to generate HDR output.

The HDR output format (ex. color transfer) will be the same as the HDR input format.

Supported on API 31+, by some device and HDR format combinations.

If not supported, `https://developer.android.com/reference/androidx/media3/transformer/Transformer` will attempt to use `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL()`.

### HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC

```
public static final int HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC = 1
```

Tone map HDR input to SDR before processing, to generate SDR output, using the `https://developer.android.com/reference/android/media/MediaCodec.html` decoder tone-mapper.

Supported on API 31+, by some device and HDR format combinations. Tone-mapping is only guaranteed to be supported on API 33+, on devices with HDR capture support.

If not supported, `https://developer.android.com/reference/androidx/media3/transformer/Transformer` throws an `https://developer.android.com/reference/androidx/media3/transformer/ExportException`.

### HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL

```
public static final int HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL = 2
```

Tone map HDR input to SDR before processing, to generate SDR output, using an OpenGL tone-mapper.

Supported on API 29+.

This may exhibit mild differences from `https://developer.android.com/reference/androidx/media3/transformer/Composition#HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC()`, depending on the device's tone-mapping implementation, but should have much wider support and have more consistent results across devices.

If not supported, `https://developer.android.com/reference/androidx/media3/transformer/Transformer` throws an `https://developer.android.com/reference/androidx/media3/transformer/ExportException`.

### KEY_COMPOSITION

```
@ExperimentalApi
public static final String KEY_COMPOSITION = "KEY_COMPOSITION"
```

Metadata key for storing a `Composition` in `https://developer.android.com/reference/androidx/media3/common/video/Frame#getMetadata()`.

### KEY_COMPOSITION_ITEM_INDEX

```
@ExperimentalApi
public static final String KEY_COMPOSITION_ITEM_INDEX = "KEY_COMPOSITION_ITEM_INDEX"
```

Metadata key for storing the media item index in the `sequences` (identified by `https://developer.android.com/reference/androidx/media3/effect/DefaultGlFrameProcessor#KEY_COMPOSITION_SEQUENCE_INDEX()`). This key should be stored in `https://developer.android.com/reference/androidx/media3/common/video/Frame#getMetadata()`.

## Public fields

### effects

```
public final Effects effects
```

The `https://developer.android.com/reference/androidx/media3/transformer/Effects` to apply to the composition.

### forceAudioTrack

```
public final boolean forceAudioTrack
```

> [!CAUTION]
> **This field is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/transformer/EditedMediaItemSequence.Builder#Builder(java.util.Set<java.lang.Integer>)` to set the track types of the sequence, and `trackTypes.contains(C.TRACK_TYPE_AUDIO)` to check for the presence of an audio track.

### hdrMode

```
@Composition.HdrMode
public final int hdrMode
```

The `https://developer.android.com/reference/androidx/media3/transformer/Composition.HdrMode` specifying how to handle HDR input video.

For more information, see `https://developer.android.com/reference/androidx/media3/transformer/Composition.Builder#setHdrMode(int)`.

### retainHdrFromUltraHdrImage

```
public final boolean retainHdrFromUltraHdrImage
```

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

For more information, see `https://developer.android.com/reference/androidx/media3/transformer/Composition.Builder#experimentalSetRetainHdrFromUltraHdrImage(boolean)`.

### sequences

```
public final ImmutableList<EditedMediaItemSequence> sequences
```

The `https://developer.android.com/reference/androidx/media3/transformer/EditedMediaItemSequence` instances to compose.

`https://developer.android.com/reference/androidx/media3/common/MediaItem` instances from different sequences that are overlapping in time will be mixed in the output.

### transmuxAudio

```
public final boolean transmuxAudio
```

Whether to transmux the `https://developer.android.com/reference/androidx/media3/common/MediaItem` audio tracks.

For more information, see `https://developer.android.com/reference/androidx/media3/transformer/Composition.Builder#setTransmuxAudio(boolean)`.

### transmuxVideo

```
public final boolean transmuxVideo
```

Whether to transmux the `https://developer.android.com/reference/androidx/media3/common/MediaItem` video tracks.

For more information, see `https://developer.android.com/reference/androidx/media3/transformer/Composition.Builder#setTransmuxVideo(boolean)`.

### videoCompositorSettings

```
public final VideoCompositorSettings videoCompositorSettings
```

The `https://developer.android.com/reference/androidx/media3/common/VideoCompositorSettings` to apply to the composition.

### videoFrameAggregationParameters

```
@ExperimentalApi
public final VideoFrameAggregationParameters videoFrameAggregationParameters
```

The `https://developer.android.com/reference/androidx/media3/transformer/VideoFrameAggregationParameters` to apply to the composition.

The default value is `https://developer.android.com/reference/androidx/media3/transformer/VideoFrameAggregationParameters#DEFAULT()`.

## Public methods

### toString

```
public String toString()
```