@UnstableApi
class TransformerUtil


Utility methods for Transformer.

Summary

Nested types

Utility for setting LogSessionId on MediaFormat (API 35+).

Public functions

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

Returns whether Effects contains speed changing effects.

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

Returns the decoder output color taking tone mapping into account.

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

Returns the image MIME type corresponding to a MediaItem.

java-static Int

Returns MediaCodec flags corresponding to C.BufferFlags.

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

Calculate what the MIME type and HdrMode to use, applying fallback measure if necessary.

java-static Int

Returns the track type constant corresponding to how a specified MIME type should be processed, which may be TRACK_TYPE_UNKNOWN if it could not be determined.

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

Adjust for invalid ColorInfo values, by defaulting to SDR_BT709_LIMITED.

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

Returns whether the provided MediaItem corresponds to an image.

java-static Unit
maybeSetMuxerWrapperAdditionalRotationDegrees(
    muxerWrapper: MuxerWrapper!,
    videoEffects: ImmutableList<Effect!>!,
    inputFormat: Format!
)

Sets the additionalRotationDegrees on the given MuxerWrapper if the given videoEffects only contains a mix of regular rotations and no-ops.

java-static Boolean
shouldTranscodeAudio(
    inputFormat: Format!,
    composition: Composition!,
    sequenceIndex: Int,
    transformationRequest: TransformationRequest!,
    encoderFactory: Codec.EncoderFactory!,
    muxerWrapper: MuxerWrapper!
)

Returns whether the audio track should be transcoded.

java-static Boolean
shouldTranscodeVideo(
    inputFormat: Format!,
    composition: Composition!,
    sequenceIndex: Int,
    transformationRequest: TransformationRequest!,
    encoderFactory: Codec.EncoderFactory!,
    muxerWrapper: MuxerWrapper!
)

Returns whether the video track should be transcoded.

java-static Boolean
validateSpeedChangingEffects(
    effects: Effects!,
    speedProvider: 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 Effects contains speed changing effects.

ignoreFirstEffect controls whether TimestampAdjustment and 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.

getImageMimeType

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

Returns the image MIME type corresponding to a MediaItem.

This method only supports some common image MIME types.

Parameters
context: Context!

The Context.

mediaItem: MediaItem!

The MediaItem to inspect.

Returns
String?

The MIME type.

getMediaCodecFlags

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

Returns MediaCodec flags corresponding to C.BufferFlags.

getOutputMimeTypeAndHdrModeAfterFallback

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

Calculate what the MIME type and HdrMode to use, applying fallback measure if necessary.

Parameters
@Composition.HdrMode hdrMode: Int

The HdrMode.

requestedOutputMimeType: String!

The desired output MIME type.

colorInfo: ColorInfo?

The ColorInfo.

Returns
Pair<String!, Int!>!

a Pair of the output MIME type and HdrMode.

getProcessedTrackType

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

Returns the track type constant corresponding to how a specified MIME type should be processed, which may be TRACK_TYPE_UNKNOWN if it could not be determined.

Image MIME types are processed as TRACK_TYPE_VIDEO.

See getTrackType for more details.

getValidColor

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

Adjust for invalid ColorInfo values, by defaulting to SDR_BT709_LIMITED.

isImage

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

Returns whether the provided MediaItem corresponds to an image.

maybeSetMuxerWrapperAdditionalRotationDegrees

java-static fun maybeSetMuxerWrapperAdditionalRotationDegrees(
    muxerWrapper: MuxerWrapper!,
    videoEffects: ImmutableList<Effect!>!,
    inputFormat: Format!
): Unit

Sets the additionalRotationDegrees on the given MuxerWrapper if the given videoEffects only contains a mix of regular rotations and no-ops. A regular rotation is a rotation divisible by 90 degrees.

shouldTranscodeAudio

java-static fun shouldTranscodeAudio(
    inputFormat: Format!,
    composition: Composition!,
    sequenceIndex: Int,
    transformationRequest: TransformationRequest!,
    encoderFactory: Codec.EncoderFactory!,
    muxerWrapper: MuxerWrapper!
): Boolean

Returns whether the audio track should be transcoded.

shouldTranscodeVideo

java-static fun shouldTranscodeVideo(
    inputFormat: Format!,
    composition: Composition!,
    sequenceIndex: Int,
    transformationRequest: TransformationRequest!,
    encoderFactory: Codec.EncoderFactory!,
    muxerWrapper: MuxerWrapper!
): Boolean

Returns whether the video track should be transcoded.

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 TimestampAdjustment or SpeedChangingAudioProcessor instance set as the first effect of its pipeline has a SpeedProvider equal to speedProvider.

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