Back to Exoplayer

Mp4Muxer (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/muxer/Mp4Muxer.html

latest11.1 KB
Original Source

Package com.google.android.exoplayer2.muxer

Class Mp4Muxer


[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public final classMp4Muxerextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")

Deprecated. com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.

A muxer for creating an MP4 container file.

The muxer supports writing H264, H265 and AV1 video, AAC audio and metadata.

All the operations are performed on the caller thread.

To create an MP4 container file, the caller must:

Some key points:

  • Tracks can be added at any point, even after writing some samples to other tracks.

  • The caller is responsible for ensuring that samples of different track types are well interleaved by calling writeSampleData(TrackToken, ByteBuffer, BufferInfo) in an order that interleaves samples from different tracks.

  • When writing a file, if an error occurs and the muxer is not closed, then the output MP4 file may still have some partial data.

Nested Class Summary

Nested Classes | Modifier and Type | Class | Description | | --- | --- | --- | | static class | Mp4Muxer.Builder | Deprecated.

A builder for Mp4Muxer instances. | | static interface | Mp4Muxer.LastFrameDurationBehavior | Deprecated.

Behavior for the last sample duration. | | static interface | Mp4Muxer.TrackToken | Deprecated.

A token representing an added track. |

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | static int | LAST_FRAME_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION | Deprecated.

Use the difference between the last timestamp and the one before that as the duration of the last sample. | | static int | LAST_FRAME_DURATION_BEHAVIOR_INSERT_SHORT_FRAME | Deprecated.

Insert a zero-length last sample. | | static ImmutableList<String> | SUPPORTED_AUDIO_SAMPLE_MIME_TYPES | Deprecated.

A list of supported audio sample mime types. | | static ImmutableList<String> | SUPPORTED_VIDEO_SAMPLE_MIME_TYPES | Deprecated.

A list of supported video sample mime types. |

Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | void | addMetadata​(String key, Object value) | Deprecated.

Adds custom metadata. | | Mp4Muxer.TrackToken | addTrack​(int sortKey, Format format) | Deprecated.

Adds a track of the given media format. | | void | addXmp​(ByteBuffer xmp) | Deprecated.

Adds xmp data. | | void | close() | Deprecated.

Closes the MP4 file. | | void | setCaptureFps​(float captureFps) | Deprecated.

Sets the capture frame rate. | | void | setLocation​(float latitude, float longitude) | Deprecated.

Sets the location. | | void | setModificationTime​(long timestampMs) | Deprecated.

Sets the file modification time. | | void | setOrientation​(int orientation) | Deprecated.

Sets the orientation hint for the video playback. | | void | writeSampleData​(Mp4Muxer.TrackToken trackToken, ByteBuffer byteBuffer, MediaCodec.BufferInfo bufferInfo) | Deprecated.

Writes encoded sample data. |

- 

Methods inherited from class java.lang.Object

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

Field Detail

- 

LAST_FRAME_DURATION_BEHAVIOR_INSERT_SHORT_FRAME

public static final int LAST_FRAME_DURATION_BEHAVIOR_INSERT_SHORT_FRAME

Deprecated.

Insert a zero-length last sample. See Also:Constant Field Values

- 

LAST_FRAME_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION

public static final int LAST_FRAME_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION

Deprecated.

Use the difference between the last timestamp and the one before that as the duration of the last sample. See Also:Constant Field Values

- 

SUPPORTED_VIDEO_SAMPLE_MIME_TYPES

public static final[ImmutableList](https://guava.dev/releases/31.1-android/api/docs/com/google/common/collect/ImmutableList.html?is-external=true "class or interface in com.google.common.collect")<[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")> SUPPORTED_VIDEO_SAMPLE_MIME_TYPES

Deprecated.

A list of supported video sample mime types.

- 

SUPPORTED_AUDIO_SAMPLE_MIME_TYPES

public static final[ImmutableList](https://guava.dev/releases/31.1-android/api/docs/com/google/common/collect/ImmutableList.html?is-external=true "class or interface in com.google.common.collect")<[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")> SUPPORTED_AUDIO_SAMPLE_MIME_TYPES

Deprecated.

A list of supported audio sample mime types.

Method Detail

- 

setOrientation

public void setOrientation​(int orientation)

Deprecated.

Sets the orientation hint for the video playback. Parameters:orientation - The orientation, in degrees.

- 

setLocation

public void setLocation​(@FloatRange(from=-90.0,to=90.0)
                        float latitude,
                        @FloatRange(from=-180.0,to=180.0)
                        float longitude)

Deprecated.

Sets the location. Parameters:latitude - The latitude, in degrees. Its value must be in the range [-90, 90].longitude - The longitude, in degrees. Its value must be in the range [-180, 180].

- 

setCaptureFps

public void setCaptureFps​(float captureFps)

Deprecated.

Sets the capture frame rate. Parameters:captureFps - The frame rate.

- 

setModificationTime

public void setModificationTime​(long timestampMs)

Deprecated.

Sets the file modification time. Parameters:timestampMs - The modification time UTC in milliseconds since the Unix epoch.

- 

addMetadata

public void addMetadata​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")key,[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")value)

Deprecated.

Adds custom metadata. Parameters:key - The metadata key in String format.value - The metadata value in String or Float format.

- 

addXmp

public void addXmp​([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")xmp)

Deprecated.

Adds xmp data. Parameters:xmp - The xmp ByteBuffer.

- 

addTrack

public[Mp4Muxer.TrackToken](Mp4Muxer.TrackToken.html "interface in com.google.android.exoplayer2.muxer")addTrack​(int sortKey,[Format](../Format.html "class in com.google.android.exoplayer2")format)

Deprecated.

Adds a track of the given media format.

Tracks can be added at any point before the muxer is closed, even after writing samples to other tracks.

The final order of tracks is determined by the provided sort key. Tracks with a lower sort key will always have a lower track id than tracks with a higher sort key. Ordering between tracks with the same sort key is not specified.

Parameters:sortKey - The key used for sorting the track list.format - The Format for the track.Returns:A unique Mp4Muxer.TrackToken. It should be used in writeSampleData(com.google.android.exoplayer2.muxer.Mp4Muxer.TrackToken, java.nio.ByteBuffer, android.media.MediaCodec.BufferInfo).

- 

writeSampleData

public void writeSampleData​([Mp4Muxer.TrackToken](Mp4Muxer.TrackToken.html "interface in com.google.android.exoplayer2.muxer")trackToken,[ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")byteBuffer,[MediaCodec.BufferInfo](https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html "class or interface in android.media")bufferInfo)
                     throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")

Deprecated.

Writes encoded sample data. Parameters:trackToken - The Mp4Muxer.TrackToken for which this sample is being written.byteBuffer - The encoded sample.bufferInfo - The MediaCodec.BufferInfo related to this sample.Throws:IOException - If there is any error while writing data to the disk.

- 

close

public void close()
           throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")

Deprecated.

Closes the MP4 file. Throws:IOException