Package com.google.android.exoplayer2.transformer

## Class Transformer.Builder

- java.lang.Object
- - com.google.android.exoplayer2.transformer.Transformer.Builder

- Enclosing class:
    Transformer

      public static final class Transformer.Builder
      extends Object

  A builder for `Transformer` instances.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Builder()` | Creates a builder with default values.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Transformer` | `build()` | Builds a `Transformer` instance.
    `Transformer.Builder` | `setContext​(Context context)` | Sets the `Context`.
    `Transformer.Builder` | `setFlattenForSlowMotion​(boolean flattenForSlowMotion)` | Sets whether the input should be flattened for media containing slow motion markers.
    `Transformer.Builder` | `setListener​(Transformer.Listener listener)` | Sets the `Transformer.Listener` to listen to the transformation events.
    `Transformer.Builder` | `setLooper​(Looper looper)` | Sets the `Looper` that must be used for all calls to the transformer and that is used to call listeners on.
    `Transformer.Builder` | `setMediaSourceFactory​(MediaSourceFactory mediaSourceFactory)` | Sets the `MediaSourceFactory` to be used to retrieve the inputs to transform.
    `Transformer.Builder` | `setOutputMimeType​(String outputMimeType)` | Sets the MIME type of the output.
    `Transformer.Builder` | `setRemoveAudio​(boolean removeAudio)` | Sets whether to remove the audio from the output.
    `Transformer.Builder` | `setRemoveVideo​(boolean removeVideo)` | Sets whether to remove the video from the output.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Builder

          public Builder()

      Creates a builder with default values.

  - ### Method Detail

    - #### setContext

          public Transformer.Builder setContext​(Context context)

      Sets the `Context`.

      This parameter is mandatory.

      Parameters:
        `context` - The `Context`.
      Returns:
        This builder.

    - #### setMediaSourceFactory

          public Transformer.Builder setMediaSourceFactory​(MediaSourceFactory mediaSourceFactory)

      Sets the `MediaSourceFactory` to be used to retrieve the inputs to transform. The default value is a `DefaultMediaSourceFactory` built with the context provided in `setContext(Context)`.
      Parameters:
        `mediaSourceFactory` - A `MediaSourceFactory`.
      Returns:
        This builder.

    - #### setRemoveAudio

          public Transformer.Builder setRemoveAudio​(boolean removeAudio)

      Sets whether to remove the audio from the output. The default value is `false`.

      The audio and video cannot both be removed because the output would not contain any samples.

      Parameters:
        `removeAudio` - Whether to remove the audio.
      Returns:
        This builder.

    - #### setRemoveVideo

          public Transformer.Builder setRemoveVideo​(boolean removeVideo)

      Sets whether to remove the video from the output. The default value is `false`.

      The audio and video cannot both be removed because the output would not contain any samples.

      Parameters:
        `removeVideo` - Whether to remove the video.
      Returns:
        This builder.

    - #### setFlattenForSlowMotion

          public Transformer.Builder setFlattenForSlowMotion​(boolean flattenForSlowMotion)

      Sets whether the input should be flattened for media containing slow motion markers. The transformed output is obtained by removing the slow motion metadata and by actually slowing down the parts of the video and audio streams defined in this metadata. The default value for `flattenForSlowMotion` is `false`.

      Only Samsung Extension Format (SEF) slow motion metadata type is supported. The transformation has no effect if the input does not contain this metadata type.

      For SEF slow motion media, the following assumptions are made on the input:

      - The input container format is (unfragmented) MP4.
      - The input contains an AVC video elementary stream with temporal SVC.
      - The recording frame rate of the video is 120 or 240 fps.

      If specifying a `MediaSourceFactory` using `setMediaSourceFactory(MediaSourceFactory)`, make sure that `Mp4Extractor.FLAG_READ_SEF_DATA` is set on the `Mp4Extractor` used. Otherwise, the slow motion metadata will be ignored and the input won't be flattened.

      Parameters:
        `flattenForSlowMotion` - Whether to flatten for slow motion.
      Returns:
        This builder.

    - #### setOutputMimeType

          public Transformer.Builder setOutputMimeType​(String outputMimeType)

      Sets the MIME type of the output. The default value is `MimeTypes.VIDEO_MP4`. Supported values are:
      - `MimeTypes.VIDEO_MP4`
      - `MimeTypes.VIDEO_WEBM` from API level 21
      Parameters:
        `outputMimeType` - The MIME type of the output.
      Returns:
        This builder.

    - #### setListener

          public Transformer.Builder setListener​(Transformer.Listener listener)

      Sets the `Transformer.Listener` to listen to the transformation events.

      This is equivalent to `Transformer.setListener(Listener)`.

      Parameters:
        `listener` - A `Transformer.Listener`.
      Returns:
        This builder.

    - #### setLooper

          public Transformer.Builder setLooper​(Looper looper)

      Sets the `Looper` that must be used for all calls to the transformer and that is used to call listeners on. The default value is the Looper of the thread that this builder was created on, or if that thread does not have a Looper, the Looper of the application's main thread.
      Parameters:
        `looper` - A `Looper`.
      Returns:
        This builder.

    - #### build

          public Transformer build()

      Builds a `Transformer` instance.
      Throws:
        `IllegalStateException` - If the `Context` has not been provided.
        `IllegalStateException` - If both audio and video have been removed (otherwise the output would not contain any samples).
        `IllegalStateException` - If the muxer doesn't support the requested output MIME type.