Class Mp4Muxer
- java.lang.Object
-
- com.google.android.exoplayer2.muxer.Mp4Muxer
-
@Deprecated public final class Mp4Muxer extends Object
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:
- Add tracks using
addTrack(int, Format)which will return aMp4Muxer.TrackToken. - Use the associated
Mp4Muxer.TrackTokenwhen writing samples for that track. close()the muxer when all data has been written.
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.
- Add tracks using
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMp4Muxer.BuilderDeprecated.A builder forMp4Muxerinstances.static interfaceMp4Muxer.LastFrameDurationBehaviorDeprecated.Behavior for the last sample duration.static interfaceMp4Muxer.TrackTokenDeprecated.A token representing an added track.
-
Field Summary
Fields Modifier and Type Field Description static intLAST_FRAME_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATIONDeprecated.Use the difference between the last timestamp and the one before that as the duration of the last sample.static intLAST_FRAME_DURATION_BEHAVIOR_INSERT_SHORT_FRAMEDeprecated.Insert a zero-length last sample.static ImmutableList<String>SUPPORTED_AUDIO_SAMPLE_MIME_TYPESDeprecated.A list of supported audio sample mime types.static ImmutableList<String>SUPPORTED_VIDEO_SAMPLE_MIME_TYPESDeprecated.A list of supported video sample mime types.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddMetadata(String key, Object value)Deprecated.Adds custom metadata.Mp4Muxer.TrackTokenaddTrack(int sortKey, Format format)Deprecated.Adds a track of the given media format.voidaddXmp(ByteBuffer xmp)Deprecated.Adds xmp data.voidclose()Deprecated.Closes the MP4 file.voidsetCaptureFps(float captureFps)Deprecated.Sets the capture frame rate.voidsetLocation(float latitude, float longitude)Deprecated.Sets the location.voidsetModificationTime(long timestampMs)Deprecated.Sets the file modification time.voidsetOrientation(int orientation)Deprecated.Sets the orientation hint for the video playback.voidwriteSampleData(Mp4Muxer.TrackToken trackToken, ByteBuffer byteBuffer, MediaCodec.BufferInfo bufferInfo)Deprecated.Writes encoded sample data.
-
-
-
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<String> SUPPORTED_VIDEO_SAMPLE_MIME_TYPES
Deprecated.A list of supported video sample mime types.
-
SUPPORTED_AUDIO_SAMPLE_MIME_TYPES
public static final ImmutableList<String> 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.
-
addXmp
public void addXmp(ByteBuffer xmp)
Deprecated.Adds xmp data.- Parameters:
xmp- The xmpByteBuffer.
-
addTrack
public Mp4Muxer.TrackToken addTrack(int sortKey, Format 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- TheFormatfor the track.- Returns:
- A unique
Mp4Muxer.TrackToken. It should be used inwriteSampleData(com.google.android.exoplayer2.muxer.Mp4Muxer.TrackToken, java.nio.ByteBuffer, android.media.MediaCodec.BufferInfo).
-
writeSampleData
public void writeSampleData(Mp4Muxer.TrackToken trackToken, ByteBuffer byteBuffer, MediaCodec.BufferInfo bufferInfo) throws IOException
Deprecated.Writes encoded sample data.- Parameters:
trackToken- TheMp4Muxer.TrackTokenfor which this sample is being written.byteBuffer- The encoded sample.bufferInfo- TheMediaCodec.BufferInforelated to this sample.- Throws:
IOException- If there is any error while writing data to the disk.
-
close
public void close() throws IOExceptionDeprecated.Closes the MP4 file.- Throws:
IOException
-
-