Table of Contents

Recording EIF files in Unity

This article explains how to record EIF files in Unity for simulation purposes.

Before you begin

Start recording

Use FrameRecorder.enabled = true to start recording, for example:

if (Session.State >= ARSession.SessionState.Ready && Session.Assembly.FrameRecorder.OnSome)
{
    var frameRecorder = Session.Assembly.FrameRecorder.Value;
    frameRecorder.enabled = true;
}

Note that you need to check whether ARAssembly.FrameRecorder exists first.

Note

ARAssembly.FrameRecorder cannot be used in some cases, such as when using FramePlayer.

FrameRecorder.enabled defaults to false, which means recording is off, and manual configuration in the editor is also invalid.

Recording will start only when the session is running and FrameRecorder.Status >= FrameRecorder.RecorderStatus.Ready.

If FrameRecorder.Status < FrameRecorder.RecorderStatus.Ready, you can use the OnReady event to wait for the recording to be ready.

Session.GetComponent<FrameRecorder>().OnReady.AddListener(() => {
    // Can start recording
});

You can use the OnRecording event to confirm a successful start:

frameRecorder.OnRecording.AddListener((file) =>
{
    Debug.Log($"Recording started: {file}");
});

There is no event triggered for a failed start, but you can check whether FrameRecorder.Status is Error to confirm.

Important

The runtime effect when playing EIF in the scene is related to the device used for recording and the frame source selected on the device at that time. Therefore, when recording EIF files, it is recommended to use the same or similar device as the target device to ensure that the playback effect is consistent with the effect on the target device. At the same time, pay special attention to whether the motion tracking function is enabled in the recording scene. If the motion tracking function is not enabled during recording, it cannot be enabled during playback, and AR functions that rely on motion tracking (such as dense spatial mapping, Mega, etc.) cannot work consistently with the device.

Stop recording

Use FrameRecorder.enabled = false to stop recording, for example:

frameRecorder.enabled = false;

This operation will immediately stop recording and block until the file writing is completed.

Important

You must call stop recording, otherwise the recording file will be incomplete, which may cause partial functionality or the entire file to be unusable:

  • When the recording format is H264, the EIF file cannot seek to a specified time point for playback (seek), and can only be played from the beginning
  • When the recording format is Obsolete, the EIF file cannot be used

File storage and export

You can use the OnRecording event to get the full real path of the recorded file:

frameRecorder.OnRecording.AddListener((file) =>
{
    Debug.Log($"Recording started: {file}");
});

By default, the recorded file is stored in the application's persistent data path, which can be accessed via Application.persistentDataPath.

You can modify the storage path of the recorded file via FrameRecorder.Configuration.FilePath. This path must be set before starting the recording, and AutoFilePath must be turned off for it to take effect. The directory must be created in advance.

Important

You must ensure that the storage directory of the recorded file exists and is writable by the application, otherwise the recording will fail to start.

For example, the following code shows how to store the recorded file in a custom directory and generate a file name based on the FrameSource type used by the session and the current time:

if (!Directory.Exists(SavePath))
{
    Directory.CreateDirectory(SavePath);
}
var frameRecorder = Session.Assembly.FrameRecorder.Value;
frameRecorder.Configuration.AutoFilePath = false;
frameRecorder.Configuration.FilePath.Type = WritablePathType.Absolute;
frameRecorder.Configuration.FilePath.FolderPath = SavePath;
frameRecorder.Configuration.FilePath.FileName = ARSessionFactory.DefaultName(Session.Assembly.FrameSource.GetType()).Replace(" ", "") + DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss.fff");

frameRecorder.enabled = true;

You can also configure it in the editor by selecting AR Session (EasyAR) and unchecking Auto File Path in the Inspector window:

alt text

Tip

You can modify the storage directory and file name (without extension) of the file via FrameRecorder.RecordingConfiguration.FilePath. The file extension will be automatically added based on the recording format.

  • When the recording format is H264, the file extension is .mkveif
  • When the recording format is Obsolete, the file extension is .eif

If the file is stored in the application's persistent data path or other private paths of the application, you can export the file to your computer in the following ways:

  • On Android, you can connect the device to your computer via USB and use adb pull or other methods to export the file to your computer. The file is usually located under /sdcarad/Android/data/<app package name>/files.
  • On iOS, you can export the file to your computer via the Devices window in Xcode, or access the application's private directory via iTunes or Finder file sharing.
  • Use code to store the file in a public directory, such as the download directory on Android or the photo album on iOS.
Note

For iOS applications, if you want to access the application's private directory via iTunes or Finder file sharing, you need to add the UIFileSharingEnabled key to the Info.plist of the Xcode project before packaging and set its value to YES:

alt text

The displayed text after adding it may differ from the added string, which is normal.

Change recording format

Change the recording format through FrameRecorder.Configuration.Format, which must be set before starting recording.

For example, the following code shows how to force the recording format to H264:

frameRecorder.Configuration.Format = FrameRecorder.InternalFormat.H264;

You can also modify the Format in the Inspector window by selecting AR Session (EasyAR) in the editor:

alt text

Note

H264 is not available on some devices (such as Windows). It is generally recommended to use Auto, which will automatically select the appropriate format based on the device.

Note

On XREAL, data recorded in Obsolete format cannot be used for simulation and is only for feedback purposes.

  • For simulation, use data recorded in H264 format.
  • For feedback, use data recorded in Obsolete format.

You can use RecordingFormat to check the current recording format.

Auto start recording when the session starts

Set AutoStart to true before the session starts to enable recording when the session begins, for example:

frameRecorder.AutoStart = true;  

Alternatively, in the editor, select AR Session (EasyAR), and in the Inspector window, check the Auto Start option for Frame Recorder:

alt text

Note

Modifying FrameRecorder.enabled in the editor is ineffective.

Data available for Mega

When using Mega, there are some special requirements for the content of EIF and related files. Older versions of the Unity plugin did not integrate these features, so data recorded with those versions cannot be used for Mega.

The following types of recorded data can be used for Mega:

  • Data recorded using Unity plugin version 4000 or higher
  • Data recorded using the Mega Toolbox
  • If the data was recorded in the Obsolete format, such as the file x.eif, a x.eif.json file must also exist in the same directory to be usable

The following types of recorded data cannot be used for Mega:

  • Data recorded using Unity plugin version 4.6 or lower
  • Data recorded using native EasyAR Sense without adding the same content as in the Unity plugin

Additionally, although Mega can work without motion tracking, the performance will differ. It is recommended to enable motion tracking when recording EIF files to ensure the playback effect meets most usage scenarios.

Next steps