Package com.google.android.exoplayer2

## Class Format

- java.lang.Object
- - com.google.android.exoplayer2.Format

- All Implemented Interfaces:
    `Parcelable`

      public final class Format
      extends Object
      implements Parcelable

  Represents a media format.

  When building formats, populate all fields whose values are known and relevant to the type of format being constructed. For information about different types of format, see ExoPlayer's Supported formats page.

  ## Fields commonly relevant to all formats

  - `id`
  - `label`
  - `language`
  - `selectionFlags`
  - `roleFlags`
  - `averageBitrate`
  - `peakBitrate`
  - `codecs`
  - `metadata`

  ## Fields relevant to container formats

  - `containerMimeType`
  - If the container only contains a single media track, fields relevant to sample formats can are also be relevant and can be set to describe the sample format of that track.
  - If the container only contains one track of a given type (possibly alongside tracks of other types), then fields relevant to that track type can be set to describe the properties of the track. See the sections below for video, audio and text formats.

  ## Fields relevant to sample formats

  - `sampleMimeType`
  - `maxInputSize`
  - `initializationData`
  - `drmInitData`
  - `subsampleOffsetUs`
  - Fields relevant to the sample format's track type are also relevant. See the sections below for video, audio and text formats.

  ## Fields relevant to video formats

  - `width`
  - `height`
  - `frameRate`
  - `rotationDegrees`
  - `pixelWidthHeightRatio`
  - `projectionData`
  - `stereoMode`
  - `colorInfo`

  ## Fields relevant to audio formats

  - `channelCount`
  - `sampleRate`
  - `pcmEncoding`
  - `encoderDelay`
  - `encoderPadding`

  ## Fields relevant to text formats

  - `accessibilityChannel`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `Format.Builder` | Builds `Format` instances.

    - ### Nested classes/interfaces inherited from interface android.os.Parcelable

      `Parcelable.ClassLoaderCreator<T extends Object>, Parcelable.Creator<T extends Object>`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `int` | `accessibilityChannel` | The Accessibility channel, or `NO_VALUE` if not known or applicable.
    `int` | `averageBitrate` | The average bitrate in bits per second, or `NO_VALUE` if unknown or not applicable.
    `int` | `bitrate` | The bitrate in bits per second.
    `int` | `channelCount` | The number of audio channels, or `NO_VALUE` if unknown or not applicable.
    `String` | `codecs` | Codecs of the format as described in RFC 6381, or null if unknown or not applicable.
    `ColorInfo` | `colorInfo` | The color metadata associated with the video, or null if not applicable.
    `String` | `containerMimeType` | The mime type of the container, or null if unknown or not applicable.
    `static Parcelable.Creator<Format>` | `CREATOR` |
    `DrmInitData` | `drmInitData` | DRM initialization data if the stream is protected, or null otherwise.
    `int` | `encoderDelay` | The number of frames to trim from the start of the decoded audio stream, or 0 if not applicable.
    `int` | `encoderPadding` | The number of frames to trim from the end of the decoded audio stream, or 0 if not applicable.
    `Class<? extends ExoMediaCrypto>` | `exoMediaCryptoType` | The type of `ExoMediaCrypto` that will be associated with the content this format describes, or `null` if the content is not encrypted.
    `float` | `frameRate` | The frame rate in frames per second, or `NO_VALUE` if unknown or not applicable.
    `int` | `height` | The height of the video in pixels, or `NO_VALUE` if unknown or not applicable.
    `String` | `id` | An identifier for the format, or null if unknown or not applicable.
    `List<byte[]>` | `initializationData` | Initialization data that must be provided to the decoder.
    `String` | `label` | The human readable label, or null if unknown or not applicable.
    `String` | `language` | The language as an IETF BCP 47 conformant tag, or null if unknown or not applicable.
    `int` | `maxInputSize` | The maximum size of a buffer of data (typically one sample), or `NO_VALUE` if unknown or not applicable.
    `Metadata` | `metadata` | Metadata, or null if unknown or not applicable.
    `static int` | `NO_VALUE` | A value for various fields to indicate that the field's value is unknown or not applicable.
    `static long` | `OFFSET_SAMPLE_RELATIVE` | A value for `subsampleOffsetUs` to indicate that subsample timestamps are relative to the timestamps of their parent samples.
    `int` | `pcmEncoding` | The `C.PcmEncoding` for PCM audio.
    `int` | `peakBitrate` | The peak bitrate in bits per second, or `NO_VALUE` if unknown or not applicable.
    `float` | `pixelWidthHeightRatio` | The width to height ratio of pixels in the video, or 1.0 if unknown or not applicable.
    `byte[]` | `projectionData` | The projection data for 360/VR video, or null if not applicable.
    `int` | `roleFlags` | Track role flags.
    `int` | `rotationDegrees` | The clockwise rotation that should be applied to the video for it to be rendered in the correct orientation, or 0 if unknown or not applicable.
    `String` | `sampleMimeType` | The sample mime type, or null if unknown or not applicable.
    `int` | `sampleRate` | The audio sampling rate in Hz, or `NO_VALUE` if unknown or not applicable.
    `int` | `selectionFlags` | Track selection flags.
    `int` | `stereoMode` | The stereo layout for 360/3D/VR video, or `NO_VALUE` if not applicable.
    `long` | `subsampleOffsetUs` | For samples that contain subsamples, this is an offset that should be added to subsample timestamps.
    `int` | `width` | The width of the video in pixels, or `NO_VALUE` if unknown or not applicable.

    - ### Fields inherited from interface android.os.Parcelable

      `CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Format.Builder` | `buildUpon()` | Returns a `Format.Builder` initialized with the values of this instance.
    `Format` | `copyWithBitrate​(int bitrate)` | Deprecated. Use `buildUpon()` and `Format.Builder.setAverageBitrate(int)` and `Format.Builder.setPeakBitrate(int)`.
    `Format` | `copyWithDrmInitData​(DrmInitData drmInitData)` | Deprecated. Use `buildUpon()` and `Format.Builder.setDrmInitData(DrmInitData)`.
    `Format` | `copyWithExoMediaCryptoType​(Class<? extends ExoMediaCrypto> exoMediaCryptoType)` | Returns a copy of this format with the specified `exoMediaCryptoType`.
    `Format` | `copyWithFrameRate​(float frameRate)` | Deprecated. Use `buildUpon()` and `Format.Builder.setFrameRate(float)`.
    `Format` | `copyWithGaplessInfo​(int encoderDelay, int encoderPadding)` | Deprecated. Use `buildUpon()`, `Format.Builder.setEncoderDelay(int)` and `Format.Builder.setEncoderPadding(int)`.
    `Format` | `copyWithLabel​(String label)` | Deprecated. Use `buildUpon()` and `Format.Builder.setLabel(String)` .
    `Format` | `copyWithManifestFormatInfo​(Format manifestFormat)` | Deprecated. Use `withManifestFormatInfo(Format)`.
    `Format` | `copyWithMaxInputSize​(int maxInputSize)` | Deprecated. Use `buildUpon()` and `Format.Builder.setMaxInputSize(int)`.
    `Format` | `copyWithMetadata​(Metadata metadata)` | Deprecated. Use `buildUpon()` and `Format.Builder.setMetadata(Metadata)`.
    `Format` | `copyWithSubsampleOffsetUs​(long subsampleOffsetUs)` | Deprecated. Use `buildUpon()` and `Format.Builder.setSubsampleOffsetUs(long)`.
    `Format` | `copyWithVideoSize​(int width, int height)` | Deprecated. Use `buildUpon()`, `Format.Builder.setWidth(int)` and `Format.Builder.setHeight(int)`.
    `static Format` | `createAudioSampleFormat​(String id, String sampleMimeType, String codecs, int bitrate, int maxInputSize, int channelCount, int sampleRate, int pcmEncoding, List<byte[]> initializationData, DrmInitData drmInitData, int selectionFlags, String language)` | Deprecated. Use `Format.Builder`.
    `static Format` | `createAudioSampleFormat​(String id, String sampleMimeType, String codecs, int bitrate, int maxInputSize, int channelCount, int sampleRate, List<byte[]> initializationData, DrmInitData drmInitData, int selectionFlags, String language)` | Deprecated. Use `Format.Builder`.
    `static Format` | `createContainerFormat​(String id, String label, String containerMimeType, String sampleMimeType, String codecs, int bitrate, int selectionFlags, int roleFlags, String language)` | Deprecated. Use `Format.Builder`.
    `static Format` | `createSampleFormat​(String id, String sampleMimeType)` | Deprecated. Use `Format.Builder`.
    `static Format` | `createVideoSampleFormat​(String id, String sampleMimeType, String codecs, int bitrate, int maxInputSize, int width, int height, float frameRate, List<byte[]> initializationData, int rotationDegrees, float pixelWidthHeightRatio, DrmInitData drmInitData)` | Deprecated. Use `Format.Builder`.
    `static Format` | `createVideoSampleFormat​(String id, String sampleMimeType, String codecs, int bitrate, int maxInputSize, int width, int height, float frameRate, List<byte[]> initializationData, DrmInitData drmInitData)` | Deprecated. Use `Format.Builder`.
    `int` | `describeContents()` |
    `boolean` | `equals​(Object obj)` |
    `int` | `getPixelCount()` | Returns the number of pixels if this is a video format whose `width` and `height` are known, or `NO_VALUE` otherwise
    `int` | `hashCode()` |
    `boolean` | `initializationDataEquals​(Format other)` | Returns whether the `initializationData`s belonging to this format and `other` are equal.
    `static String` | `toLogString​(Format format)` | Returns a prettier `String` than `toString()`, intended for logging.
    `String` | `toString()` |
    `Format` | `withManifestFormatInfo​(Format manifestFormat)` |
    `void` | `writeToParcel​(Parcel dest, int flags)` |

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### NO_VALUE

          public static final int NO_VALUE

      A value for various fields to indicate that the field's value is unknown or not applicable.
      See Also:
        Constant Field Values

    - #### OFFSET_SAMPLE_RELATIVE

          public static final long OFFSET_SAMPLE_RELATIVE

      A value for `subsampleOffsetUs` to indicate that subsample timestamps are relative to the timestamps of their parent samples.
      See Also:
        Constant Field Values

    - #### id

          @Nullable
          public final String id

      An identifier for the format, or null if unknown or not applicable.

    - #### label

          @Nullable
          public final String label

      The human readable label, or null if unknown or not applicable.

    - #### language

          @Nullable
          public final String language

      The language as an IETF BCP 47 conformant tag, or null if unknown or not applicable.

    - #### selectionFlags

          @SelectionFlags
          public final int selectionFlags

      Track selection flags.

    - #### roleFlags

          @RoleFlags
          public final int roleFlags

      Track role flags.

    - #### averageBitrate

          public final int averageBitrate

      The average bitrate in bits per second, or `NO_VALUE` if unknown or not applicable. The way in which this field is populated depends on the type of media to which the format corresponds:
      - DASH representations: Always `NO_VALUE`.
      - HLS variants: The `AVERAGE-BANDWIDTH` attribute defined on the corresponding `EXT-X-STREAM-INF` tag in the master playlist, or `NO_VALUE` if not present.
      - SmoothStreaming track elements: The `Bitrate` attribute defined on the corresponding `TrackElement` in the manifest, or `NO_VALUE` if not present.
      - Progressive container formats: Often `NO_VALUE`, but may be populated with the average bitrate of the container if known.
      - Sample formats: Often `NO_VALUE`, but may be populated with the average bitrate of the stream of samples with type `sampleMimeType` if known. Note that if `sampleMimeType` is a compressed format (e.g., `MimeTypes.AUDIO_AAC`), then this bitrate is for the stream of still compressed samples.

    - #### peakBitrate

          public final int peakBitrate

      The peak bitrate in bits per second, or `NO_VALUE` if unknown or not applicable. The way in which this field is populated depends on the type of media to which the format corresponds:
      - DASH representations: The `@bandwidth` attribute of the corresponding `Representation` element in the manifest.
      - HLS variants: The `BANDWIDTH` attribute defined on the corresponding `EXT-X-STREAM-INF` tag.
      - SmoothStreaming track elements: Always `NO_VALUE`.
      - Progressive container formats: Often `NO_VALUE`, but may be populated with the peak bitrate of the container if known.
      - Sample formats: Often `NO_VALUE`, but may be populated with the peak bitrate of the stream of samples with type `sampleMimeType` if known. Note that if `sampleMimeType` is a compressed format (e.g., `MimeTypes.AUDIO_AAC`), then this bitrate is for the stream of still compressed samples.

    - #### bitrate

          public final int bitrate

      The bitrate in bits per second. This is the peak bitrate if known, or else the average bitrate if known, or else `NO_VALUE`. Equivalent to: `peakBitrate != NO_VALUE ? peakBitrate : averageBitrate`.

    - #### codecs

          @Nullable
          public final String codecs

      Codecs of the format as described in RFC 6381, or null if unknown or not applicable.

    - #### metadata

          @Nullable
          public final Metadata metadata

      Metadata, or null if unknown or not applicable.

    - #### containerMimeType

          @Nullable
          public final String containerMimeType

      The mime type of the container, or null if unknown or not applicable.

    - #### sampleMimeType

          @Nullable
          public final String sampleMimeType

      The sample mime type, or null if unknown or not applicable.

    - #### maxInputSize

          public final int maxInputSize

      The maximum size of a buffer of data (typically one sample), or `NO_VALUE` if unknown or not applicable.

    - #### initializationData

          public final List<byte[]> initializationData

      Initialization data that must be provided to the decoder. Will not be null, but may be empty if initialization data is not required.

    - #### drmInitData

          @Nullable
          public final DrmInitData drmInitData

      DRM initialization data if the stream is protected, or null otherwise.

    - #### subsampleOffsetUs

          public final long subsampleOffsetUs

      For samples that contain subsamples, this is an offset that should be added to subsample timestamps. A value of `OFFSET_SAMPLE_RELATIVE` indicates that subsample timestamps are relative to the timestamps of their parent samples.

    - #### width

          public final int width

      The width of the video in pixels, or `NO_VALUE` if unknown or not applicable.

    - #### height

          public final int height

      The height of the video in pixels, or `NO_VALUE` if unknown or not applicable.

    - #### frameRate

          public final float frameRate

      The frame rate in frames per second, or `NO_VALUE` if unknown or not applicable.

    - #### rotationDegrees

          public final int rotationDegrees

      The clockwise rotation that should be applied to the video for it to be rendered in the correct orientation, or 0 if unknown or not applicable. Only 0, 90, 180 and 270 are supported.

    - #### pixelWidthHeightRatio

          public final float pixelWidthHeightRatio

      The width to height ratio of pixels in the video, or 1.0 if unknown or not applicable.

    - #### projectionData

          @Nullable
          public final byte[] projectionData

      The projection data for 360/VR video, or null if not applicable.

    - #### stereoMode

          @StereoMode
          public final int stereoMode

      The stereo layout for 360/3D/VR video, or `NO_VALUE` if not applicable. Valid stereo modes are `C.STEREO_MODE_MONO`, `C.STEREO_MODE_TOP_BOTTOM`, `C.STEREO_MODE_LEFT_RIGHT`, `C.STEREO_MODE_STEREO_MESH`.

    - #### colorInfo

          @Nullable
          public final ColorInfo colorInfo

      The color metadata associated with the video, or null if not applicable.

    - #### channelCount

          public final int channelCount

      The number of audio channels, or `NO_VALUE` if unknown or not applicable.

    - #### sampleRate

          public final int sampleRate

      The audio sampling rate in Hz, or `NO_VALUE` if unknown or not applicable.

    - #### pcmEncoding

          @PcmEncoding
          public final int pcmEncoding

      The `C.PcmEncoding` for PCM audio. Set to `NO_VALUE` for other media types.

    - #### encoderDelay

          public final int encoderDelay

      The number of frames to trim from the start of the decoded audio stream, or 0 if not applicable.

    - #### encoderPadding

          public final int encoderPadding

      The number of frames to trim from the end of the decoded audio stream, or 0 if not applicable.

    - #### accessibilityChannel

          public final int accessibilityChannel

      The Accessibility channel, or `NO_VALUE` if not known or applicable.

    - #### exoMediaCryptoType

          @Nullable
          public final Class<? extends ExoMediaCrypto> exoMediaCryptoType

      The type of `ExoMediaCrypto` that will be associated with the content this format describes, or `null` if the content is not encrypted. Cannot be null if `drmInitData` is non-null.

    - #### CREATOR

          public static final Parcelable.Creator<Format> CREATOR

  - ### Method Detail

    - #### createVideoSampleFormat

          @Deprecated
          public static Format createVideoSampleFormat​(@Nullable
                                                       String id,
                                                       @Nullable
                                                       String sampleMimeType,
                                                       @Nullable
                                                       String codecs,
                                                       int bitrate,
                                                       int maxInputSize,
                                                       int width,
                                                       int height,
                                                       float frameRate,
                                                       @Nullable
                                                       List<byte[]> initializationData,
                                                       @Nullable
                                                       DrmInitData drmInitData)

      Deprecated.
      Use `Format.Builder`.

    - #### createVideoSampleFormat

          @Deprecated
          public static Format createVideoSampleFormat​(@Nullable
                                                       String id,
                                                       @Nullable
                                                       String sampleMimeType,
                                                       @Nullable
                                                       String codecs,
                                                       int bitrate,
                                                       int maxInputSize,
                                                       int width,
                                                       int height,
                                                       float frameRate,
                                                       @Nullable
                                                       List<byte[]> initializationData,
                                                       int rotationDegrees,
                                                       float pixelWidthHeightRatio,
                                                       @Nullable
                                                       DrmInitData drmInitData)

      Deprecated.
      Use `Format.Builder`.

    - #### createAudioSampleFormat

          @Deprecated
          public static Format createAudioSampleFormat​(@Nullable
                                                       String id,
                                                       @Nullable
                                                       String sampleMimeType,
                                                       @Nullable
                                                       String codecs,
                                                       int bitrate,
                                                       int maxInputSize,
                                                       int channelCount,
                                                       int sampleRate,
                                                       @Nullable
                                                       List<byte[]> initializationData,
                                                       @Nullable
                                                       DrmInitData drmInitData,
                                                       @SelectionFlags
                                                       int selectionFlags,
                                                       @Nullable
                                                       String language)

      Deprecated.
      Use `Format.Builder`.

    - #### createAudioSampleFormat

          @Deprecated
          public static Format createAudioSampleFormat​(@Nullable
                                                       String id,
                                                       @Nullable
                                                       String sampleMimeType,
                                                       @Nullable
                                                       String codecs,
                                                       int bitrate,
                                                       int maxInputSize,
                                                       int channelCount,
                                                       int sampleRate,
                                                       @PcmEncoding
                                                       int pcmEncoding,
                                                       @Nullable
                                                       List<byte[]> initializationData,
                                                       @Nullable
                                                       DrmInitData drmInitData,
                                                       @SelectionFlags
                                                       int selectionFlags,
                                                       @Nullable
                                                       String language)

      Deprecated.
      Use `Format.Builder`.

    - #### createContainerFormat

          @Deprecated
          public static Format createContainerFormat​(@Nullable
                                                     String id,
                                                     @Nullable
                                                     String label,
                                                     @Nullable
                                                     String containerMimeType,
                                                     @Nullable
                                                     String sampleMimeType,
                                                     @Nullable
                                                     String codecs,
                                                     int bitrate,
                                                     @SelectionFlags
                                                     int selectionFlags,
                                                     @RoleFlags
                                                     int roleFlags,
                                                     @Nullable
                                                     String language)

      Deprecated.
      Use `Format.Builder`.

    - #### createSampleFormat

          @Deprecated
          public static Format createSampleFormat​(@Nullable
                                                  String id,
                                                  @Nullable
                                                  String sampleMimeType)

      Deprecated.
      Use `Format.Builder`.

    - #### buildUpon

          public Format.Builder buildUpon()

      Returns a `Format.Builder` initialized with the values of this instance.

    - #### copyWithMaxInputSize

          @Deprecated
          public Format copyWithMaxInputSize​(int maxInputSize)

      Deprecated.
      Use `buildUpon()` and `Format.Builder.setMaxInputSize(int)`.

    - #### copyWithSubsampleOffsetUs

          @Deprecated
          public Format copyWithSubsampleOffsetUs​(long subsampleOffsetUs)

      Deprecated.
      Use `buildUpon()` and `Format.Builder.setSubsampleOffsetUs(long)`.

    - #### copyWithLabel

          @Deprecated
          public Format copyWithLabel​(@Nullable
                                      String label)

      Deprecated.
      Use `buildUpon()` and `Format.Builder.setLabel(String)` .

    - #### copyWithManifestFormatInfo

          @Deprecated
          public Format copyWithManifestFormatInfo​(Format manifestFormat)

      Deprecated.
      Use `withManifestFormatInfo(Format)`.

    - #### withManifestFormatInfo

          public Format withManifestFormatInfo​(Format manifestFormat)

    - #### copyWithGaplessInfo

          @Deprecated
          public Format copyWithGaplessInfo​(int encoderDelay,
                                            int encoderPadding)

      Deprecated.
      Use `buildUpon()`, `Format.Builder.setEncoderDelay(int)` and `Format.Builder.setEncoderPadding(int)`.

    - #### copyWithFrameRate

          @Deprecated
          public Format copyWithFrameRate​(float frameRate)

      Deprecated.
      Use `buildUpon()` and `Format.Builder.setFrameRate(float)`.

    - #### copyWithDrmInitData

          @Deprecated
          public Format copyWithDrmInitData​(@Nullable
                                            DrmInitData drmInitData)

      Deprecated.
      Use `buildUpon()` and `Format.Builder.setDrmInitData(DrmInitData)`.

    - #### copyWithMetadata

          @Deprecated
          public Format copyWithMetadata​(@Nullable
                                         Metadata metadata)

      Deprecated.
      Use `buildUpon()` and `Format.Builder.setMetadata(Metadata)`.

    - #### copyWithBitrate

          @Deprecated
          public Format copyWithBitrate​(int bitrate)

      Deprecated.
      Use `buildUpon()` and `Format.Builder.setAverageBitrate(int)` and `Format.Builder.setPeakBitrate(int)`.

    - #### copyWithVideoSize

          @Deprecated
          public Format copyWithVideoSize​(int width,
                                          int height)

      Deprecated.
      Use `buildUpon()`, `Format.Builder.setWidth(int)` and `Format.Builder.setHeight(int)`.

    - #### copyWithExoMediaCryptoType

          public Format copyWithExoMediaCryptoType​(@Nullable
                                                   Class<? extends ExoMediaCrypto> exoMediaCryptoType)

      Returns a copy of this format with the specified `exoMediaCryptoType`.

    - #### getPixelCount

          public int getPixelCount()

      Returns the number of pixels if this is a video format whose `width` and `height` are known, or `NO_VALUE` otherwise

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals​(@Nullable
                                Object obj)

      Overrides:
        `equals` in class `Object`

    - #### initializationDataEquals

          public boolean initializationDataEquals​(Format other)

      Returns whether the `initializationData`s belonging to this format and `other` are equal.
      Parameters:
        `other` - The other format whose `initializationData` is being compared.
      Returns:
        Whether the `initializationData`s belonging to this format and `other` are equal.

    - #### toLogString

          public static String toLogString​(@Nullable
                                           Format format)

      Returns a prettier `String` than `toString()`, intended for logging.

    - #### describeContents

          public int describeContents()

      Specified by:
        `describeContents` in interface `Parcelable`

    - #### writeToParcel

          public void writeToParcel​(Parcel dest,
                                    int flags)

      Specified by:
        `writeToParcel` in interface `Parcelable`