Skip to main content
Version: 21 Aug 2024

Muxer

APIs for MediaMuxer to facilitate muxing of elementary streams. More...

Detailed Description

public class Muxer; 

Details*

MediaMuxer description goes here.


Public Methods

MLResult AddAudioTrack

Add a new audio track. This should be called before Start and after Configure. GetSupportedMimes can be used to query for all the supported MIME types for a given audio output format.

public MLResult AddAudioTrack(
string mimeType,
int sampleRate,
int channels,
out int addedTrackIndex
)

Parameters

TypeNameDescription
stringmimeTypeThe audio content's MIME type.
intsampleRateThe audio's sample rate.
intchannelsThe number of audio channels.
out intaddedTrackIndexIndex of the added audio track.

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult AddVideoTrack

Add a new video track. This should be called before Start and after Configure. GetSupportedMimes can be used to query for all the supported MIME types for a given video output format.

public MLResult AddVideoTrack(
string mimeType,
int width,
int height,
out int addedTrackIndex
)

Parameters

TypeNameDescription
stringmimeTypeThe video content's MIME type.
intwidthThe video content's width in pixels.
intheightThe video content's height in pixels.
out intaddedTrackIndexIndex of the added video track.

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult Configure

Configure the Muxer for a given output format with output path.

public MLResult Configure(
OutputFormat format,
string filePath
)

Parameters

TypeNameDescription
OutputFormatformatThe format of the muxed output media file. Value should be one returned from GetSupportedOutputFormats
stringfilePath

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult GetSupportedMimes

Get a list of all the supported mime-types for a given Media Muxer Output Format.

public MLResult GetSupportedMimes(
OutputFormat format,
out string [] results
)

Parameters

TypeNameDescription
OutputFormatformatOutputFormat for which to retrieve supported MIME types.
out string []resultsArray that will contain the supported MIME type names.

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult GetSupportedOutputFormats

Get a list of all the supported Media Muxer Output Formats.

public MLResult GetSupportedOutputFormats(
out OutputFormat [] results
)

Parameters

TypeNameDescription
out OutputFormat []resultsArray of OutputFormat that will contain the supported formats.

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


Muxer

public Muxer()

MLResult SetLocation

Set and store the geodata (latitude and longitude) in the output file. This should be called before Start and after Configure. The geodata is stored in udta box if the output format is OutputFormat.MPEG4, and is ignored for other output formats. The geodata is stored according to ISO-6709 standard.

public MLResult SetLocation(
float latitude,
float longitude
)

Parameters

TypeNameDescription
floatlatitudeThe latitude in degrees. Its value must be in the range [-90, 90].
floatlongitudeThe longitude in degrees. Its value must be in the range [-180, 180].

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult SetOrientationHint

Set the orientation hint for output video playback. This should be called before Start and after Configure Calling this method will not rotate the video frame when muxer is generating the file, but add a composition matrix containing the rotation angle in the output video if the output format is OutputFormat.MPEG4 so that a video player can choose the proper orientation for playback. Note that some video players may choose to ignore the composition matrix in a video during playback. By default, the rotation degree is 0.

public MLResult SetOrientationHint(
int degrees
)

Parameters

TypeNameDescription
intdegreesThe rotation angle. Must be 0, 90, 180 or 270.

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult Start

Start muxing. Make sure all the tracks have been added (AddAudioTrack or AddVideoTrack) before calling this. If the Muxer has already been Stopped , it cannot be re- Started .

public MLResult Start()

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult Stop

Stop muxing. Once the muxer Stops , it can not be re- Started .

public MLResult Stop()

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


MLResult WriteSampleData

Writes an encoded sample into the muxer. The application needs to make sure that the samples are written into the right tracks. Also, it needs to make sure the samples for each track are written in chronological order (e.g. in the order they are provided by the encoder.)

public MLResult WriteSampleData(
int trackIndex,
byte [] data,
long time,
CodecBufferFlags flags
)

Parameters

TypeNameDescription
inttrackIndexThe track index number to write the sample data into. This should be one of the number returned by AddAudioTrack and AddVideoTrack
byte []dataBuffer of data to write to the muxer
longtimeTimestamp in microseconds
CodecBufferFlagsflagsMLMediaCodecBufferFlag . Supported values: KeyFrame , EOS , and MuxerData

Returns: MLResult with Code "Ok" if the operation completed successfully without errors. Check MLResult.IsOk for status.


Public Enums

CodecBufferFlags

Indicate the type of data when queuing the input buffer of muxer sample data

EnumeratorValueDescription
KeyFrame1The (encoded) buffer contains the data for a key frame.
EOS4Signals the end of stream, i.e. no buffers will be available after this.
MuxerData16Buffer contains muxer data - Supported only for Exif data block.

OutputFormat

Output formats for MediaMuxer. Use Muxer.GetSupportedOutputFormats(out OutputFormat[]) to query for all supported output formats for the Muxer.

EnumeratorValueDescription
MPEG40MP4 format
WEBM1VP8/VORBIS data in a WEBM container
ThreeGPP23gpp format
HEIF3HEIC data in a HEIF container
OGG4Opus audio data in an OGG container