Video recording of Sceneform SceneViews

This developer guide takes you through the steps to enable your app to record Sceneform SceneViews to a local video file. It uses functionality available in the VideoRecorder class, which is available as part of the VideoRecording Sample sample starting with version 1.6.0 of the Sceneform SDK for Android.

Build and run the sample app

To build and run the VideoRecording Sample app:

  1. Make sure you have a Sceneform project in Android Studio, and that your Android device is connected to the development machine via USB. See the quickstart for detailed steps.
  2. Import the VideoRecording Sample into your project.
  3. In Android Studio, click Run . Then, choose your device as the deployment target and click OK to launch the sample app on your device.
  4. As you move your device and place 3D objects in the space around you, click the Record button to begin recording, and the Stop button to stop recording.

The recorded video will be accessible via the camera roll on the device, in a photo album named Sceneform or at the path:

/sdcard/Pictures/Sceneform/Sample<hex characters>.mp4

Overview of enabling an app to support Sceneform video recording

Enabling your app to record Sceneform scenes requires:

  1. Requesting app permissions
  2. Initializing the video recorder
  3. Starting and stopping video recording

1. Request app permissions

In order to be able to write the video file to local storage, you app must request the WRITE_EXTERNAL_STORAGE permission by adding the following line to your AndroidManifest.xml:

<application>
  …
</application>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

2. Initialize the video recorder

The VideoRecording Sample includes a class named VideoRecorder, which encapsulates all the settings logic needed to use the MediaRecorder to capture frames from a SceneView object to create a video.

To use the video recorder, initialize the VideoRecorder class in your activity, for example in onCreate().

// Create a new video recorder instance.
videoRecorder = new VideoRecorder();

// Specify the AR scene view to be recorded.
videoRecorder.setSceneView(arFragment.getArSceneView());

// Set video quality and recording orientation to match that of the device.
int orientation = getResources().getConfiguration().orientation;
videoRecorder.setVideoQuality(CamcorderProfile.QUALITY_2160P, orientation);

3. Create a video recording

  1. To begin recording, call onToggleRecord():

       // Returns true if recording has started.
       boolean recording = videoRecorder.onToggleRecord();
    
  2. To stop recording, call onToggleRecord() a second time:

       // Returns false if recording has stopped.
       boolean recording = videoRecorder.onToggleRecord();
    
  3. To retrieve the file path of the video recording, use getVideoPath():

       // Determine absolute file path of video recording.
       String videoPath = videoRecorder.getVideoPath().getAbsolutePath();
    
  4. Optionally, copy the recorded file to your development machine using adb:

adb pull /sdcard/…/path/to/recorded/video.mp4 .

To determine the correct location for images and video so that they properly show up on the camera roll, the VideoRecord class utilizes Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).