Skip to main content
Version: 21 Aug 2024

MLMediaRecorder

NameSpace: MagicLeap

APIs for video and audio recording. More...

Detailed Description

public class MLMediaRecorder; 

Details*

MLMediaRecorder description goes here.


Public Fields

Handle

Handle to the underlying media recorder object.


public ulong Handle { get; set; }


InputSurface

Native surface object which should be used to get the native buffers to render the video frames onto for recorded.


public MLNativeSurface InputSurface = MagicLeapNativeBindings.InvalidHandle { get; set; }


Public Methods

MLMediaRecorder Create

Create a media recorder object

public static MLMediaRecorder Create()

Returns: Media recorder object if construction was successful, null otherwise


MLResult GetInputSurface

Gets the input surface to record from when using SURFACE video source. May only be called after MLMediaRecorderPrepare and MLMediaRecorderStart. Frames rendered to the producer before MLMediaRecorderStart() is called will be discarded. When using an input surface, there are no accessible input buffers, as buffers are automatically passed from the other modules to this surface. The returned input surface can also be passed as a destination surface to - a video/mixed reality video capture session when calling MLCameraPrepareCapture(). Captured raw video frames will be consumed directly as input to an encoder without copying. Caller of this API should release the surface using #MLMediaRecorderReleaseInputSurface() on the Surface handle after usage.

public MLResult GetInputSurface()

MLResult GetMaxAmplitude

Returns the maximum absolute amplitude that was sampled since the last call to this method. Call this only after the MLMediaRecorder.SetAudioSource().

public MLResult GetMaxAmplitude(
out int maxAmp
)

Parameters

TypeNameDescription
out intmaxAmp

delegate void OnErrorDelegate

public delegate void OnErrorDelegate(
OnErrorData trackInfo
)

Parameters

TypeNameDescription
OnErrorDatatrackInfoInfo received when the media recorder runs into an error.

delegate void OnInfoDelegate

public delegate void OnInfoDelegate(
OnInfoData info
)

Parameters

TypeNameDescription
OnInfoDatainfo

delegate void OnTrackErrorDelegate

public delegate void OnTrackErrorDelegate(
OnTrackErrorData trackInfo
)

Parameters

TypeNameDescription
OnTrackErrorDatatrackInfoInfo received when the media recorder runs into a track error.

delegate void OnTrackInfoDelegate

public delegate void OnTrackInfoDelegate(
OnTrackInfoData info
)

Parameters

TypeNameDescription
OnTrackInfoDatainfo

MLResult Prepare

Prepares the recorder to begin capturing and encoding data for input mediaformat. Should be called after setting up the desired audio and video sources, encoders, but before MLMediaRecorder.Start().

public MLResult Prepare(
MLMediaFormat format
)

Parameters

TypeNameDescription
MLMediaFormatformatMedia format object to configure the video & audio track.

MLResult Reset

Restarts the MediaRecorder to its idle state. After calling this method, you will have to configure it again as if it had just been constructed.

public MLResult Reset()

MLResult SetAudioEncoder

Sets the audio encoder to be used for recording. If this method is not called, the output file will not contain an audio track. Call this after MLMediaRecorder.SetOutputFormat() and before MLMediaRecorder.Prepare().

public MLResult SetAudioEncoder(
AudioEncoder inAudioEncoder
)

Parameters

TypeNameDescription
AudioEncoderinAudioEncoderAvailable audio encoder formats

MLResult SetAudioSource

Set MediaRecorder audio source. Cannot be called twice without calling MLMediaRecorder.Reset() in between.

public MLResult SetAudioSource(
AudioSource inAudioSource
)

Parameters

TypeNameDescription
AudioSourceinAudioSourceAudio source to put in the recorded media.

MLResult SetGeoLocation

Sets the GEO location for recording.

public MLResult SetGeoLocation(
long inLatitude10000,
long inLongitude10000
)

Parameters

TypeNameDescription
longinLatitude10000the 10000 multiplies latitude of location.
longinLongitude10000the 10000 multiplies longitude of location.

MLResult SetMaxDuration

Sets the maximum duration (in ms) of the recording session. Call this after MLMediaRecorder.SetOutputFormat() and before MLMediaRecorder.Prepare(). After recording reaches the specified duration, a notification will be sent via the callback with a MLMediaRecorder.Info code of MLMediaRecorder.Info.MaxDurationReached and recording will be stopped. Stopping happens asynchronously, there is no guarantee that the recorder will have stopped by the time the listener is notified.

public MLResult SetMaxDuration(
int inMaxDurationMsec
)

Parameters

TypeNameDescription
intinMaxDurationMsec

MLResult SetMaxFileSize

Sets the maximum file size (in bytes) of the recording session. Call this after MLMediaRecorder.SetOutputFormat() and before MLMediaRecorder.Prepare(). After recording reaches the specified filesize, a notification will be sent via the callback with a MLMediaRecorder.Info code of MLMediaRecorder.Info.MaxFileSizeReached and recording will be stopped. happens asynchronously, there is no guarantee that the recorder will have stopped by the time the listener is notified.

public MLResult SetMaxFileSize(
long inMaxFileSize
)

Parameters

TypeNameDescription
longinMaxFileSize

MLResult SetOutputFileForFD

Pass in the unmanaged file descriptor of the file to be written. Call this after MLMediaRecorder.SetOutputFormat() but before MLMediaRecorder.Prepare().

public MLResult SetOutputFileForFD(
int fd
)

Parameters

TypeNameDescription
intfdUnmanaged file descriptor of the output file.

MLResult SetOutputFileForPath

Sets the path of the output file to be produced. Call this after MLMediaRecorder.SetOutputFormat() but before MLMediaRecorder.Prepare().

public MLResult SetOutputFileForPath(
string path
)

Parameters

TypeNameDescription
stringpathPath to output file. Folders should exist already.

MLResult SetOutputFormat

Sets the format of the output file produced during recording.

public MLResult SetOutputFormat(
OutputFormat inFormat
)

Parameters

TypeNameDescription
OutputFormatinFormatPossible output formats

MLResult SetVideoEncoder

Sets the video encoder to be used for recording. If this method is not called, the output file will not contain a video track. Call this after MLMediaRecorder.SetOutputFormat() and before MLMediaRecorder.Prepare(). The video source is always set to camera by default.

public MLResult SetVideoEncoder(
VideoEncoder inVideoEncoder
)

Parameters

TypeNameDescription
VideoEncoderinVideoEncoderAvailable video encoder formats

MLResult SetVideoSource

Sets MediaRecorder video source. Cannot be called twice without calling MLMediaRecorder.Reset() in between.

public MLResult SetVideoSource(
VideoSource inVideoSource
)

Parameters

TypeNameDescription
VideoSourceinVideoSourceVideo source to put in the recorded media.

MLResult Start

Begins capturing and encoding data to the specified file. Call this after MLMediaRecorder.Prepare(). The apps should not start another recording session during recording.

public MLResult Start()

MLResult Stop

Stops recording. Call this after MLMediaRecorder.Start(). Once recording is stopped, you will have to configure it again as if it has just been constructed.

public MLResult Stop()

Public Events

OnError

MediaRecorder received a general error message.

public OnErrorDelegate OnError()

OnInfo

MediaRecorder received a general info/warning message.

public OnInfoDelegate OnInfo()

OnTrackError

MediaRecorder received a track-related error message.

public OnTrackErrorDelegate OnTrackError()

OnTrackInfo

MediaRecorder received a track-related info/warning message.

public OnTrackInfoDelegate OnTrackInfo()

Public Enums

AudioEncoder

Available audio encoder formats

EnumeratorValueDescription
Default0
AMR_NBAMR NB.
AMR_WBAMR WB.
AACAAC.
HE_AACHE AAC.
AAC_ELDAAC ELD.
VORBISVorbis.
OPUSOpus.

AudioSource

Audio source to put in the recorded media.

EnumeratorValueDescription
Voice0Recording voice.
WorldRecording ambient sounds.
VirtualRecording digital sounds.
MixedMixed reality mode: digital + ambient.

Error

Video recorder error types

EnumeratorValueDescription
Unknown1
ServerDied2
TrackGeneral100
VideoNoSyncFrame200

Event

Media recorder events

EnumeratorValueDescription
Error1Media recorder error.
Info2Media recorder info.
TrackError100Media recorder track error.
TrackInfo101Media recorder track info.

Info

EnumeratorValueDescription
Unknown1
MaxDurationReached800Max duration of the clip is reached.
MaxFileSizeReached801Max file size is reached.
MaxFileSizeApproaching802Max file size is approaching.
TrackCompletionStatus1000Next output file has started.
TrackProgressInTime1001The info about progress in time.
TrackType1002track info.
TrackDurationMs1003The info about track duration.
TrackMaxChunkDurationMs1004The time to measure the max chunk duration.
TrackEncodedFrames1005The info about encoded frames.
TrackInterChunkTimeUs1006The time to measure how well the audio and video track data interleaved.
TrackInitialDelayMs1007The time to measure system response.
TrackStartOffsetMs1008The time used to compensate for initial A/V sync.
TrackDataKBytes1009Total number of bytes of the media data.

OutputFormat

Possible output formats

EnumeratorValueDescription
Default0
THREE_GPP3gpp format.
MPEG_4MP4 format.
AMR_NBAMR NB.
AMR_WBAMR WB.
AAC_ADIFAAC_ADIF.
AAC_ADTSAAC_ADTS.
RTP_AVPStream over a socket, limited to a single stream.
MPEG2TSH.264/AAC data encapsulated in MPEG2/TS.
WEBMVP8/VORBIS data in a WEBM container.
HEIFHEIC data in a HEIF container.
OGGOpus data in a OGG container.

VideoEncoder

Available video encoder formats

EnumeratorValueDescription
Default0
H263H263. This format has support for software encoder.
H264H264. This format has support for hardware encoder.
MPEG_4_SPMPEG4 SP. This format has support for software encoder.
VP8VP8. This format has support for software encoder.
HEVCHEVC. This format has support for hardware encoder.

VideoSource

Video source to put in the recorded media.

EnumeratorValueDescription
Camera1Camera video source.