Stay organized with collections Save and categorize content based on your preferences.

Format

public final class Format implements Bundleable


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

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

Fields relevant to video formats

Fields relevant to audio formats

Fields relevant to text formats

Summary

Nested types

@UnstableApi
public final class Format.Builder

Builds Format instances.

Constants

static final Bundleable.Creator<Format>

Object that can restore Format from a Bundle.

static final int

A value for various fields to indicate that the field's value is unknown or not applicable.

static final long
@UnstableApi
OFFSET_SAMPLE_RELATIVE = 9223372036854775807

A value for subsampleOffsetUs to indicate that subsample timestamps are relative to the timestamps of their parent samples.

Public fields

final int

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

final int

The average bitrate in bits per second, or NO_VALUE if unknown or not applicable.

final int

The bitrate in bits per second.

final int

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

final @Nullable String

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

final @Nullable ColorInfo

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

final @Nullable String

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

final int

The type of crypto that must be used to decode samples associated with this format, or CRYPTO_TYPE_NONE if the content is not encrypted.

final @Nullable DrmInitData

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

final int

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

final int

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

final float

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

final int

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

final @Nullable String

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

final List<byte[]>

Initialization data that must be provided to the decoder.

final @Nullable String

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

final @Nullable String

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

final int

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

final @Nullable Metadata

Metadata, or null if unknown or not applicable.

final int

The C.PcmEncoding for PCM audio.

final int

The peak bitrate in bits per second, or NO_VALUE if unknown or not applicable.

final float

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

final @Nullable byte[]

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

final int

Track role flags.

final int

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.

final @Nullable String

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

final int

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

final int

Track selection flags.

final int

The stereo layout for 360/3D/VR video, or NO_VALUE if not applicable.

final long

For samples that contain subsamples, this is an offset that should be added to subsample timestamps.

final int

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

Public constructors

Public methods

Format.Builder

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

Format

This method is deprecated.

Use buildUpon and setAverageBitrate and setPeakBitrate.

Format

Returns a copy of this format with the specified cryptoType.

Format

This method is deprecated.

Use buildUpon and setDrmInitData.

Format
@UnstableApi
copyWithFrameRate(float frameRate)

This method is deprecated.

Use buildUpon and setFrameRate.

Format
@UnstableApi
copyWithGaplessInfo(int encoderDelay, int encoderPadding)

This method is deprecated.

Use buildUpon, setEncoderDelay and setEncoderPadding.

Format

This method is deprecated.

Use buildUpon and setLabel .

Format

This method is deprecated.

Use withManifestFormatInfo.

Format

This method is deprecated.

Use buildUpon and setMaxInputSize.

Format

This method is deprecated.

Use buildUpon and setMetadata.

Format
@UnstableApi
copyWithSubsampleOffsetUs(long subsampleOffsetUs)

This method is deprecated.

Use buildUpon and setSubsampleOffsetUs.

Format
@UnstableApi
copyWithVideoSize(int width, int height)

This method is deprecated.

Use buildUpon, setWidth and setHeight.

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

This method is deprecated.

Use Format.Builder.

static Format
@UnstableApi
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,
    @C.SelectionFlags int selectionFlags,
    @Nullable String language
)

This method is deprecated.

Use Format.Builder.

static Format
@UnstableApi
createContainerFormat(
    @Nullable String id,
    @Nullable String label,
    @Nullable String containerMimeType,
    @Nullable String sampleMimeType,
    @Nullable String codecs,
    int bitrate,
    @C.SelectionFlags int selectionFlags,
    @C.RoleFlags int roleFlags,
    @Nullable String language
)

This method is deprecated.

Use Format.Builder.

static Format

This method is deprecated.

Use Format.Builder.

static Format
@UnstableApi
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
)

This method is deprecated.

Use Format.Builder.

static Format
@UnstableApi
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
)

This method is deprecated.

Use Format.Builder.

boolean
int

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

int
boolean

Returns whether the initializationDatas belonging to this format and other are equal.

Bundle

Returns a Bundle representing the information stored in this object.

Bundle
@UnstableApi
toBundle(boolean excludeMetadata)

Returns a Bundle representing the information stored in this object.

static String

Returns a prettier String than toString, intended for logging.

String
Format

Constants

CREATOR

@UnstableApi
public static final Bundleable.Creator<FormatCREATOR

Object that can restore Format from a Bundle.

NO_VALUE

public static final int NO_VALUE = -1

A value for various fields to indicate that the field's value is unknown or not applicable.

OFFSET_SAMPLE_RELATIVE

@UnstableApi
public static final long OFFSET_SAMPLE_RELATIVE = 9223372036854775807

A value for subsampleOffsetUs to indicate that subsample timestamps are relative to the timestamps of their parent samples.

Public fields

accessibilityChannel

@UnstableApi
public final int accessibilityChannel

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

averageBitrate

@UnstableApi
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 multivariant 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., AUDIO_AAC), then this bitrate is for the stream of still compressed samples.

bitrate

@UnstableApi
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.

channelCount

public final int channelCount

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

codecs

public final @Nullable String codecs

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

colorInfo

@UnstableApi
public final @Nullable ColorInfo colorInfo

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

containerMimeType

public final @Nullable String containerMimeType

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

cryptoType

@UnstableApi
@C.CryptoType
public final int cryptoType

The type of crypto that must be used to decode samples associated with this format, or CRYPTO_TYPE_NONE if the content is not encrypted. Cannot be CRYPTO_TYPE_NONE if drmInitData is non-null, but may be CRYPTO_TYPE_UNSUPPORTED to indicate that the samples are encrypted using an unsupported crypto type.

drmInitData

@UnstableApi
public final @Nullable DrmInitData drmInitData

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

encoderDelay

@UnstableApi
public final int encoderDelay

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

encoderPadding

@UnstableApi
public final int encoderPadding

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

frameRate

public final float frameRate

The frame rate in frames per second, 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.

id

public final @Nullable String id

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

initializationData

@UnstableApi
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.

label

public final @Nullable String label

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

language

public final @Nullable String language

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

maxInputSize

@UnstableApi
public final int maxInputSize

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

metadata

@UnstableApi
public final @Nullable Metadata metadata

Metadata, or null if unknown or not applicable.

pcmEncoding

@UnstableApi
@C.PcmEncoding
public final int pcmEncoding

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

peakBitrate

@UnstableApi
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., AUDIO_AAC), then this bitrate is for the stream of still compressed samples.

pixelWidthHeightRatio

public final float pixelWidthHeightRatio

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

projectionData

@UnstableApi
public final @Nullable byte[] projectionData

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

roleFlags

@C.RoleFlags
public final int roleFlags

Track role flags.

rotationDegrees

@UnstableApi
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.

sampleMimeType

public final @Nullable String sampleMimeType

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

sampleRate

public final int sampleRate

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

selectionFlags

@C.SelectionFlags
public final int selectionFlags

Track selection flags.

stereoMode

@UnstableApi
@C.StereoMode
public final int stereoMode

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

subsampleOffsetUs

@UnstableApi
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.

Public constructors

Format

public Format()

Public methods

buildUpon

@UnstableApi
public Format.Builder buildUpon()

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

copyWithBitrate

@UnstableApi
public Format copyWithBitrate(int bitrate)

copyWithCryptoType

@UnstableApi
public Format copyWithCryptoType(@C.CryptoType int cryptoType)

Returns a copy of this format with the specified cryptoType.

copyWithDrmInitData

@UnstableApi
public Format copyWithDrmInitData(@Nullable DrmInitData drmInitData)

copyWithFrameRate

@UnstableApi
public Format copyWithFrameRate(float frameRate)

copyWithGaplessInfo

@UnstableApi
public Format copyWithGaplessInfo(int encoderDelay, int encoderPadding)

copyWithLabel

@UnstableApi
public Format copyWithLabel(@Nullable String label)

copyWithManifestFormatInfo

@UnstableApi
public Format copyWithManifestFormatInfo(Format manifestFormat)

copyWithMaxInputSize

@UnstableApi
public Format copyWithMaxInputSize(int maxInputSize)

copyWithMetadata

@UnstableApi
public Format copyWithMetadata(@Nullable Metadata metadata)

copyWithSubsampleOffsetUs

@UnstableApi
public Format copyWithSubsampleOffsetUs(long subsampleOffsetUs)

copyWithVideoSize

@UnstableApi
public Format copyWithVideoSize(int width, int height)

createAudioSampleFormat

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

createAudioSampleFormat

@UnstableApi
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,
    @C.SelectionFlags int selectionFlags,
    @Nullable String language
)

createContainerFormat

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

createSampleFormat

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

createVideoSampleFormat

@UnstableApi
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
)

createVideoSampleFormat

@UnstableApi
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
)

equals

public boolean equals(@Nullable Object obj)

getPixelCount

@UnstableApi
public int getPixelCount()

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

hashCode

public int hashCode()

initializationDataEquals

@UnstableApi
public boolean initializationDataEquals(Format other)

Returns whether the initializationDatas belonging to this format and other are equal.

Parameters
Format other

The other format whose initializationData is being compared.

Returns
boolean

Whether the initializationDatas belonging to this format and other are equal.

toBundle

@UnstableApi
public Bundle toBundle()

Returns a Bundle representing the information stored in this object.

toBundle

@UnstableApi
public Bundle toBundle(boolean excludeMetadata)

Returns a Bundle representing the information stored in this object. If excludeMetadata is true, metadata is excluded.

toLogString

@UnstableApi
public static String toLogString(@Nullable Format format)

Returns a prettier String than toString, intended for logging.

toString

public String toString()

withManifestFormatInfo

@UnstableApi
public Format withManifestFormatInfo(Format manifestFormat)