0
2

Recorderとは?

「Unity Recorder」とは、Unity のエディタ内でゲームプレイ、アニメーション、
その他のシーンコンテンツを、ビデオ・画像・オーディオ・アニメーションクリップ
などの、様々な形式でキャプチャおよびエクスポートするツールです。

インストール方法

Unityエディタを開き、上部のメニューから
「Window」>「Package Manager」を選択します。
右上の検索バーに「Recorder」と入力し、出てきたパッケージをインストールします。

スクリプトで制御する

「Window」>「General」>「Recorder」>「Recorder Window」
の順に選択すると、画像のようなウィンドウが表示されます。
今回は、ウィンドウの各種設定と録画の開始・終了をスクリプトから制御します。

制御するにあたって、最初にアプローチを整理します。

『Recorderの設定 -> Controllerの設定 -> Recorderの追加 -> Controllerの作成』

この順番で処理を書いていきます。


1.「Recorderの設定」

-> ウィンドウの左にある「Add Recorder」から追加できるレコーダー本体の設定。

// インスタンスを作成
recorderSettings = ScriptableObject.CreateInstance<MovieRecorderSettings>();

// 出力形式
recorderSettings.OutputFormat = MovieRecorderSettings.VideoRecorderOutputFormat.MP4

// ビデオ品質
recorderSettings.VideoBitRateMode = UnityEditor.VideoBitrateMode.High

// 出力設定
recorderSettings.OutputFile = $"保存先のパス/ファイル名";

// 録画設定
recorderSettings.ImageInputSettings = new GameViewInputSettings();

// 録音設定
recorderSettings.AudioInputSettings.PreserveAudio = true;

// 有効化
recorderSettings.Enabled = true;

2.「Controllerの設定」

-> レコーダーを管理し、レコーディングの開始・終了を行うコントローラーの設定。

// インスタンスを作成
controllerSettings = ScriptableObject.CreateInstance<RecorderControllerSettings>();

// フレームレートの制御方法
controllerSettings.FrameRatePlayback = FrameRatePlayback.Constant;

// フレームレート
controllerSettings.FrameRate = 30f;

// フレームレートを制限するか
controllerSettings.CapFrameRate = true;

3.「Recorderの追加」

-> 1.で作成したレコーダーの設定を、2.で作成したコントローラーの設定に追加。

controllerSettings.AddRecorderSettings(recorderSettings);

4.「Controllerの作成」

-> コントローラーのインスタンスを作成して、レコーディングを開始・終了させる。

// インスタンスを作成
controller = new RecorderController(controllerSettings);
// レコーディングの準備
controller.PrepareRecording();
// レコーディングの開始
controller.StartRecording();

あとは、終了したいタイミングで「RecorderController.StopRecording()」を呼びます。
録画に成功すると、OutputFile で指定したパスに新しく動画ファイルが作成されます。

以上がスクリプトによる(Movie)Recorderの制御です!
最後までご覧いただきありがとうございました :laughing:

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2