Android Guides | Samples

Android.Media.MediaMuxer Class

MediaMuxer facilitates muxing elementary streams.

See Also: MediaMuxer

Syntax

[Android.Runtime.Register("android/media/MediaMuxer", DoNotGenerateAcw=true)]
public sealed class MediaMuxer : Object

Remarks

MediaMuxer facilitates muxing elementary streams. Currently only supports an mp4 file as the output and at most one audio and/or one video elementary stream.

It is generally used like this:

java Example

 MediaMuxer muxer = new MediaMuxer("temp.mp4", OutputFormat.MUXER_OUTPUT_MPEG_4);
 // More often, the MediaFormat will be retrieved from MediaCodec.getOutputFormat()
 // or MediaExtractor.getTrackFormat().
 MediaFormat audioFormat = new MediaFormat(...);
 MediaFormat videoFormat = new MediaFormat(...);
 int audioTrackIndex = muxer.addTrack(audioFormat);
 int videoTrackIndex = muxer.addTrack(videoFormat);
 ByteBuffer inputBuffer = ByteBuffer.allocate(bufferSize);
 boolean finished = false;
 BufferInfo bufferInfo = new BufferInfo();

 muxer.start();
 while(!finished) {
   // getInputBuffer() will fill the inputBuffer with one frame of encoded
   // sample from either MediaCodec or MediaExtractor, set isAudioSample to
   // true when the sample is audio data, set up all the fields of bufferInfo,
   // and return true if there are no more samples.
   finished = getInputBuffer(inputBuffer, isAudioSample, bufferInfo);
   if (!finished) {
     int currentTrackIndex = isAudioSample ? audioTrackIndex : videoTrackIndex;
     muxer.writeSampleData(currentTrackIndex, inputBuffer, bufferInfo);
   }
 };
 muxer.stop();
 muxer.release();

[Android Documentation]

Requirements

Namespace: Android.Media
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 18

The members of Android.Media.MediaMuxer are listed below.

See Also: Object

Public Constructors

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

AddTrack(MediaFormat) : Int32
Adds a track with the specified format.
Release()
Make sure you call this when you're done to free up any resources instead of relying on the garbage collector to do this for you at some point in the future.
SetLocation(Single, Single)
Set and store the geodata (latitude and longitude) in the output file.
SetOrientationHint(Int32)
Sets the orientation hint for output video playback.
Start()
Starts the muxer.
Stop()
Stops the muxer.
WriteSampleData(Int32, ByteBuffer, MediaCodec+BufferInfo)
Writes an encoded sample into the muxer.