# 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
public final class TransformerUtil
```

<br />

*** ** * ** ***

Utility methods for Transformer.

## Summary

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

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

## Public methods

### containsSpeedChangingEffects

```
public static boolean containsSpeedChangingEffects(
    Effects effects,
    boolean ignoreFirstEffect
)
```

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

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

### getDecoderOutputColor

```
public static ColorInfo getDecoderOutputColor(
    ColorInfo decoderInputColor,
    boolean isMediaCodecToneMappingRequested
)
```

Returns the decoder output color taking tone mapping into account.

### getEditedMediaItem

```
public static EditedMediaItem getEditedMediaItem(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)
```

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

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

### getEditedMediaItemIndex

```
public static int getEditedMediaItemIndex(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)
```

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

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

### getEditedMediaItemSequence

```
public static EditedMediaItemSequence getEditedMediaItemSequence(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)
```

Returns the `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Timeline timeline` | The `https://developer.android.com/reference/androidx/media3/common/Timeline` associated to the `https://developer.android.com/reference/androidx/media3/transformer/EditedMediaItemSequence`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId` associated to the `https://developer.android.com/reference/androidx/media3/transformer/EditedMediaItemSequence`. |

### getImageMimeType

```
public static @Nullable String getImageMimeType(Context context, MediaItem mediaItem)
```

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

This method only supports some common image MIME types.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | The MIME type. |

### getMediaCodecFlags

```
public static int getMediaCodecFlags(@C.BufferFlags int flags)
```

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

### getOffsetToCompositionTimeUs

```
public static long getOffsetToCompositionTimeUs(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId,
    long offsetUs
)
```

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Timeline timeline` | The `https://developer.android.com/reference/androidx/media3/common/Timeline` associated with this renderer. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId mediaPeriodId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/source/MediaSource.MediaPeriodId`. |
| `long offsetUs` | 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

```
public static Pair<String, Integer> getOutputMimeTypeAndHdrModeAfterFallback(
    @Composition.HdrMode int hdrMode,
    String requestedOutputMimeType,
    @Nullable ColorInfo colorInfo
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/transformer/Composition.HdrMode int hdrMode` | The `https://developer.android.com/reference/androidx/media3/transformer/Composition.HdrMode`. |
| `https://developer.android.com/reference/java/lang/String.html requestedOutputMimeType` | The desired output MIME type. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/ColorInfo colorInfo` | The `https://developer.android.com/reference/androidx/media3/common/ColorInfo`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/util/Pair.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/Integer.html>` | a `https://developer.android.com/reference/android/util/Pair.html` of the output MIME type and `https://developer.android.com/reference/androidx/media3/transformer/Composition.HdrMode`. |

### getProcessedTrackType

```
@C.TrackType
public static int getProcessedTrackType(@Nullable String mimeType)
```

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

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

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

### getValidColor

```
public static ColorInfo getValidColor(@Nullable ColorInfo colorInfo)
```

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

### isImage

```
public static boolean isImage(Context context, MediaItem mediaItem)
```

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

### validateSpeedChangingEffects

```
public static boolean validateSpeedChangingEffects(
    Effects effects,
    SpeedProvider speedProvider
)
```

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/androidx/media3/effect/TimestampAdjustment` or `https://developer.android.com/reference/androidx/media3/common/audio/SpeedChangingAudioProcessor` instance set as the first effect of its pipeline has a `https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider` equal to `speedProvider`.

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