# TransformerUtil

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/TransformerUtil.java+class:androidx.media3.transformer.TransformerUtil)

*** ** * ** ***


```
@UnstableApi
class TransformerUtil
```

<br />

*** ** * ** ***

Utility methods for Transformer.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 35) class https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil.Api35` Utility for setting LogSessionId on MediaFormat (API 35+). |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#containsSpeedChangingEffects(androidx.media3.transformer.Effects,boolean)( effects: https://developer.android.com/reference/kotlin/androidx/media3/transformer/Effects!, ignoreFirstEffect: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Returns whether `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Effects` contains speed changing effects. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo!` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getDecoderOutputColor(androidx.media3.common.ColorInfo,boolean)( decoderInputColor: https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo!, isMediaCodecToneMappingRequested: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Returns the decoder output color taking tone mapping into account. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem!` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getEditedMediaItem(androidx.media3.common.Timeline,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)( timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId! )` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem` corresponding to `mediaPeriodId` within ` timeline`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getEditedMediaItemIndex(androidx.media3.common.Timeline,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)( timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId! )` Returns the index of the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem` corresponding to `mediaPeriodId` within `timeline`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItemSequence!` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getEditedMediaItemSequence(androidx.media3.common.Timeline,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)( timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId! )` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItemSequence` corresponding to `mediaPeriodId` within `timeline`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getImageMimeType(android.content.Context,androidx.media3.common.MediaItem)(context: https://developer.android.com/reference/android/content/Context.html!, mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem!)` Returns the image MIME type corresponding to a `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getMediaCodecFlags(int)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.BufferFlags flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns `https://developer.android.com/reference/android/media/MediaCodec.html` flags corresponding to `https://developer.android.com/reference/kotlin/androidx/media3/common/C.BufferFlags`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getOffsetToCompositionTimeUs(androidx.media3.common.Timeline,androidx.media3.exoplayer.source.MediaSource.MediaPeriodId,long)( timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!, mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!, offsetUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Returns the offset between a renderer timestamp and the start of the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition`. |
| `java-static https://developer.android.com/reference/android/util/Pair.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getOutputMimeTypeAndHdrModeAfterFallback(int,java.lang.String,androidx.media3.common.ColorInfo)( @https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition.HdrMode hdrMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, requestedOutputMimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, colorInfo: https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo? )` Calculate what the MIME type and `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition.HdrMode` to use, applying fallback measure if necessary. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.TrackType https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getProcessedTrackType(java.lang.String)(mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/C.TrackType` constant corresponding to how a specified MIME type should be processed, which may be `https://developer.android.com/reference/kotlin/androidx/media3/common/C#TRACK_TYPE_UNKNOWN()` if it could not be determined. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo!` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#getValidColor(androidx.media3.common.ColorInfo)(colorInfo: https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo?)` Adjust for invalid `https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo` values, by defaulting to `https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo#SDR_BT709_LIMITED()`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#isImage(android.content.Context,androidx.media3.common.MediaItem)(context: https://developer.android.com/reference/android/content/Context.html!, mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem!)` Returns whether the provided `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` corresponds to an image. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/transformer/TransformerUtil#validateSpeedChangingEffects(androidx.media3.transformer.Effects,androidx.media3.common.audio.SpeedProvider)( effects: https://developer.android.com/reference/kotlin/androidx/media3/transformer/Effects!, speedProvider: https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedProvider! )` Checks whether any speed changing effects at the first position of each pipeline match ` speedProvider`. |

## Public functions

### containsSpeedChangingEffects

```
java-static fun containsSpeedChangingEffects(
    effects: Effects!,
    ignoreFirstEffect: Boolean
): Boolean
```

Returns whether `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Effects` contains speed changing effects.

`ignoreFirstEffect` controls whether `https://developer.android.com/reference/kotlin/androidx/media3/effect/TimestampAdjustment` and `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedChangingAudioProcessor` are ignored as first elements of the video and audio pipelines, respectively.

### getDecoderOutputColor

```
java-static fun getDecoderOutputColor(
    decoderInputColor: ColorInfo!,
    isMediaCodecToneMappingRequested: Boolean
): ColorInfo!
```

Returns the decoder output color taking tone mapping into account.

### getEditedMediaItem

```
java-static fun getEditedMediaItem(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!
): EditedMediaItem!
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem` corresponding to `mediaPeriodId` within `
timeline`.

| Parameters |
|---|---|
| `timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` associated to the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem`. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated to the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem`. |

### getEditedMediaItemIndex

```
java-static fun getEditedMediaItemIndex(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!
): Int
```

Returns the index of the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem` corresponding to `mediaPeriodId` within `timeline`.

| Parameters |
|---|---|
| `timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` associated to the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem`. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated to the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItem`. |

### getEditedMediaItemSequence

```
java-static fun getEditedMediaItemSequence(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!
): EditedMediaItemSequence!
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItemSequence` corresponding to `mediaPeriodId` within `timeline`.

If `mediaPeriodId` does not map to a sequence this method will throw a `https://developer.android.com/reference/java/lang/IllegalStateException.html`.

| Parameters |
|---|---|
| `timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` associated to the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItemSequence`. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated to the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/EditedMediaItemSequence`. |

### getImageMimeType

```
java-static fun getImageMimeType(context: Context!, mediaItem: MediaItem!): String?
```

Returns the image MIME type corresponding to a `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem`.

This method only supports some common image MIME types.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | The `https://developer.android.com/reference/android/content/Context.html`. |
| `mediaItem: https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` to inspect. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The MIME type. |

### getMediaCodecFlags

```
java-static fun getMediaCodecFlags(@C.BufferFlags flags: Int): Int
```

Returns `https://developer.android.com/reference/android/media/MediaCodec.html` flags corresponding to `https://developer.android.com/reference/kotlin/androidx/media3/common/C.BufferFlags`.

### getOffsetToCompositionTimeUs

```
java-static fun getOffsetToCompositionTimeUs(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    offsetUs: Long
): Long
```

Returns the offset between a renderer timestamp and the start of the `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition`.

| Parameters |
|---|---|
| `timeline: https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/Timeline` associated with this renderer. |
| `mediaPeriodId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`. |
| `offsetUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The offset added to timestamps of buffers to ensure monotonically increasing timestamps, in microseconds. This is the constant offset between the current MediaPeriod timestamps and the renderer timestamp. See [this corresponding topic on timestamps](https://developer.android.com/reference/androidx/media3/exoplayer/Renderer#timestamps-and-offsets). |

### getOutputMimeTypeAndHdrModeAfterFallback

```
java-static fun getOutputMimeTypeAndHdrModeAfterFallback(
    @Composition.HdrMode hdrMode: Int,
    requestedOutputMimeType: String!,
    colorInfo: ColorInfo?
): Pair<String!, Int!>!
```

Calculate what the MIME type and `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition.HdrMode` to use, applying fallback measure if necessary.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition.HdrMode hdrMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition.HdrMode`. |
| `requestedOutputMimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The desired output MIME type. |
| `colorInfo: https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo?` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/util/Pair.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>!` | a `https://developer.android.com/reference/android/util/Pair.html` of the output MIME type and `https://developer.android.com/reference/kotlin/androidx/media3/transformer/Composition.HdrMode`. |

### getProcessedTrackType

```
@C.TrackType
java-static fun getProcessedTrackType(mimeType: String?): Int
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/C.TrackType` constant corresponding to how a specified MIME type should be processed, which may be `https://developer.android.com/reference/kotlin/androidx/media3/common/C#TRACK_TYPE_UNKNOWN()` if it could not be determined.

`https://developer.android.com/reference/kotlin/androidx/media3/common/MimeTypes#isImage(java.lang.String)` MIME types are processed as `https://developer.android.com/reference/kotlin/androidx/media3/common/C#TRACK_TYPE_VIDEO()`.

See `https://developer.android.com/reference/kotlin/androidx/media3/common/MimeTypes#getTrackType(java.lang.String)` for more details.

### getValidColor

```
java-static fun getValidColor(colorInfo: ColorInfo?): ColorInfo!
```

Adjust for invalid `https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo` values, by defaulting to `https://developer.android.com/reference/kotlin/androidx/media3/common/ColorInfo#SDR_BT709_LIMITED()`.

### isImage

```
java-static fun isImage(context: Context!, mediaItem: MediaItem!): Boolean
```

Returns whether the provided `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaItem` corresponds to an image.

### validateSpeedChangingEffects

```
java-static fun validateSpeedChangingEffects(
    effects: Effects!,
    speedProvider: SpeedProvider!
): Boolean
```

Checks whether any speed changing effects at the first position of each pipeline match `
speedProvider`.

The method verifies that any `https://developer.android.com/reference/kotlin/androidx/media3/effect/TimestampAdjustment` or `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedChangingAudioProcessor` instance set as the first effect of its pipeline has a `https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedProvider` equal to `speedProvider`.

If no speed changing effects are present, this method returns `true`.