---
title: VideoRecording
slug: world-sdk-guide-ja/videorecording
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

ワールド内でビデオ関連の機能を使用して、WorldVideoRecorder APIを使ってビデオを保存または共有し、ビデオを使用してフィードを作成できます。

ビデオの録画および保存/共有/フィード投稿機能を使用するには、次のようにインポート文を作成する必要があります。

```typescript
import { WorldVideoRecorder } from 'ZEPETO.World';
```

WorldVideoRecorder APIは、以下のビデオ関連機能を提供します。

| **API**                                                                                                                                                    | **説明**                                                                                                                                                                                                                                 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| WorldVideoRecorder.StartRecording(camera: UnityEngine.Camera, resolutions: VideoResolutions, durationSecond: number)\:boolean                              | ビデオの録画を開始します。録画カメラ、ビデオ解像度、録画時間をパラメータとして設定できます。戻り値は、録画開始が成功したかどうかを示します。<br /><br />- enum VideoResolutions \{ W1280xH720 = 0, W720xH1280 = 1, W1920xH1080 = 2, W1080xH1920 = 3 }<br />- durationSecond : 最大値は60なので、可能であれば60未満で入力してください。 |
| WorldVideoRecorder.StopRecording()                                                                                                                         | 進行中のビデオの録画を停止します。                                                                                                                                                                                                                      |
| WorldVideoRecorder.IsRecording()\:boolean                                                                                                                  | ビデオの録画を続行するかどうかを返します。                                                                                                                                                                                                                  |
| WorldVideoRecorder.SaveToCameraRoll(callback: System.Action$1)                                                                                             | ビデオをフォトライブラリに保存します。                                                                                                                                                                                                                    |
| WorldVideoRecorder.Share(callback: System.Action$1)                                                                                                        | 外部アプリとビデオを共有します。                                                                                                                                                                                                                       |
| WorldVideoRecorder.CreateFeed(contents: string, $callback: System.Action$1)                                                                                | ビデオをフィードにアップロードします。最初の要素であるcontentsは、投稿の内容を指定することができます。                                                                                                                                                                                |
| WorldVideoRecorder.AddVideoPlayerComponent(playerObject: UnityEngine.GameObject, renderTexture: UnityEngine.RenderTexture)\:UnityEngine\_Video.VideoPlayer | ビデオを再生したいGameObjectにビデオプレイヤーコンポーネントを追加し、録画したビデオファイルを接続します。これにより、追加されたビデオプレイヤーが返され、パラメータに応じてビデオを再生するための幅、高さ、またはRenderTextureを指定できます。                                                                                                    |
| WorldVideoRecorder.GetThumbnail()\:UnityEngine.Texture2D;                                                                                                  | 録画したビデオのサムネイルを返します。                                                                                                                                                                                                                    |

次は、World Video Recorder内の動画を保存/共有/フィード投稿する機能の関数を呼び出す例です。

:::hint{type="danger"}
- Unityエディタ環境では確認できませんが、アプリを通して再生する際には確認できます。
- 解像度はファイルとして保存される際に指定された値で記録されますが、ZEPETO Feedにアップロードされると解像度が変わる可能性があります。
- durationSecondに60を超える値を入力すると、録画が正しく機能しません。
:::

```typescript
WorldVideoRecorder.SaveToCameraRoll(result => {console.log(`${result}`)});   

WorldVideoRecorder.Share(result => {console.log(`${result}`)});

WorldVideoRecorder.CreateFeed("[contents]", result => {console.log(`${result}`)});
```



以下は、RenderTextureを使用してWorldVideoRecorder内の動画録画機能の関数を使用した全体の例コードです。

```typescript
import { Camera, GameObject, RenderTexture } from 'UnityEngine';
import { Button, RawImage } from 'UnityEngine.UI';
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { VideoResolutions, WorldVideoRecorder } from 'ZEPETO.World';

export default class WorldVideoRecorderExample extends ZepetoScriptBehaviour {
    
    // WorldVideoRecorder Video UI 
    public startRecordingButton: Button;
    public stopRecordingButton: Button;
    public saveVideoButton: Button;
    public shareVideoButton: Button;
    public createFeedButton: Button;
    public getThumbnailButton: Button;
    public thumbnailImage: RawImage;

    // Recorder Camera 
    public recorderCamera: Camera;

    // Target Texture 
    public targetTexture: RenderTexture;

    // VideoPlayer Object 
    private videoPlayerObject: GameObject;

    Awake() {
        this.videoPlayerObject = new GameObject();
    }

    Start() {
        this.startRecordingButton.onClick.AddListener(() => {
            if (false == WorldVideoRecorder.StartRecording(this.recorderCamera, VideoResolutions.W1280xH720, 15)) {
                return;
            }

            this.StartCoroutine(this.CheckRecording());
        });

        this.stopRecordingButton.onClick.AddListener(() => {
            if (false == WorldVideoRecorder.IsRecording()) {
                return;
            }

            WorldVideoRecorder.StopRecording();
        });

        this.saveVideoButton.onClick.AddListener(() => {
            if (false == WorldVideoRecorder.IsRecording()) {
                WorldVideoRecorder.SaveToCameraRoll(result => { console.log(`${result}`) });
            }
        });

        this.shareVideoButton.onClick.AddListener(() => {
            if (false == WorldVideoRecorder.IsRecording()) {
                WorldVideoRecorder.Share(result => { console.log(`${result}`) });
            }
        });

        this.createFeedButton.onClick.AddListener(() => {
            if (false == WorldVideoRecorder.IsRecording()) {
                WorldVideoRecorder.CreateFeed("[contents]", result => { console.log(`${result}`) });
            }
        });

        this.getThumbnailButton.onClick.AddListener(() => {
            if (false == WorldVideoRecorder.IsRecording()) {
                this.thumbnailImage.texture = WorldVideoRecorder.GetThumbnail();
            }
        });
    }

    *CheckRecording() {
        while (WorldVideoRecorder.IsRecording()) {
            yield null;
        }

        let videoPlayer = WorldVideoRecorder.AddVideoPlayerComponent(this.videoPlayerObject, this.targetTexture);

        if (videoPlayer == null) {
            return;
        }
        
        videoPlayer.Play();
    }
}
```

スクリプトを書いた後、キャンバスに必要なボタンと生画像を作成します。

その後、インスペクターで各コンポーネントを割り当てます。

- カメラには、通常のカメラコンポーネントを使用できます。
- ターゲットテクスチャについては、作成 > レンダーテクスチャとして作成してください。

::Image[]{src="https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-9Q1Nl9SoGPJfMgEClrJkV-20240904-102426.png" size="58" width="337" height="441" position="center" showCaption="false"}

:::hint{type="success"}
**👍 ヒント**

- スクリーンショットと同じレンダーテクスチャを使用すると、正しくレンダリングされない場合がありますので、録画用に新しいレンダーテクスチャを作成して使用してください。
:::



QRモバイルビルドを通してビデオ録画機能をテストできます。

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-_RN5L3ExW9fSNhlLPLc30-20240904-102426.png)

