Sceneform SceneViews の録画
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このデベロッパー ガイドでは、アプリがシーンの動画 SceneView
をローカルの動画ファイルに録画できるようにする手順について説明します。VideoRecorder
クラスで利用可能な機能を使用します。この機能は、Sceneform SDK for Android のバージョン 1.6.0 以降の VideoRecording サンプル サンプルの一部として提供されています。
サンプルアプリをビルドして実行する
VideoRecording Sample アプリをビルドして実行するには:
- Android Studio にシーン プロジェクトが含まれていること、および Android デバイスが USB を介して開発マシンに接続されていることを確認してください。詳細な手順については、クイックスタートをご覧ください。
- プロジェクトに VideoRecording サンプルをインポートします。
- Android Studio で [Run]
をクリックします。次に、デプロイのターゲットとしてデバイスを選択し、[OK] をクリックしてデバイス上でサンプルアプリを起動します。
- デバイスを移動して 3D オブジェクトを周囲のスペースに配置したら、[Record] ボタンをクリックして録画を開始し、[Stop] ボタンをクリックして録画を停止します。
録画した動画にアクセスするには、デバイスのカメラロール、Sceneform
という名前のフォトアルバム、またはパスを使用します。
/sdcard/Pictures/Sceneform/Sample<hex characters>.mp4
アプリでシーンシーンを録画できるようにするには、次のことを行う必要があります。
- アプリの権限のリクエスト
- 動画レコーダーの初期化
- 録画の開始と停止
1. アプリの権限をリクエストする
動画ファイルをローカル ストレージに書き込むには、アプリで AndroidManifest.xml
に次の行を追加して、WRITE_EXTERNAL_STORAGE
権限をリクエストする必要があります。
<application>
…
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
2. 動画レコーダーを初期化する
VideoRecording サンプルには VideoRecorder
という名前のクラスが含まれています。このクラスは、MediaRecorder を使用して SceneView
オブジェクトからフレームをキャプチャして動画を作成するのに必要なすべての設定ロジックをカプセル化します。
動画レコーダーを使用するには、アクティビティ(onCreate()
など)で VideoRecorder クラスを初期化します。
// 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. 動画を撮影する
録画を開始するには、onToggleRecord()
を呼び出します。
// Returns true if recording has started.
boolean recording = videoRecorder.onToggleRecord();
録画を停止するには、onToggleRecord()
をもう一度呼び出します。
// Returns false if recording has stopped.
boolean recording = videoRecorder.onToggleRecord();
録画のファイルパスを取得するには、getVideoPath()
を使用します。
// Determine absolute file path of video recording.
String videoPath = videoRecorder.getVideoPath().getAbsolutePath();
(省略可)adb を使用して、録画したファイルを開発マシンにコピーします。
adb pull /sdcard/…/path/to/recorded/video.mp4 .
カメラロール上に適切に表示されるよう、画像や動画の正しい場所を特定するために、VideoRecord
クラスは Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
を使用します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2022-09-26 UTC。
[null,null,["最終更新日 2022-09-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,["# Video recording of Sceneform SceneViews\n\nThis 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----------------------------\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----------------------------------------------------------------\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\n### 1. 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\n### 2. 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\n### 3. 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))."]]