VideoKitRecorder
namespace VideoKit {
/// <summary>
/// Unity component for recording video and audio files.
/// </summary>
class VideoKitRecorder : MonoBehaviour { ... }
}
This component manages recording videos. The component can be added to any game object in the scene.
One recorder component can only record one video at a time. To record multiple videos simultaneously, use multiple recorder components.
Format Settings
The recorder's format settings dictate what types of media can be recorded, and how the resulting recording is handled:
Specifying the Recording Format
/// <summary>
/// Recording format.
/// </summary>
Format format { get; set; }
The format
dictates what type of file gets recorded in a given recording session.
See MediaRecorder.Format
for supported formats.
Preparing on Awake
/// <summary>
/// Prepare the hardware encoders on awake.
/// </summary>
bool prepareOnAwake { get; set; }
Preparing the recorder on Awake
prevents a noticeable stutter that occurs on the very first recording.
Specifying the Recording Action
/// <summary>
/// Recording action.
/// </summary>
RecordingAction recordingAction { get; set; }
The recordingAction
is used to specify what happens once a recording session is completed.
The following actions are currently supported:
/// <summary>
/// Recording action.
/// </summary>
[Flags]
enum RecordingAction : int {
/// <summary>
/// Nothing.
/// </summary>
None = 0,
/// <summary>
/// Save the media asset to the camera roll.
/// </summary>
CameraRoll = 2,
/// <summary>
/// Prompt the user to share the media asset with the native sharing UI.
/// </summary>
Share = 4,
/// <summary>
/// Playback the video with the platform default media player.
/// </summary>
Playback = 8,
/// <summary>
/// Define a custom callback to receive the media asset.
/// </summary>
Custom = 32,
}
The RecordingAction.Custom
mode is mutually exclusive with all other recording actions.
Specifying a Recording Callback
/// <summary>
/// Event raised when a recording session is completed.
/// </summary>
UnityEvent<MediaAsset> OnRecordingCompleted { get; }
The OnRecordingCompleted
event can be used to register a callback to be invoked with the
recorded MediaAsset
.
The OnRecordingCompleted
event is only raised when the recordingAction
is set to RecordingAction.Custom
.
Video Settings
The video settings are used to configure the video stream of recordings.
These settings only have an effect when the format
supports recording pixel buffers,
and when the videoMode
is not VideoMode.None
.
Specifying the Video Mode
/// <summary>
/// Video recording mode.
/// </summary>
VideoMode videoMode { get; set; }
The videoMode
defines how pixel buffers will be recorded. The following video modes are supported:
/// <summary>
/// Video recording mode.
/// </summary>
enum VideoMode : int {
/// <summary>
/// Don't record video.
/// </summary>
None = 0,
/// <summary>
/// Record pixel buffers from one or more game cameras.
/// </summary>
Camera = 1,
/// <summary>
/// Record pixel buffers from the screen.
/// </summary>
Screen = 2,
/// <summary>
/// Record pixel buffers from a texture.
/// </summary>
Texture = 3,
/// <summary>
/// Record pixel buffers from a camera device.
/// </summary>
CameraDevice = 4,
}
The videoMode
is ignored when the recorder format does not support recording pixel buffers.
Specifying the Video Resolution
/// <summary>
/// Video recording resolution.
/// </summary>
Resolution resolution { get; set; }
The resolution
determines the video resolution of recorded videos or images.
The following resolution presets are supported:
/// <summary>
/// Video recording resolution presets.
/// </summary>
enum Resolution : int {
/// <summary>
/// QVGA resolution.
/// </summary>
_240xAuto = 11,
/// <summary>
/// QVGA resolution.
/// </summary>
_320xAuto = 5,
/// <summary>
/// Portrait SD (480p) resolution.
/// </summary>
_480xAuto = 6,
/// <summary>
/// SD (480p) resolution.
/// </summary>
_640xAuto = 0,
/// <summary>
/// Potrait HD (720p) resolution.
/// </summary>
_720xAuto = 7,
/// <summary>
/// HD (720p) resolution.
/// </summary>
_1280xAuto = 1,
/// <summary>
/// Portrait Full HD (1080p) resolution.
/// </summary>
_1080xAuto = 12,
/// <summary>
/// Full HD (1080p) resolution.
/// </summary>
_1920xAuto = 2,
/// <summary>
/// Portrait 2K WQHD resolution.
/// </summary>
_1440xAuto = 13,
/// <summary>
/// 2K WQHD resolution.
/// </summary>
_2560xAuto = 3,
/// <summary>
/// Portrait 4K UHD resolution.
/// </summary>
_2160xAuto = 14,
/// <summary>
/// 4K UHD resolution.
/// </summary>
_3840xAuto = 4,
/// <summary>
/// Screen resolution.
/// </summary>
Screen = 9,
/// <summary>
/// Half of the screen resolution.
/// </summary>
HalfScreen = 10,
/// <summary>
/// Custom resolution.
/// </summary>
Custom = 8,
}
Specifying a Custom Resolution
/// <summary>
/// Video recording custom resolution.
/// </summary>
Vector2Int customResolution { get; set; }
The customResolution
is used to specify a custom recording resolution.
The customResolution
is only used when the resolution
is set to Resolution.Custom
Specifying the Recording Cameras
/// <summary>
/// Game cameras to record.
/// </summary>
Camera[] cameras { get; set; }
The cameras
property holds an array of game cameras to record in a given recording session.
The cameras
are only used when the videoMode
is set to VideoMode.Camera
.
Specifying the Recording Texture
/// <summary>
/// Texture to record.
/// </summary>
Texture? texture { get; set; }
The texture
property is used to record pixel buffers from a Texture
.
The texture
is only used when the videoMode
is set to VideoMode.Texture
.
Specifying the Camera Manager
/// <summary>
/// Camera manager for recording pixel buffers from a camera device.
/// </summary>
VideoKitCameraManager? cameraManager { get; set; }
The cameraManager
property is used to record pixel buffers from a CameraDevice
.
The cameraManager
is only used when the videoMode
is set to VideoMode.CameraDevice
.
Specifying the GIF Frame Rate
/// <summary>
/// Frame rate for animated GIF images.
/// </summary>
[Tooltip(@"Frame rate for animated GIF images."),]
float _frameRate { get; set; } = 10;
When recording animated GIF images, the frame duration must be specified ahead of time using this property.
The _frameRate
property is only used when recording animated GIF images.
Specifying the Video Bitrate
/// <summary>
/// Video bit rate in bits per second.
/// </summary>
int videoBitRate { get; set; } = 20_000_000;
The videoBitRate
is used when recording to a format that supports variable bitrate recording like MP4
and HEVC
.
This setting strongly influences the visual quality and file size of recorded videos.
Specifying the Keyframe Interval
/// <summary>
/// Video keyframe interval in seconds.
/// </summary>
int keyframeInterval { get; set; } = 2;
The keyframeInterval
is used by some formats to control visual quality of recorded videos.
Skipping Frames
/// <summary>
/// Number of successive camera frames to skip while recording.
/// </summary>
int frameSkip { get; set; }
The frameSkip
property is used to record at a fraction of the realtime frame rate.
This is particularly useful for recording animated GIF images which have a lower frame rate.
This setting is not supported when the videoMode
is VideoMode.CameraDevice
.
Audio Settings
The audio settings are used to configure the audio stream of recordings.
These settings only have an effect when the format
supports recording audio buffers,
and when the audioMode
is not AudioMode.None
.
Specifying the Audio Mode
/// <summary>
/// Audio recording mode.
/// </summary>
AudioMode audioMode { get; set; }
The audioMode
defines how audio buffers will be recorded. The following audio modes are supported:
/// <summary>
/// Audio recording mode.
/// </summary>
enum AudioMode : int {
/// <summary>
/// Don't record audio.
/// </summary>
None = 0,
/// <summary>
/// Record audio from an audio listener.
/// </summary>
AudioListener = 1,
/// <summary>
/// Record audio from an audio device.
/// </summary>
AudioDevice = 2,
/// <summary>
/// Record audio from an audio source.
/// </summary>
AudioSource = 4,
}
The audioMode
is ignored when the recorder format does not support recording audio buffers.
On WebGL, neither AudioMode.AudioSource
nor AudioMode.AudioListener
is supported because
Unity does not support capturing engine audio on WebGL.
Specifying the Audio Listener
/// <summary>
/// Audio listener for recording audio from an audio listener.
/// </summary>
AudioListener? audioListener { get; set; }
The audioListener
property is used to specify a scene
AudioListener
to record game audio from.
The audioListener
is only used when the audioMode
is set to AudioMode.AudioListener
.
Specifying the Audio Manager
/// <summary>
/// Audio manager for recording audio from an audio device.
/// </summary>
VideoKitAudioManager? audioManager { get; set; }
The audioManager
property is used to specify a VideoKitAudioManager
for recording audio buffers from an AudioDevice
.
The audioManager
is only used when the audioMode
is set to AudioMode.AudioDevice
.
Specifying the Audio Source
/// <summary>
/// Audio source for recording audio from an audio source.
/// </summary>
AudioSource? audioSource { get; set; }
The audioSource
property is used to specify a scene
AudioSource
to record game audio from.
The audioSource
is only used when the audioMode
is set to AudioMode.AudioSource
.
Managing Sessions
The recorder component records a video or audio file in a recording session.
Inspecting the Recording Status
/// <summary>
/// Recorder status.
/// </summary>
Status status { get; }
The recording status
reports the current state of recording.
/// <summary>
/// Recorder status.
/// </summary>
enum Status : int {
/// <summary>
/// No recording session is in progress.
/// </summary>
Idle = 0,
/// <summary>
/// Recording session is in progress.
/// </summary>
Recording = 1,
/// <summary>
/// Recording session is in progress but is paused.
/// </summary>
Paused = 2,
}
Starting a Recording Session
/// <summary>
/// Start recording.
/// </summary>
void StartRecording ();
A recording session is started by calling the StartRecording method. This method can be invoked directly from UI elements.
Recorders can only record one video at a time.
Pausing a Recording Session
/// <summary>
/// Pause recording.
/// </summary>
void PauseRecording ();
A recording session can be paused. This will stop appending pixel buffers and audio buffers to the recorder until the session is resumed.
This method has been deprecated, and will likely be removed in an upcoming version of VideoKit.
Resuming a Recording Session
/// <summary>
/// Resume recording.
/// </summary>
void ResumeRecording ();
A paused recording session can be resumed with this method.
Finishing a Recording Session
/// <summary>
/// Stop recording.
/// </summary>
void StopRecording ();
A recording session is stopped by calling the StopRecording
method. The recordingAction
will be
invoked once recording is completed.