Android에서 AR 세션 녹화 및 재생하기

Recording & Playback API를 사용하면 지정된 환경 내에서 동영상 및 AR 데이터를 한 번 녹화하고 이 콘텐츠를 사용하여 라이브 카메라 세션을 대체할 수 있습니다.

기본 요건

계속 진행하기 전에 기본 AR 개념ARCore 세션 구성 방법을 이해해야 합니다.

다른 ARCore API와의 호환성

세션 데이터가 처리되는 방식으로 인해 ARCore API는 재생 중에 녹화 중에 관찰된 것과 다른 결과를 생성할 수 있습니다. 후속 재생 세션 중에 다른 결과를 생성할 수도 있습니다. 예를 들어 감지된 추적 가능 기기의 수, 정확한 감지 시점, 시간 경과에 따른 포즈는 재생 중에 다를 수 있습니다.

공유 카메라와의 호환성

공유 카메라를 사용하는 세션은 녹화될 수 있습니다. 하지만 공유 카메라 모드로는 현재 해당 세션을 재생할 수 없습니다.

클라우드 앵커와의 호환성

세션을 녹화하거나 재생하는 동안 클라우드 앵커를 호스팅하고 확인할 수 있습니다.

녹화

ARCore 세션 녹화를 시작, 중지, 상태를 확인합니다.

ARCore 세션 기록

ARCore 세션을 녹화하려면 세션을 구성하고 녹화에 사용할 MP4 URI를 제공합니다. session.resume()를 처음 호출하기 전에 session.startRecording()를 호출합니다. 세션이 재개되면 녹화가 자동으로 시작됩니다. 세션이 일시중지될 때 녹화를 자동으로 중지하려면 RecordingConfig.setAutoStopOnPause()를 호출합니다. 부분 세션을 녹화하려면 세션이 실행되는 동안 session.startRecording()를 호출합니다.

Java

// Configure the ARCore session.
Session session = new Session(context);
Uri destination = Uri.fromFile(new File(context.getFilesDir(), "recording.mp4"));
RecordingConfig recordingConfig =
        new RecordingConfig(session)
        .setMp4DatasetUri(destination)
        .setAutoStopOnPause(true);
try {
  // Prepare the session for recording, but do not start recording yet.
  session.startRecording(recordingConfig);
} catch (RecordingFailedException e) {
  Log.e(TAG, "Failed to start recording", e);
}

// Resume the ARCore session to start recording.
session.resume();

Kotlin

// Configure the ARCore session.
val session = Session(context)
val destination = Uri.fromFile(File(context.getFilesDir(), "recording.mp4"))
val recordingConfig = RecordingConfig(session)
  .setMp4DatasetUri(destination)
  .setAutoStopOnPause(true)
session.startRecording(recordingConfig)

// Resume the ARCore session to start recording.
session.resume()

세션 녹음 중지

현재 실행 중인 AR 세션을 일시중지하지 않고 녹화를 중지하려면 session.stopRecording()를 호출합니다.

Java

try {
  session.stopRecording();  // Stop recording.
} catch (RecordingFailedException e) {
  Log.e(TAG, "Failed to stop recording", e);
}

Kotlin

session.stopRecording()

녹화 상태 확인

session.getRecordingStatus()를 언제든지 사용하여 현재 RecordingStatus를 확인할 수 있습니다.

Java

// Use any time to determine current RecordingStatus.
if (session.getRecordingStatus() == RecordingStatus.OK) {
  // Update the UI to show that the session is currently being recorded.
}

Kotlin

// Use any time to determine current RecordingStatus.
if (session.recordingStatus == RecordingStatus.OK) {
  // Update the UI to show that the session is currently being recorded.
}

재생

이전에 녹화된 AR 세션 재생 세션은 실시간으로 재생되며 세션 재생 또는 속도는 조정할 수 없습니다.

이전에 녹화된 세션 재생

이전에 녹화된 세션을 재생하려면 첫 번째 session.resume() 호출 전에 session.setPlaybackDatasetUri()를 호출합니다.

첫 번째 session.resume() 호출로 인해 재생이 시작된 후 session.pause()를 호출하여 세션을 일시중지하면 모든 카메라 이미지 프레임 및 데이터 세트에 기록된 기타 센서 데이터의 처리가 정지됩니다. 이러한 방식으로 삭제되는 카메라 이미지 프레임과 센서 프레임 데이터는 session.resume()를 호출하여 세션이 다시 재개될 때 재처리되지 않습니다. 일반적으로 세션의 AR 추적은 처리된 데이터의 차이로 인해 문제가 발생합니다.

Java

// Configure the ARCore session.
Session session = new Session(context);

// Specify the previously recorded MP4 file.
Uri recordingUri = Uri.fromFile(new File(context.getFilesDir(), "recording.mp4"));
session.setPlaybackDatasetUri(recordingUri);
…

// Start playback from the beginning of the dataset.
session.resume();
…

// Pause the AR session, but silently continue MP4 playback. Camera frames
// and other recorded sensor data is discarded while the session is paused.
session.pause();
…

// Resume the AR session. Camera frames and other sensor data from the MP4
// that was silently played back while the session was paused is not
// processed by ARCore.
session.resume();

Kotlin

// Configure the ARCore session.
val session = Session(context)

// Specify the previously recorded MP4 file.
val recordingUri = Uri.fromFile(File(context.filesDir, "recording.mp4"))
session.playbackDatasetUri = recordingUri
…

// Start playback from the beginning of the dataset.
session.resume()
…

// Pause the AR session, but silently continue MP4 playback. Camera frames
// and other recorded sensor data is discarded while the session is paused.
session.pause()
…

// Resume the AR session. Camera frames and other sensor data from the MP4
// that was silently played back while the session was paused is not
// processed by ARCore.
session.resume()

처음부터 재생 다시 시작

데이터 세트의 시작 부분부터 재생을 다시 시작하려면 세션을 일시중지하고 session.setPlaybackDatasetUri()를 호출하여 세션을 재개하기 전에 동일한 MP4 녹화를 지정합니다.

Java

session.pause();
// Pause and specify the SAME dataset:
session.setPlaybackDatasetUri(previousRecordingUri);
session.resume();  // Playback starts from the BEGINNING of the dataset.

Kotlin

session.pause()
// Pause and specify the SAME dataset:
session.playbackDatasetUri = previousRecordingUri
session.resume()  // Playback starts from the BEGINNING of the dataset.

다른 세션 재생

다른 데이터 세트를 재생하려면 세션을 재개하기 전에 세션을 일시 중지하고 새 데이터 세트를 지정합니다.

Java

// Switch to a different dataset.
session.pause();   // Pause the playback of the first dataset.
// Specify a different dataset to use.
session.setPlaybackDatasetUri(newRecordingUri);
session.resume();  // Start playback from the beginning of the new dataset.

Kotlin

// Switch to a different dataset.
session.pause()   // Pause the playback of the first dataset.
// Specify a different dataset to use.
session.playbackDatasetUri = newRecordingUri
session.resume()  // Start playback from the beginning of the new dataset.

재생 상태 확인

언제든지 session.getPlaybackStatus()를 사용하여 현재 PlaybackStatus를 확인합니다.

Java

// Use any time to determine current PlaybackStatus.
if (session.getPlaybackStatus() != PlaybackStatus.OK) {
  // Update the UI to show that the session playback has finished.
}

Kotlin

// Use any time to determine current PlaybackStatus.
if (session.playbackStatus != PlaybackStatus.OK) {
  // Update the UI to show that the session playback has finished.
}

다음 단계