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
Type | Name | Description |
---|---|---|
out int | maxAmp |
delegate void OnErrorDelegate
public delegate void OnErrorDelegate(
OnErrorData trackInfo
)
Parameters
Type | Name | Description |
---|---|---|
OnErrorData | trackInfo | Info received when the media recorder runs into an error. |
delegate void OnInfoDelegate
public delegate void OnInfoDelegate(
OnInfoData info
)
Parameters
Type | Name | Description |
---|---|---|
OnInfoData | info |
delegate void OnTrackErrorDelegate
public delegate void OnTrackErrorDelegate(
OnTrackErrorData trackInfo
)
Parameters
Type | Name | Description |
---|---|---|
OnTrackErrorData | trackInfo | Info received when the media recorder runs into a track error. |
delegate void OnTrackInfoDelegate
public delegate void OnTrackInfoDelegate(
OnTrackInfoData info
)
Parameters
Type | Name | Description |
---|---|---|
OnTrackInfoData | info |
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
Type | Name | Description |
---|---|---|
MLMediaFormat | format | Media 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
Type | Name | Description |
---|---|---|
AudioEncoder | inAudioEncoder | Available 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
Type | Name | Description |
---|---|---|
AudioSource | inAudioSource | Audio source to put in the recorded media. |
MLResult SetGeoLocation
Sets the GEO location for recording.
public MLResult SetGeoLocation(
long inLatitude10000,
long inLongitude10000
)
Parameters
Type | Name | Description |
---|---|---|
long | inLatitude10000 | the 10000 multiplies latitude of location. |
long | inLongitude10000 | the 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
Type | Name | Description |
---|---|---|
int | inMaxDurationMsec |
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
Type | Name | Description |
---|---|---|
long | inMaxFileSize |
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
Type | Name | Description |
---|---|---|
int | fd | Unmanaged 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
Type | Name | Description |
---|---|---|
string | path | Path 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
Type | Name | Description |
---|---|---|
OutputFormat | inFormat | Possible 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
Type | Name | Description |
---|---|---|
VideoEncoder | inVideoEncoder | Available 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
Type | Name | Description |
---|---|---|
VideoSource | inVideoSource | Video 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
Enumerator | Value | Description |
---|---|---|
Default | 0 | |
AMR_NB | AMR NB. | |
AMR_WB | AMR WB. | |
AAC | AAC. | |
HE_AAC | HE AAC. | |
AAC_ELD | AAC ELD. | |
VORBIS | Vorbis. | |
OPUS | Opus. |
AudioSource
Audio source to put in the recorded media.
Enumerator | Value | Description |
---|---|---|
Voice | 0 | Recording voice. |
World | Recording ambient sounds. | |
Virtual | Recording digital sounds. | |
Mixed | Mixed reality mode: digital + ambient. |
Error
Video recorder error types
Enumerator | Value | Description |
---|---|---|
Unknown | 1 | |
ServerDied | 2 | |
TrackGeneral | 100 | |
VideoNoSyncFrame | 200 |
Event
Media recorder events
Enumerator | Value | Description |
---|---|---|
Error | 1 | Media recorder error. |
Info | 2 | Media recorder info. |
TrackError | 100 | Media recorder track error. |
TrackInfo | 101 | Media recorder track info. |
Info
Enumerator | Value | Description |
---|---|---|
Unknown | 1 | |
MaxDurationReached | 800 | Max duration of the clip is reached. |
MaxFileSizeReached | 801 | Max file size is reached. |
MaxFileSizeApproaching | 802 | Max file size is approaching. |
TrackCompletionStatus | 1000 | Next output file has started. |
TrackProgressInTime | 1001 | The info about progress in time. |
TrackType | 1002 | track info. |
TrackDurationMs | 1003 | The info about track duration. |
TrackMaxChunkDurationMs | 1004 | The time to measure the max chunk duration. |
TrackEncodedFrames | 1005 | The info about encoded frames. |
TrackInterChunkTimeUs | 1006 | The time to measure how well the audio and video track data interleaved. |
TrackInitialDelayMs | 1007 | The time to measure system response. |
TrackStartOffsetMs | 1008 | The time used to compensate for initial A/V sync. |
TrackDataKBytes | 1009 | Total number of bytes of the media data. |
OutputFormat
Possible output formats
Enumerator | Value | Description |
---|---|---|
Default | 0 | |
THREE_GPP | 3gpp format. | |
MPEG_4 | MP4 format. | |
AMR_NB | AMR NB. | |
AMR_WB | AMR WB. | |
AAC_ADIF | AAC_ADIF. | |
AAC_ADTS | AAC_ADTS. | |
RTP_AVP | Stream over a socket, limited to a single stream. | |
MPEG2TS | H.264/AAC data encapsulated in MPEG2/TS. | |
WEBM | VP8/VORBIS data in a WEBM container. | |
HEIF | HEIC data in a HEIF container. | |
OGG | Opus data in a OGG container. |
VideoEncoder
Available video encoder formats
Enumerator | Value | Description |
---|---|---|
Default | 0 | |
H263 | H263. This format has support for software encoder. | |
H264 | H264. This format has support for hardware encoder. | |
MPEG_4_SP | MPEG4 SP. This format has support for software encoder. | |
VP8 | VP8. This format has support for software encoder. | |
HEVC | HEVC. This format has support for hardware encoder. |
VideoSource
Video source to put in the recorded media.
Enumerator | Value | Description |
---|---|---|
Camera | 1 | Camera video source. |