MediaFormatUtil
@UnstableApi
public final class MediaFormatUtil
Helper class containing utility methods for managing MediaFormat instances.
Summary
Constants |
|
|---|---|
static final String |
KEY_MAX_BIT_RATE = "max-bitrate"The |
static final String |
KEY_PCM_ENCODING_EXTENDED = "exo-pcm-encoding-int"Custom |
static final String |
KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT = "exo-pixel-width-height-ratio-float"Custom |
Public methods |
|
|---|---|
static Format |
createFormatFromMediaFormat(MediaFormat mediaFormat)Returns a |
static MediaFormat |
createMediaFormatFromFormat(Format format)Returns a |
static byte[] |
getArray(ByteBuffer byteBuffer) |
static @Nullable ColorInfo |
getColorInfo(MediaFormat mediaFormat)Creates and returns a |
static float |
getFloat(MediaFormat mediaFormat, String name, float defaultValue)Supports |
static float |
getFloatFromIntOrFloat(Returns the value of a key whose value can be set as int or float. |
static int |
getInteger(MediaFormat mediaFormat, String name, int defaultValue)Supports |
static @Nullable String |
getString(Supports |
static @Nullable Integer |
getTimeLapseFrameRate(MediaFormat format)Returns the time lapse capture FPS from the given |
static boolean |
isAudioFormat(MediaFormat mediaFormat)Returns whether a |
static boolean |
isVideoFormat(MediaFormat mediaFormat)Returns whether a |
static void |
maybeSetByteBuffer(MediaFormat format, String key, @Nullable byte[] value)Sets a |
static void |
maybeSetColorInfo(MediaFormat format, @Nullable ColorInfo colorInfo)Sets a |
static void |
maybeSetFloat(MediaFormat format, String key, float value)Sets a |
static void |
maybeSetInteger(MediaFormat format, String key, int value)Sets a |
static void |
maybeSetString(MediaFormat format, String key, @Nullable String value)Sets a |
static void |
setCsdBuffers(MediaFormat format, List<byte[]> csdBuffers)Sets a |
Constants
KEY_MAX_BIT_RATE
public static final String KEY_MAX_BIT_RATE = "max-bitrate"
The MediaFormat key for the maximum bitrate in bits per second.
The associated value is an integer.
The key string constant is the same as MediaFormat#KEY_MAX_BITRATE. Values for it are already returned by the framework MediaExtractor; the key is a hidden field in
MediaFormat though, which is why it's being replicated here.
KEY_PCM_ENCODING_EXTENDED
public static final String KEY_PCM_ENCODING_EXTENDED = "exo-pcm-encoding-int"
Custom MediaFormat key associated with an integer representing the PCM encoding.
Equivalent to KEY_PCM_ENCODING, except it allows additional values defined by C.PcmEncoding, including ENCODING_PCM_16BIT_BIG_ENDIAN, ENCODING_PCM_24BIT, ENCODING_PCM_24BIT_BIG_ENDIAN, ENCODING_PCM_32BIT and ENCODING_PCM_32BIT_BIG_ENDIAN.
KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT
public static final String KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT = "exo-pixel-width-height-ratio-float"
Custom MediaFormat key associated with a float representing the ratio between a pixel's width and height.
Public methods
createFormatFromMediaFormat
public static Format createFormatFromMediaFormat(MediaFormat mediaFormat)
Returns a Format representing the given MediaFormat.
createMediaFormatFromFormat
public static MediaFormat createMediaFormatFromFormat(Format format)
Returns a MediaFormat representing the given ExoPlayer Format.
May include the following custom keys:
getColorInfo
public static @Nullable ColorInfo getColorInfo(MediaFormat mediaFormat)
Creates and returns a ColorInfo, if a valid instance is described in the MediaFormat.
Under API 24, null will always be returned, because MediaFormat color keys like KEY_COLOR_STANDARD were only added in API 24.
getFloat
public static float getFloat(MediaFormat mediaFormat, String name, float defaultValue)
Supports getFloat for API < 29.
getFloatFromIntOrFloat
public static float getFloatFromIntOrFloat(
MediaFormat mediaFormat,
String keyName,
float defaultValue
)
Returns the value of a key whose value can be set as int or float.
The defaultValue is returned if the key is not present in the MediaFormat.
| Throws | |
|---|---|
java.lang.ClassCastException |
If the stored value for the key is other than int or float. |
getInteger
public static int getInteger(MediaFormat mediaFormat, String name, int defaultValue)
Supports getInteger for API < 29.
getString
public static @Nullable String getString(
MediaFormat mediaFormat,
String name,
@Nullable String defaultValue
)
Supports getString for API < 29.
getTimeLapseFrameRate
public static @Nullable Integer getTimeLapseFrameRate(MediaFormat format)
Returns the time lapse capture FPS from the given MediaFormat if it was set.
isAudioFormat
public static boolean isAudioFormat(MediaFormat mediaFormat)
Returns whether a MediaFormat is an audio format.
isVideoFormat
public static boolean isVideoFormat(MediaFormat mediaFormat)
Returns whether a MediaFormat is a video format.
maybeSetByteBuffer
public static void maybeSetByteBuffer(MediaFormat format, String key, @Nullable byte[] value)
Sets a MediaFormatByteBuffer value. Does nothing if value is null.
| Parameters | |
|---|---|
MediaFormat format |
The |
String key |
The key to set. |
@Nullable byte[] value |
The byte array that will be wrapped to obtain the value. |
maybeSetColorInfo
public static void maybeSetColorInfo(MediaFormat format, @Nullable ColorInfo colorInfo)
Sets a MediaFormat's color information. Does nothing if colorInfo is null.
| Parameters | |
|---|---|
MediaFormat format |
The |
@Nullable ColorInfo colorInfo |
The color info to set. |
maybeSetFloat
public static void maybeSetFloat(MediaFormat format, String key, float value)
Sets a MediaFormat float value. Does nothing if value is NO_VALUE.
| Parameters | |
|---|---|
MediaFormat format |
The |
String key |
The key to set. |
float value |
The value to set. |
maybeSetInteger
public static void maybeSetInteger(MediaFormat format, String key, int value)
Sets a MediaFormat integer value. Does nothing if value is NO_VALUE.
| Parameters | |
|---|---|
MediaFormat format |
The |
String key |
The key to set. |
int value |
The value to set. |
maybeSetString
public static void maybeSetString(MediaFormat format, String key, @Nullable String value)
Sets a MediaFormatString value. Does nothing if value is null.
| Parameters | |
|---|---|
MediaFormat format |
The |
String key |
The key to set. |
@Nullable String value |
The value to set. |
setCsdBuffers
public static void setCsdBuffers(MediaFormat format, List<byte[]> csdBuffers)
Sets a MediaFormat's codec specific data buffers.
| Parameters | |
|---|---|
MediaFormat format |
The |
List<byte[]> csdBuffers |
The csd buffers to set. |