Media3 Transformer is actively under development and we are looking to hear from you! We welcome your feedback, feature requests and bug reports in the issue tracker. Follow the ExoPlayer blog for the latest updates.

Transformations

Transcode between formats

You can specify the output audio and video formats you want to produce when building the transformation request. For example, the following code shows how to configure the transformation request to output H.264/AVC video and AAC audio:

Kotlin

TransformationRequest.Builder()
    .setVideoMimeType(MimeTypes.VIDEO_H264)
    .setAudioMimeType(AUDIO_AAC)
    .build()

Java

new TransformationRequest.Builder()
    .setVideoMimeType(MimeTypes.VIDEO_H264)
    .setAudioMimeType(AUDIO_AAC)
    .build();

If the input media format already matches the transformation request for audio or video, Transformer automatically switches to transmuxing, that is, copying the compressed samples from the input container to the output container without modification. This avoids the computational cost and potential quality loss of decoding and re-encoding in the same format.

Remove audio or video

Remove audio or video by configuring Transformer.Builder, for example:

Kotlin

val transformer = Transformer.Builder(context)
    .setRemoveAudio(true)
    .addListener(transformerListener)
    .build()

Java

Transformer transformer =
    new Transformer.Builder(context)
        .setRemoveAudio(true)
        .addListener(transformerListener)
        .build();

Trim a clip

You can remove any media outside specified start and end timestamps by setting the clipping configuration on the input media item. For example, to produce a clip containing only the media between 10 seconds and 20 seconds:

Kotlin

val inputMediaItem = MediaItem.Builder()
    .setUri(uri)
    .setClippingConfiguration(
        ClippingConfiguration.Builder()
            .setStartPositionMs(10_000)
            .setEndPositionMs(20_000)
            .build())
    .build()

Java

MediaItem inputMediaItem =
    new MediaItem.Builder()
        .setUri(uri)
        .setClippingConfiguration(
            new MediaItem.ClippingConfiguration.Builder()
                .setStartPositionMs(10_000)
                .setEndPositionMs(20_000)
                .build())
        .build();

Video edits

Transformer takes a list of video effects to apply in order. The library includes video effect implementations for common use cases, or you can write custom effects and pass them in when building transformer.

You can rescale media, which can be useful to save on processing resources or bandwidth when dealing with very high resolution input, such as 4k or 8k video. For example, to scale proportionally to 480 pixels high:

Kotlin

Transformer.Builder(context)
  .setVideoEffects(listOf(Presentation.createForHeight(480)))
  .build()

Java

new Transformer.Builder(context)
    .setVideoEffects(ImmutableList.of(
        Presentation.createForHeight(480)))
    .build();

Alternatively, you can scale by a given factor, for example, to halve the size:

Kotlin

Transformer.Builder(context)
  .setVideoEffects(listOf(ScaleToFitTransformation.Builder().setScale(.5f, .5f).build()))
  .build()

Java

new Transformer.Builder(context)
    .setVideoEffects(ImmutableList.of(
        new ScaleToFitTransformation.Builder().setScale(.5f, .5f).build()))
    .build();

You can configure rotation in the same way:

Kotlin

Transformer.Builder(context)
  .setVideoEffects(
    listOf(
      ScaleToFitTransformation.Builder()
        .setRotationDegrees(90f)
        .build()
    )
  )
  .build()

Java

new Transformer.Builder(context)
    .setVideoEffects(ImmutableList.of(
        new ScaleToFitTransformation.Builder()
            .setRotationDegrees(90f)
            .build()))
    .build();

Custom video effects

setVideoEffects accepts a list of video effects that are applied in sequence. This is implemented by running a GL shader program for each effect in turn. If multiple matrix transformation effects appear in sequence, they are collapsed together into one shader for efficiency and quality.

The demo app includes examples of custom video effects.