Google is committed to advancing racial equity for Black communities. See how.

Record and play back an AR session on Unity targeting Android

The Recording & Playback API enables you to record video and AR data once within a given environment and use that content to replace a live camera session.

Prerequisites

Make sure that you understand fundamental AR concepts and how to configure an ARCore session before proceeding.

Compatibility with other ARCore APIs

Due to the way session data is processed, ARCore APIs may produce different results during playback than observed during recording. They may also produce different results during subsequent playback sessions. For example, the number of detected trackables, the precise timing of their detection, and their poses over time may be different during playback.

Compatibility with Cloud Anchors

You can host and resolve Cloud Anchors while recording or playing back a session.

Recording

Start, stop, and check the status of an ARCore session recording.

Record an ARCore session

To record an entire ARCore session, call Session.StartRecording(). This method will fail if a recording is already in progress. Recording may continue even if the session is paused. If this happens, ARCore will continue to capture sensor data, while recording the camera feed as a black screen.

ARCoreRecordingConfig config = new ARCoreRecordingConfig();
config.Mp4DatasetFilepath = "path/to/file.mp4";

Session.StartRecording(config);

Stop a recording

To stop recording, call Session.StopRecording().

Session.StopRecording();

Check recording status

ARRecordingManager.RecordingStatus can be used at any time to determine the current RecordingStatus.

Debug.Log("Current Recording Status: " + Session.RecordingStatus);

Playback

Play back previously recorded AR sessions. Sessions play back in real time, and session playback or speed cannot be adjusted.

Play back a previously recorded session

To play back a previously recorded session, call Session.SetPlaybackDataset() and provide a file path for the dataset you wish to play back. You must pause the session to use this method. Resume the session for the change to take effect.

Once playback has started, pausing the session by by disabling the ARCoreSession will suspend processing of all camera image frames and any other recorded sensor data in the dataset. Camera image frames and sensor frame data that is discarded in this way will not be reprocessed when the session is again resumed by re-enabling the ARCoreSession. AR tracking for the session will generally suffer due to the gap in processed data.

// Pause the current session when providing the path.
session.enabled = false;

// In the next frame, provide a filepath for the dataset you wish to play back.
session.SetPlaybackDataset("path/to/file.mp4");

// In the frame after that, resume the session.
session.enabled = true;

Restart playback from the beginning

To restart a playback from the beginning of the dataset, pause the session and call Session.SetPlaybackDataset(), specifying the same MP4 recording before resuming the session.

// Pause the current session when re-setting the path.
session.enabled = false;

// In the next frame, specify the same dataset.
session.SetPlaybackDataset(filepath); // filepath is the same path you used before

// In the frame after that, resume playback from the beginning of the dataset.
session.enabled = true;

Play back a different session

To play back a different dataset, call Session.SetPlaybackDataset() and specify a new dataset before resuming the session.

// Pause the current session when re-setting the path.
session.enabled = false;

// In the next frame, specify a new dataset.
session.SetPlaybackDataset(newFilepath); // newFilepath is a different path than the one you used before

// In the frame after that, resume playback from the beginning of the new dataset.
session.enabled = true;

Check playback status

ARPlaybackManager.PlaybackStatus can be used at any time to determine the current playback status.

Debug.Log("Current Playback Status: " + session.PlaybackStatus);

What’s next