- Sceneform SDK for Android was open sourced and archived (github.com/google-ar/sceneform-android-sdk) with version 1.16.0.
- This site (developers.google.com/sceneform) serves as the documentation archive for the previous version, Sceneform SDK for Android 1.15.0.
- Do not use version 1.17.0 of the Sceneform Maven artifacts.
- The 1.17.1 Maven artifacts can be used. Other than the version, however, the 1.17.1 artifacts are identical to the 1.15.0 artifacts.
Video recording of Sceneform SceneViews
Stay organized with collections
Save and categorize content based on your preferences.
This developer guide takes you through the steps to enable your app to record
Sceneform SceneView
s 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:
- 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.
- Import the
VideoRecording Sample
into your project.
- In Android Studio, click Run
. Then,
choose your device as the deployment target and click OK to launch the
sample app on your device.
- 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
Enabling your app to record Sceneform scenes requires:
- Requesting app permissions
- Initializing the video recorder
- 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
To begin recording, call onToggleRecord()
:
// Returns true if recording has started.
boolean recording = videoRecorder.onToggleRecord();
To stop recording, call onToggleRecord()
a second time:
// Returns false if recording has stopped.
boolean recording = videoRecorder.onToggleRecord();
To retrieve the file path of the video recording, use getVideoPath()
:
// Determine absolute file path of video recording.
String videoPath = videoRecorder.getVideoPath().getAbsolutePath();
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)
.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-06-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-26 UTC."],[[["\u003cp\u003eThis guide explains how to record Sceneform \u003ccode\u003eSceneView\u003c/code\u003es to a local video file using the \u003ccode\u003eVideoRecorder\u003c/code\u003e class.\u003c/p\u003e\n"],["\u003cp\u003eYou can build and run the provided \u003cstrong\u003eVideoRecording Sample\u003c/strong\u003e app to experience the recording functionality.\u003c/p\u003e\n"],["\u003cp\u003eEnabling video recording in your app involves requesting permissions, initializing the \u003ccode\u003eVideoRecorder\u003c/code\u003e, and starting/stopping recording using \u003ccode\u003eonToggleRecord()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eRecorded videos are saved to the device's camera roll in a folder named \u003ccode\u003eSceneform\u003c/code\u003e and can be accessed via their file path.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eVideoRecorder\u003c/code\u003e class uses \u003ccode\u003eMediaRecorder\u003c/code\u003e to capture frames from the \u003ccode\u003eSceneView\u003c/code\u003e and save them as a video file.\u003c/p\u003e\n"]]],["To enable Sceneform video recording, first, request the `WRITE_EXTERNAL_STORAGE` permission in `AndroidManifest.xml`. Then, initialize the `VideoRecorder` class, setting the `SceneView` and video quality. Start recording by calling `onToggleRecord()`, and call it again to stop. Retrieve the video's file path with `getVideoPath()`. The video is saved in the device's camera roll within a `Sceneform` album or at `/sdcard/Pictures/Sceneform/`. You can also copy the video using adb pull.\n"],null,["This developer guide takes you through the steps to enable your app to record\nSceneform [`SceneView`s](/sceneform/reference/com/google/ar/sceneform/SceneView) to a local video file. It uses functionality\navailable in the `VideoRecorder` class, which is available as part of the\n[VideoRecording Sample](//github.com/google-ar/sceneform-android-sdk/tree/v1.15.0/samples/videorecording)\nsample starting with version 1.6.0 of the Sceneform SDK for Android.\n\nBuild and run the sample app\n\nTo build and run the **VideoRecording Sample** app:\n\n1. 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](/sceneform/develop/android-quickstart) for detailed steps.\n2. Import the [VideoRecording Sample](//github.com/google-ar/sceneform-android-sdk/tree/v1.15.0/samples/videorecording) into your project.\n3. In Android Studio, click **Run** . Then, choose your device as the deployment target and click **OK** to launch the sample app on your device.\n4. 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.\n\nThe recorded video will be accessible via the camera roll on the device, in a\nphoto album named `Sceneform` or at the path: \n\n /sdcard/Pictures/Sceneform/Sample\u003chex characters\u003e.mp4\n\nOverview of enabling an app to support Sceneform video recording\n\nEnabling your app to record Sceneform scenes requires:\n\n1. Requesting app permissions\n2. Initializing the video recorder\n3. Starting and stopping video recording\n\n1. Request app permissions\n\nIn order to be able to write the video file to local storage, you app must\nrequest the `WRITE_EXTERNAL_STORAGE` permission by adding the following line to\nyour `AndroidManifest.xml`: \n\n \u003capplication\u003e\n ...\n \u003c/application\u003e\n\n \u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/\u003e\n\n2. Initialize the video recorder\n\nThe **VideoRecording Sample** includes a class named `VideoRecorder`, which\nencapsulates all the settings logic needed to use the\n[MediaRecorder](//developer.android.com/guide/topics/media/mediarecorder) to\ncapture frames from a `SceneView` object to create a video.\n\nTo use the video recorder, initialize the\n[VideoRecorder](//github.com/google-ar/sceneform-android-sdk/blob/v1.15.0/samples/videorecording/app/src/main/java/com/google/ar/sceneform/samples/videorecording/VideoRecorder.java)\nclass in your activity, for example in `onCreate()`. \n\n // Create a new video recorder instance.\n videoRecorder = new VideoRecorder();\n\n // Specify the AR scene view to be recorded.\n videoRecorder.setSceneView(arFragment.getArSceneView());\n\n // Set video quality and recording orientation to match that of the device.\n int orientation = getResources().getConfiguration().orientation;\n videoRecorder.setVideoQuality(CamcorderProfile.QUALITY_2160P, orientation);\n\n3. Create a video recording\n\n1. To begin recording, call `onToggleRecord()`:\n\n // Returns true if recording has started.\n boolean recording = videoRecorder.onToggleRecord();\n\n2. To stop recording, call `onToggleRecord()` a second time:\n\n // Returns false if recording has stopped.\n boolean recording = videoRecorder.onToggleRecord();\n\n3. To retrieve the file path of the video recording, use `getVideoPath()`:\n\n // Determine absolute file path of video recording.\n String videoPath = videoRecorder.getVideoPath().getAbsolutePath();\n\n4. Optionally, copy the recorded file to your development machine using adb:\n\n```\nadb pull /sdcard/…/path/to/recorded/video.mp4 .\n```\n\nTo determine the correct location for images and video so that they properly\nshow up on the camera roll, the `VideoRecord` class utilizes\n[`Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)`](//developer.android.com/reference/android/os/Environment#getExternalStoragePublicDirectory(java.lang.String))."]]