Class MediaFormat

  • All Implemented Interfaces:
    android.os.Parcelable

    public final class MediaFormat
    extends java.lang.Object
    implements android.os.Parcelable
    An immutable Parcelable object that can be used describe the format of media stream.

    This is a derivative of the media format class in ExoPlayer 1 SDK.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface android.os.Parcelable

        android.os.Parcelable.ClassLoaderCreator<T extends java.lang.Object>, android.os.Parcelable.Creator<T extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean adaptive
      Specifies whether the format represents an adaptive track, meaning that the format of the actual media data may change (e.g.
      int bitrate
      The average bandwidth in bits per second, or Constants.NO_VALUE if unknown or not applicable.
      int channelCount
      The number of audio channels, or Constants.NO_VALUE if unknown or not applicable.
      static android.os.Parcelable.Creator<MediaFormat> CREATOR  
      long durationUs
      The duration in microseconds, or Constants.UNKNOWN_TIME_US if the duration is unknown, or Constants.MATCH_LONGEST_US if the duration should match the duration of the longest track whose duration is known.
      int encoderDelay
      The number of samples to trim from the start of the decoded audio stream.
      int encoderPadding
      The number of samples to trim from the end of the decoded audio stream.
      int height
      The height of the video in pixels, or Constants.NO_VALUE if unknown or not applicable.
      java.util.List<byte[]> initializationData
      Initialization data that must be provided to the decoder.
      java.lang.String language
      The language of the track, or null if unknown or not applicable
      int maxHeight
      If the video is flagged adaptive, this is the maximum height of the video in pixels that will be encountered in the stream.
      int maxInputSize
      The maximum size of a buffer of data (typically one sample) in the format, or Constants.NO_VALUE if unknown or not applicable.
      int maxWidth
      If the video is flagged adaptive, this is the maximum width of the video in pixels that will be encountered in the stream.
      java.lang.String mimeType
      The mime type of the format.
      static java.util.List<byte[]> NO_INITIALIZATION_DATA
      Empty initialization data.
      static long OFFSET_SAMPLE_RELATIVE
      A value for subSampleOffsetUs to indicate that sub-sample timestamps are relative to the timestamps of their parent samples.
      int pcmEncoding
      The encoding for PCM audio streams.
      float pixelWidthHeightRatio
      The width to height ratio of pixels in the video, or Constants.NO_VALUE if unknown or not applicable.
      byte[] projectionData
      The projection data for 360/VR video, or null if not applicable.
      int rotationDegrees
      The clockwise rotation that should be applied to the video for it to be rendered in the correct orientation, or Constants.NO_VALUE if unknown or not applicable.
      int sampleRate
      The audio sampling rate in Hz, or Constants.NO_VALUE if unknown or not applicable.
      int stereoMode
      The stereo layout for 360/3D/VR video, or NO_VALUE if not applicable.
      long subSampleOffsetUs
      For samples that contain sub-samples, this is an offset that should be added to sub-sample timestamps.
      java.lang.String trackId
      The identifier for the track represented by the format, or null if unknown or not applicable.
      int width
      The width of the video in pixels, or Constants.NO_VALUE if unknown or not applicable.
      • Fields inherited from interface android.os.Parcelable

        CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
    • Field Detail

      • OFFSET_SAMPLE_RELATIVE

        public static final long OFFSET_SAMPLE_RELATIVE
        A value for subSampleOffsetUs to indicate that sub-sample timestamps are relative to the timestamps of their parent samples.
        See Also:
        Constant Field Values
      • NO_INITIALIZATION_DATA

        public static final java.util.List<byte[]> NO_INITIALIZATION_DATA
        Empty initialization data.
      • trackId

        @Nullable
        public final java.lang.String trackId
        The identifier for the track represented by the format, or null if unknown or not applicable.
      • mimeType

        @NonNull
        public final java.lang.String mimeType
        The mime type of the format.
      • bitrate

        public final int bitrate
        The average bandwidth in bits per second, or Constants.NO_VALUE if unknown or not applicable.
      • maxInputSize

        public final int maxInputSize
        The maximum size of a buffer of data (typically one sample) in the format, or Constants.NO_VALUE if unknown or not applicable.
      • initializationData

        @NonNull
        public final java.util.List<byte[]> initializationData
        Initialization data that must be provided to the decoder. Set to NO_INITIALIZATION_DATA if there is initialization data.
      • adaptive

        public final boolean adaptive
        Specifies whether the format represents an adaptive track, meaning that the format of the actual media data may change (e.g. to adapt to network conditions).
      • width

        public final int width
        The width of the video in pixels, or Constants.NO_VALUE if unknown or not applicable.
      • height

        public final int height
        The height of the video in pixels, or Constants.NO_VALUE if unknown or not applicable.
      • maxWidth

        public final int maxWidth
        If the video is flagged adaptive, this is the maximum width of the video in pixels that will be encountered in the stream. Set to Constants.NO_VALUE if unknown or not applicable.
      • maxHeight

        public final int maxHeight
        If the video is flagged adaptive, this is the maximum height of the video in pixels that will be encountered in the stream. Set to Constants.NO_VALUE if unknown or not applicable.
      • pixelWidthHeightRatio

        public final float pixelWidthHeightRatio
        The width to height ratio of pixels in the video, or Constants.NO_VALUE if unknown or not applicable.
      • stereoMode

        public final int stereoMode
        The stereo layout for 360/3D/VR video, or NO_VALUE if 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 Constants.NO_VALUE if unknown or not applicable.
      • projectionData

        @Nullable
        public final byte[] projectionData
        The projection data for 360/VR video, or null if not applicable.
      • channelCount

        public final int channelCount
        The number of audio channels, or Constants.NO_VALUE if unknown or not applicable.
      • sampleRate

        public final int sampleRate
        The audio sampling rate in Hz, or Constants.NO_VALUE if unknown or not applicable.
      • pcmEncoding

        public final int pcmEncoding
        The encoding for PCM audio streams.
      • encoderDelay

        public final int encoderDelay
        The number of samples to trim from the start of the decoded audio stream.
      • encoderPadding

        public final int encoderPadding
        The number of samples to trim from the end of the decoded audio stream.
      • language

        @Nullable
        public final java.lang.String language
        The language of the track, or null if unknown or not applicable
      • subSampleOffsetUs

        public final long subSampleOffsetUs
        For samples that contain sub-samples, this is an offset that should be added to sub-sample timestamps.
      • CREATOR

        public static final android.os.Parcelable.Creator<MediaFormat> CREATOR
    • Method Detail

      • createVideoFormat

        public static MediaFormat createVideoFormat​(java.lang.String trackId,
                                                    java.lang.String mimeType,
                                                    int bitrate,
                                                    int maxInputSize,
                                                    long durationUs,
                                                    int width,
                                                    int height,
                                                    java.util.List<byte[]> initializationData)
      • createVideoFormat

        public static MediaFormat createVideoFormat​(java.lang.String trackId,
                                                    java.lang.String mimeType,
                                                    int bitrate,
                                                    int maxInputSize,
                                                    long durationUs,
                                                    int width,
                                                    int height,
                                                    java.util.List<byte[]> initializationData,
                                                    int rotationDegrees,
                                                    float pixelWidthHeightRatio)
      • createVideoFormat

        public static MediaFormat createVideoFormat​(java.lang.String trackId,
                                                    java.lang.String mimeType,
                                                    int bitrate,
                                                    int maxInputSize,
                                                    long durationUs,
                                                    int width,
                                                    int height,
                                                    java.util.List<byte[]> initializationData,
                                                    int rotationDegrees,
                                                    float pixelWidthHeightRatio,
                                                    byte[] projectionData,
                                                    int stereoMode)
      • createAudioFormat

        public static MediaFormat createAudioFormat​(java.lang.String trackId,
                                                    java.lang.String mimeType,
                                                    int bitrate,
                                                    int maxInputSize,
                                                    long durationUs,
                                                    int channelCount,
                                                    int sampleRate,
                                                    java.util.List<byte[]> initializationData,
                                                    java.lang.String language)
      • createAudioFormat

        public static MediaFormat createAudioFormat​(java.lang.String trackId,
                                                    java.lang.String mimeType,
                                                    int bitrate,
                                                    int maxInputSize,
                                                    long durationUs,
                                                    int channelCount,
                                                    int sampleRate,
                                                    java.util.List<byte[]> initializationData,
                                                    java.lang.String language,
                                                    int pcmEncoding)
      • createTextFormat

        public static MediaFormat createTextFormat​(java.lang.String trackId,
                                                   java.lang.String mimeType,
                                                   int bitrate,
                                                   long durationUs,
                                                   java.lang.String language)
      • createTextFormat

        public static MediaFormat createTextFormat​(java.lang.String trackId,
                                                   java.lang.String mimeType,
                                                   int bitrate,
                                                   long durationUs,
                                                   java.lang.String language,
                                                   long subSampleOffsetUs)
      • createImageFormat

        public static MediaFormat createImageFormat​(java.lang.String trackId,
                                                    java.lang.String mimeType,
                                                    int bitrate,
                                                    long durationUs,
                                                    java.util.List<byte[]> initializationData,
                                                    java.lang.String language)
      • createFormatForMimeType

        public static MediaFormat createFormatForMimeType​(java.lang.String trackId,
                                                          java.lang.String mimeType,
                                                          int bitrate,
                                                          long durationUs)
      • createId3Format

        public static MediaFormat createId3Format()
      • copyWithMaxInputSize

        public MediaFormat copyWithMaxInputSize​(int maxInputSize)
      • copyWithMaxVideoDimensions

        public MediaFormat copyWithMaxVideoDimensions​(int maxWidth,
                                                      int maxHeight)
      • copyWithSubSampleOffsetUs

        public MediaFormat copyWithSubSampleOffsetUs​(long subSampleOffsetUs)
      • copyWithDurationUs

        public MediaFormat copyWithDurationUs​(long durationUs)
      • copyWithLanguage

        public MediaFormat copyWithLanguage​(java.lang.String language)
      • copyWithFixedTrackInfo

        public MediaFormat copyWithFixedTrackInfo​(java.lang.String trackId,
                                                  int bitrate,
                                                  int width,
                                                  int height,
                                                  java.lang.String language)
      • copyAsAdaptive

        public MediaFormat copyAsAdaptive​(java.lang.String trackId)
      • copyWithGaplessInfo

        public MediaFormat copyWithGaplessInfo​(int encoderDelay,
                                               int encoderPadding)
      • getFrameworkMediaFormatV16

        public final android.media.MediaFormat getFrameworkMediaFormatV16()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • describeContents

        public int describeContents()
        Specified by:
        describeContents in interface android.os.Parcelable
      • writeToParcel

        public void writeToParcel​(android.os.Parcel dest,
                                  int flags)
        Specified by:
        writeToParcel in interface android.os.Parcelable