### Start Running Source: https://www.videokit.ai/reference/cameradevice Starts the camera preview stream and begins receiving pixel buffers via the provided handler. ```APIDOC ## StartRunning ### Description Starts the camera preview stream and invokes the provided handler with `PixelBuffer` instances. ### Method `void StartRunning (Action handler);` ### Parameters #### Path Parameters - **handler** (Action) - Required - Delegate to receive preview image frames. ``` -------------------------------- ### Start Running Source: https://www.videokit.ai/reference/audiodevice Starts the audio stream and provides a handler to receive audio buffers. The handler is invoked on a dedicated audio device thread. ```APIDOC ## StartRunning ### Description Starts the audio stream and provides a handler to receive audio buffers. The handler is invoked on a dedicated audio device thread. ### Method Signature `void StartRunning(Action handler)` ### Parameters #### Parameters - **handler** (Action) - Delegate to receive audio buffers. ``` -------------------------------- ### Start Recording Source: https://www.videokit.ai/reference/videokitrecorder Starts a new recording session. This method can be invoked directly or asynchronously. ```APIDOC ## StartRecording ### Description Start recording. ### Method `void StartRecording();` ### Async Method `Task StartRecordingAsync();` ### Notes A recording session is started by calling the `StartRecording` method. The `StartRecordingAsync` method waits for the recording session to asynchronously start. ``` -------------------------------- ### Starting Camera Stream Source: https://www.videokit.ai/cameras Starts streaming pixel buffers from the camera device. Requires a callback for processing pixel data. ```APIDOC ## Streaming Pixel Buffers ### Description Starts streaming pixel buffers from the camera device. Requires a callback for processing pixel data. ### Method `CameraDevice.StartRunning` ### Parameters #### Path Parameters - **OnPixelBuffer** (Action) - Required - Callback invoked with pixel buffers as they become available. ### Request Example ```csharp // Start streaming pixel buffers from the camera cameraDevice.StartRunning(OnPixelBuffer); void OnPixelBuffer(PixelBuffer pixelBuffer) { // ... } ``` ``` -------------------------------- ### Start Recording Session Asynchronously Source: https://www.videokit.ai/reference/videokitrecorder Asynchronously starts a recording session, allowing for exception handling. ```csharp /// /// Start recording. /// Task StartRecordingAsync(); ``` -------------------------------- ### Start Camera Stream Source: https://www.videokit.ai/reference/cameradevice Start the camera preview stream and provide a handler to receive `PixelBuffer` instances. The handler is invoked on a dedicated camera thread. ```csharp /// /// Start the camera preview. /// /// Delegate to receive preview image frames. void StartRunning (Action handler); ``` -------------------------------- ### Configure Preview Resolution Source: https://www.videokit.ai/reference/cameradevice Sets or gets the desired resolution for the camera's preview stream. This should be configured before starting the preview. ```APIDOC ## previewResolution ### Description Gets or sets the desired resolution (width and height) for the camera's preview stream. This property must be set **before** starting the preview stream. The resolution is specified in landscape format, meaning width should always be larger than height. ### Property `(int width, int height) previewResolution { get; set; }` ### Usage Set the desired preview resolution before initiating the camera preview. ``` -------------------------------- ### Start Audio Stream Source: https://www.videokit.ai/reference/audiodevice Provide a handler to receive audio buffers when starting the stream. The handler is invoked on a dedicated audio device thread. ```csharp /// /// Start running. /// /// Delegate to receive audio buffers. void StartRunning(Action handler); ``` -------------------------------- ### StartRunning Source: https://www.videokit.ai/reference/multicameradevice Starts the camera preview from a specific camera within a multi-camera device, leaving other cameras unaffected. ```APIDOC ## StartRunning ### Description Starts the camera preview from a given camera in the multi-camera device. ### Method Signature `void StartRunning(CameraDevice camera);` ### Parameters #### Path Parameters - **camera** (CameraDevice) - Required - The camera device to start. Must be a member of this multi-camera device. ``` -------------------------------- ### Start Audio Streaming Source: https://www.videokit.ai/reference/videokitaudiomanager Starts streaming audio buffers from the audio device. If no device is set, it defaults to the system's default audio device. The OnAudioBuffer event is invoked as buffers become available. ```csharp /// /// Start streaming audio. /// void StartRunning(); ``` -------------------------------- ### Start Stream Source: https://www.videokit.ai/reference/multicameradevice Starts the video stream from the multi-camera device, providing a handler to receive pixel buffers from each camera. ```APIDOC ## StartRunning ### Description Start running the multi-camera device stream. ### Method `void StartRunning(Action handler)` ### Parameters * **handler** (Action) - Delegate to receive preview frames. The handler is invoked on a dedicated camera thread. ### Notes * The provided handler is invoked on a dedicated camera thread, not the Unity main thread. ``` -------------------------------- ### Discover Camera Devices Source: https://www.videokit.ai/cameras After obtaining permissions, discover available camera devices. This example selects the first front-facing camera. ```csharp using System.Linq; // Discover available camera devices CameraDevice[] cameraDevices = await CameraDevice.Discover(); // Use the first front-facing camera device CameraDevice cameraDevice = cameraDevices.FirstOrDefault(cam => cam.frontFacing); ``` -------------------------------- ### Install VideoKit with Unity Package Manager Source: https://www.videokit.ai/ Add these lines to your `Packages/manifest.json` file to import the SDK. Ensure you have the correct registry URLs and package name. ```json { "scopedRegistries": [ { "name": "VideoKit", "url": "https://registry.npmjs.com", "scopes": ["ai.videokit"] }, { "name": "Muna", "url": "https://registry.npmjs.com", "scopes": ["ai.muna"] } ], "dependencies": { "ai.videokit.videokit": "1.0.10", ... } } ``` -------------------------------- ### Start Recording Session Source: https://www.videokit.ai/reference/videokitrecorder Initiates a recording session. This method can be invoked directly from UI elements. ```csharp /// /// Start recording. /// void StartRecording(); ``` -------------------------------- ### Initialize Camera Preview Source: https://www.videokit.ai/cameras Allocates memory for preview data and creates a texture for display. Ensure this is called before starting the camera. ```csharp private NativeArray rgbaData; private Texture2D texture; void StartCamera() { // Get the current preview resolution from the camera var (width, height) = camera.previewResolution; // Create preview data rgbaData = new NativeArray(width * height * 4, Allocator.Persistent); // Create the preview texture texture = new Texture2D(width, height, TextureFormat.RGBA32, false); // Start streaming pixel buffers from the camera cameraDevice.StartRunning(OnPixelBuffer); } ``` -------------------------------- ### Configure Preview Frame Rate Source: https://www.videokit.ai/reference/cameradevice Sets or gets the desired frame rate for the camera's preview stream. This should be configured before starting the preview. ```APIDOC ## frameRate ### Description Gets or sets the desired frame rate for the camera's preview stream. This property must be set **before** starting the preview stream. ### Property `float frameRate { get; set; }` ### Usage Set the desired preview frame rate before initiating the camera preview. ``` -------------------------------- ### Start Camera Preview Source: https://www.videokit.ai/reference/multicameradevice Resumes the preview for a specific camera within a multi-camera device. Ensure the provided camera is a member of the device. ```csharp /// /// Start the camera preview from a given camera in the multi-camera device. /// /// Camera device. MUST be a member of this multi-camera device. void StartRunning(CameraDevice camera); ``` -------------------------------- ### Appending Sample Buffers (With Code) Source: https://www.videokit.ai/recorders Explains how to append pixel and audio buffers to the recorder. It shows examples using `CameraSource` for video and manually creating `PixelBuffer` and `AudioBuffer`. ```APIDOC ## Appending Sample Buffers ### Using CameraSource ```csharp // Create a clock to generate recording timestamps var clock = new RealtimeClock(); // Create a camera source var cameraSource = new CameraSource( recorder, // the recorder accepts and records pixel buffers from the source clock, // the clock is used to generate recording timestamps Camera.main // the camera source captures pixel buffers from one or more game cameras ); ``` ### Appending Raw Pixel Buffers ```csharp // Create a pixel buffer Texture2D image = ...; using var pixelBuffer = new PixelBuffer( image, // texture to get pixel data from clock.timestamp // pixel buffer timestamp to use for recording ); // Append recorder.Append(pixelBuffer); ``` ### Appending Audio Buffers ```csharp // Create an audio buffer float[] data = ...; using var audioBuffer = new AudioBuffer( 44_100, 2, data, clock.timestamp ); // Append recorder.Append(audioBuffer); ``` ``` -------------------------------- ### Discover Multi-Camera Devices Source: https://www.videokit.ai/multicameras Discover available multi-camera devices after obtaining necessary permissions. This example selects the first available device. ```csharp using System.Linq; // Discover available multi-camera devices MultiCameraDevice[] multiCameraDevices = await MultiCameraDevice.Discover(); // Use the first multi-camera device MultiCameraDevice multiCameraDevice = multiCameraDevices.FirstOrDefault(); ``` -------------------------------- ### Start Streaming Audio Buffers Source: https://www.videokit.ai/microphones Begin streaming audio buffers from the `AudioDevice` by calling `StartRunning` and providing a callback function. This callback will be invoked on a dedicated microphone thread. ```csharp // Start streaming audio buffers from the audio device audioDevice.StartRunning(OnAudioBuffer); ``` ```csharp void OnAudioBuffer(AudioBuffer audioBuffer) { // ... } ``` -------------------------------- ### Initialize Camera Preview Resources Source: https://www.videokit.ai/multicameras Allocate a `NativeArray` for transformed pixel data and create a `Texture2D` for display. Starts streaming pixel buffers from the camera. ```csharp private NativeArray rgbaData; private Texture2D texture; void StartCamera() { // Get the current preview resolution from the camera var (width, height) = camera.previewResolution; // Create preview data rgbaData = new NativeArray(width * height * 4, Allocator.Persistent); // Create the preview texture texture = new Texture2D(width, height, TextureFormat.RGBA32, false); // Start streaming pixel buffers from the camera multiCameraDevice.StartRunning(OnPixelBuffer); } ``` -------------------------------- ### Start Streaming Audio Buffers Source: https://www.videokit.ai/microphones Initiate the streaming of audio buffers from the selected audio device by calling the AudioDevice.StartRunning method and providing a callback function to handle the incoming audio data. ```APIDOC ## Start Streaming Audio Buffers ### Description Initiate the streaming of audio buffers from the selected audio device by calling the AudioDevice.StartRunning method and providing a callback function to handle the incoming audio data. ### Method ```csharp // Start streaming audio buffers from the audio device audioDevice.StartRunning(OnAudioBuffer); void OnAudioBuffer(AudioBuffer audioBuffer) { // ... } ``` ### Important The callback function (`OnAudioBuffer` in this example) is invoked on a dedicated microphone thread, not the Unity main thread. Avoid calling Unity methods directly from this callback. ``` -------------------------------- ### Start Camera Streaming Source: https://www.videokit.ai/cameras Begin streaming pixel buffers from the camera device by providing a callback function. This callback is invoked on a dedicated camera thread, so avoid calling Unity methods directly from it. ```csharp // Start streaming pixel buffers from the camera cameraDevice.StartRunning(OnPixelBuffer); ``` ```csharp void OnPixelBuffer(PixelBuffer pixelBuffer) { // ... } ``` -------------------------------- ### Configuring Camera Settings Source: https://www.videokit.ai/reference/videokitcameramanager Configure camera properties such as frame rate, focus mode, and exposure mode before starting the stream. ```APIDOC ## Specifying the Preview Frame Rate ### Description The desired camera preview frame rate can be specified, and will be set before the camera starts streaming. ### FrameRate Enum ```csharp enum FrameRate : int { Default = 0, Lowest = 1, _15 = 15, _30 = 30, _60 = 60, _120 = 120, _240 = 240 } ``` ### Specifying the Focus Mode ### Description The desired camera focus mode can be specified, and will be set before the camera starts streaming. ### Specifying the Exposure Mode ### Description The desired camera exposure mode can be specified, and will be set before the camera starts streaming. ### Notes - When streaming from a `MultiCameraDevice`, the specified `frameRate` will be set on all contained cameras. - The `FrameRate._120` and `FrameRate._240` presets are used for slow motion video capture and are only supported on iOS. ``` -------------------------------- ### Start Streaming Pixel Buffers Source: https://www.videokit.ai/multicameras Begin streaming pixel buffers from a multi-camera device. Provide a callback function to process incoming pixel buffers. Note that the callback is invoked on a dedicated camera thread, not the Unity main thread. ```csharp // Start streaming pixel buffers from the multi-camera multiCameraDevice.StartRunning(OnPixelBuffer); ``` ```csharp void OnPixelBuffer(CameraDevice cameraDevice, PixelBuffer pixelBuffer) { // ... } ``` -------------------------------- ### Start Camera Stream Source: https://www.videokit.ai/reference/videokitcameramanager Initiates streaming of PixelBuffer instances from the camera device. The OnPixelBuffer event will be triggered as buffers become available. ```csharp /// /// Start the camera preview. /// void StartRunning(); ``` -------------------------------- ### Photo Resolution Source: https://www.videokit.ai/reference/cameradevice Gets or sets the resolution for capturing high-resolution photos. Should be set before starting the preview stream. ```APIDOC ## Photo Resolution ### Description Gets or sets the resolution (width and height) for capturing photos. ### Property `(int width, int height) photoResolution { get; set; }` ### Remarks - The photo resolution should only be set **before** starting the preview stream. - The resolution is specified in landscape format, meaning `width` must always be larger than `height`. ``` -------------------------------- ### Set Camera Photo Resolution Source: https://www.videokit.ai/reference/cameradevice Get or set the photo resolution. This should only be set before starting the preview stream. Width must be larger than height for landscape format. ```csharp /// /// Get or set the photo resolution. /// (int width, int height) photoResolution { get; set; } ``` -------------------------------- ### Creating a Recorder (With Code) Source: https://www.videokit.ai/recorders Demonstrates how to create a `MediaRecorder` instance with specified format, width, height, and frame rate. ```APIDOC ## Creating a Recorder ```csharp // Create a recorder var recorder = await MediaRecorder.Create( format: MediaRecorder.Format.MP4, width: 1280, height: 720, frameRate: 30 ); ``` ``` -------------------------------- ### Create MediaRecorder Instance Source: https://www.videokit.ai/recorders Instantiate a MediaRecorder specifying the desired format and settings. Refer to `MediaRecorder` for format-specific requirements. ```csharp // Create a recorder var recorder = await MediaRecorder.Create( format: MediaRecorder.Format.MP4, width: 1280, height: 720, frameRate: 30 ); ``` -------------------------------- ### Configure Preview Resolution Source: https://www.videokit.ai/reference/cameradevice Sets the desired resolution for the camera preview stream. This must be configured before starting the preview and should be specified in landscape format (width > height). ```csharp (int width, int height) previewResolution { get; set; } ``` -------------------------------- ### Get Camera Zoom Range Source: https://www.videokit.ai/reference/cameradevice Get the supported zoom ratio range for the camera device. ```csharp /// /// Zoom ratio range. /// (float min, float max) zoomRange { get; } ``` -------------------------------- ### AudioBuffer Constructors Source: https://www.videokit.ai/reference/audiobuffer Demonstrates how to create an AudioBuffer from different data sources. ```APIDOC ## AudioBuffer Constructors ### From a Managed Buffer ```csharp AudioBuffer( int sampleRate, int channelCount, float[] data, long timestamp = 0L ); ``` Creates a new `AudioBuffer` from a managed array of linear PCM samples. This overload copies the input data. ### From a Native Array ```csharp AudioBuffer( int sampleRate, int channelCount, NativeArray data, long timestamp = 0L ); ``` Initializes an `AudioBuffer` from a Unity `NativeArray`. This overload avoids copying the sample buffer, but the native array must remain valid. ### From a Native Buffer ```csharp unsafe AudioBuffer( int sampleRate, int channelCount, float* data, int sampleCount, long timestamp = 0L ); ``` Initializes an `AudioBuffer` from a raw native pointer to sample data. This overload also avoids copying. ``` -------------------------------- ### Create Audio Handler with VideoKitAudioManager Source: https://www.videokit.ai/microphones Use the `VideoKitAudioManager` component to stream audio buffers from an `AudioDevice`. Register a handler for audio buffers and start streaming. ```csharp using UnityEngine; using VideoKit; public class AudioHandler : MonoBehaviour { public VideoKitAudioManager audioManager; private void Start() { // Register a handler for audio buffers audioManager.OnAudioBuffer += OnAudioBuffer; // Start streaming audioManager.StartRunning(); } private void OnAudioBuffer(AudioBuffer audioBuffer) { // Use the audio data Debug.Log($"Received {audioBuffer.sampleBuffer.Length} audio samples"); } } ``` -------------------------------- ### Start Multi-Camera Stream Source: https://www.videokit.ai/reference/multicameradevice Initiates streaming from all contained cameras, providing a handler to receive pixel buffers. The handler is invoked on a dedicated camera thread. ```csharp void StartRunning(Action handler); ``` -------------------------------- ### Create Realtime Clock: NatCorder vs VideoKit Source: https://www.videokit.ai/upgrades Demonstrates creating a realtime clock for recording. The API for creating a `RealtimeClock` remains the same between NatCorder and VideoKit. ```csharp using NatML.Recorders.Clocks; // NatCorder: Create a realtime clock var clock = new RealtimeClock(); ``` ```csharp using VideoKit.Clocks; // VideoKit: Create a realtime clock var clock = new RealtimeClock(); ``` -------------------------------- ### Get or Set Audio Device Source: https://www.videokit.ai/reference/videokitaudiomanager Specifies the audio device used for recording. This property can be used to get or set the active AudioDevice. ```csharp /// /// Get or set the audio device used for streaming. /// AudioDevice? device { get; set; } ``` -------------------------------- ### Set Camera White Balance Mode Source: https://www.videokit.ai/reference/cameradevice Get or set the white balance mode. Use `IsWhiteBalanceModeSupported` to check for support. ```csharp /// /// Get or set the white balance mode. /// WhiteBalanceMode whiteBalanceMode { get; set; } ``` -------------------------------- ### Get Timestamp Source: https://www.videokit.ai/reference/realtimeclock Retrieves the current timestamp in nanoseconds. ```APIDOC ## timestamp ### Description Current timestamp in nanoseconds. ### Method Get ### Endpoint RealtimeClock.timestamp ### Parameters None ### Response - **timestamp** (long) - The current elapsed time in nanoseconds. ``` -------------------------------- ### Current Exposure Sensitivity Source: https://www.videokit.ai/reference/cameradevice Get the current exposure sensitivity (ISO). ```APIDOC ## float ISO { get; } ``` -------------------------------- ### Current Exposure Duration Source: https://www.videokit.ai/reference/cameradevice Get the current exposure duration in seconds. ```APIDOC ## float exposureDuration { get; } ``` -------------------------------- ### Inspecting the Preview Rotation Source: https://www.videokit.ai/reference/videokitcameraview Get or set the rotation of the camera preview. ```APIDOC ## PixelBuffer.Rotation rotation ### Description Get or set the camera preview rotation. Pixel buffers are typically landscape left, and this property rotates them upright. It resets automatically when the component is enabled. ### Property - **rotation** (PixelBuffer.Rotation) - The rotation of the camera preview. ``` -------------------------------- ### Create Camera Source for Recording Source: https://www.videokit.ai/recorders Set up a `CameraSource` to capture pixel buffers from a game camera and a `RealtimeClock` for timestamps. The recorder accepts and records pixel buffers from this source. ```csharp // Create a clock to generate recording timestamps var clock = new RealtimeClock(); // Create a camera source var cameraSource = new CameraSource( recorder, // the recorder accepts and records pixel buffers from the source clock, // the clock is used to generate recording timestamps Camera.main // the camera source captures pixel buffers from one or more game cameras ); ``` -------------------------------- ### Exposure Sensitivity Range Source: https://www.videokit.ai/reference/cameradevice Get the supported range for exposure sensitivity (ISO). ```APIDOC ## (float min, float max) ISORange { get; } ``` -------------------------------- ### Exposure Duration Range Source: https://www.videokit.ai/reference/cameradevice Get the supported range for exposure duration in seconds. ```APIDOC ## (float min, float max) exposureDurationRange { get; } ``` -------------------------------- ### Create Screen Source Source: https://www.videokit.ai/reference/screensource Creates a screen source with specified dimensions, a handler for pixel buffers, and an optional clock for timestamps. Use `useLateUpdate` to control frame capture timing. ```csharp /// /// Create a screen source. /// /// Image width. /// Image height. /// Handler to receive images. /// Clock for generating image timestamps. /// Whether to use` LateUpdate` instead of end of frame for capturing frames. See #52. ScreenSource( int width, int height, Action handler, IClock? clock = null, bool useLateUpdate = false ); ``` -------------------------------- ### Get Current Exposure Sensitivity Source: https://www.videokit.ai/reference/cameradevice Retrieves the current exposure sensitivity (ISO). ```csharp /// /// Get the current exposure sensitivity. /// float ISO { get; } ``` -------------------------------- ### Using the Recorder Component (No Code) Source: https://www.videokit.ai/recorders This section describes how to use the VideoKitRecorder component for recording videos without writing custom code. It involves adding UI buttons to start and stop the recording process. ```APIDOC ## Using the Recorder Component ### Starting a Recording To start recording, invoke `VideoKitRecorder.StartRecording`. ### Stopping a Recording To stop recording, invoke `VideoKitRecorder.StopRecording`. ``` -------------------------------- ### Create a MediaRecorder Source: https://www.videokit.ai/reference/mediarecorder Use this method to create a media recorder instance. Specify the desired format and relevant settings like dimensions, frame rate, and bit rates. The prefix parameter allows organizing recordings into subdirectories. ```csharp static Task Create ( Format format, int width = 0, int height = 0, float frameRate = 0f, int sampleRate = 0, int channelCount = 0, int videoBitRate = 20_000_000, int keyframeInterval = 2, float compressionQuality = 0.8f, int audioBitRate = 64_000, string? prefix = null ); ``` -------------------------------- ### Get Current Exposure Duration Source: https://www.videokit.ai/reference/cameradevice Retrieves the current exposure duration in seconds. ```csharp /// /// Get the current exposure duration in seconds. /// float exposureDuration { get; } ``` -------------------------------- ### Pause/Resume Clock Source: https://www.videokit.ai/reference/realtimeclock Gets or sets a value indicating whether the clock is paused. ```APIDOC ## paused ### Description Whether the clock paused. ### Method Get/Set ### Endpoint RealtimeClock.paused ### Parameters #### Set Parameters - **paused** (bool) - Required - Set to true to pause the clock, false to resume. ``` -------------------------------- ### Get Device Name Source: https://www.videokit.ai/reference/mediadevice Retrieves the human-friendly display name of the media device. ```csharp /// /// Display friendly device name. /// string name { get; } ``` -------------------------------- ### Get Unique Device Identifier Source: https://www.videokit.ai/reference/mediadevice Retrieves the unique identifier of the media device. ```csharp /// /// Device unique ID. /// string uniqueId { get; } ``` -------------------------------- ### Create MediaAsset from StreamingAssets Source: https://www.videokit.ai/reference/mediaasset Create a media asset by loading from a file within the StreamingAssets folder. ```csharp /// /// Create a media asset from a file in `StreamingAssets`. /// /// Relative file path in `StreamingAssets`. /// Media asset. static Task FromStreamingAssets(string path); ``` -------------------------------- ### Create MediaAsset from File Source: https://www.videokit.ai/reference/mediaasset Creates a MediaAsset from a file on the local file system using its path. ```APIDOC ## FromFile ### Description Create a media asset from a file. ### Method Signature `static Task FromFile(string path)` ### Parameters #### Path Parameters - **path** (string) - Required - Path to media file. ``` -------------------------------- ### Timestamp Property Source: https://www.videokit.ai/reference/fixedclock Gets the current timestamp in nanoseconds, representing the elapsed time. ```APIDOC ## Timestamp Property ### Description Get the current timestamp in nanoseconds. ### Method GET ### Endpoint `/timestamp` ### Response #### Success Response (200) - **timestamp** (long) - The current elapsed time in nanoseconds. ``` -------------------------------- ### Managing Camera Stream Source: https://www.videokit.ai/reference/videokitcameramanager Control the camera stream by checking its status, starting, and stopping it. ```APIDOC ## Streaming Pixel Buffers ### Checking the Streaming Status #### Property ```csharp bool running { get; } ``` ### Description The `running` property reports whether the camera manager is currently streaming pixel buffers from the `device`. ### Starting the Stream #### Method ```csharp void StartRunning(); ``` ### Description Start streaming `PixelBuffer` instances from the camera device. The `OnPixelBuffer` event will be invoked with pixel buffers as they become available from the camera device. ### Stopping the Stream #### Method ```csharp void StopRunning(); ``` ### Description Stop streaming pixel buffers from the camera device. ``` -------------------------------- ### Create MediaAsset from Plain Text Source: https://www.videokit.ai/reference/mediaasset Create a media asset from plain text. The text will be written to a temporary file to ensure a valid path. ```csharp /// /// Create a media aseet from plain text. /// /// Text. /// Text asset. static Task FromText(string text); ``` -------------------------------- ### Get Exposure Sensitivity Range Source: https://www.videokit.ai/reference/cameradevice Retrieves the supported range for exposure sensitivity (ISO). ```csharp /// /// Exposure sensitivity range. /// (float min, float max) ISORange { get; } ``` -------------------------------- ### Get Exposure Duration Range Source: https://www.videokit.ai/reference/cameradevice Retrieves the supported range for exposure duration in seconds. ```csharp /// /// Exposure duration range in seconds. /// (float min, float max) exposureDurationRange { get; } ``` -------------------------------- ### Inspect Plane Row Stride Source: https://www.videokit.ai/reference/pixelbuffer Get the row stride in bytes for a specific plane. ```csharp /// /// Row stride in bytes. /// int Plane.rowStride { get; } ``` -------------------------------- ### Get Audio Device Location Source: https://www.videokit.ai/reference/audiodevice Retrieves the relative location of an audio device, if reported. ```csharp Location location { get; } ``` -------------------------------- ### Streaming Pixel Buffers Source: https://www.videokit.ai/multicameras Begin streaming pixel buffers from a multi-camera device by calling `MultiCameraDevice.StartRunning` and providing a callback function. ```APIDOC ## Streaming Pixel Buffers ### Description Start streaming pixel buffers from the multi-camera device by providing a callback function that will be invoked with pixel buffers as they become available. ### Method `multiCameraDevice.StartRunning(OnPixelBuffer)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp // Start streaming pixel buffers from the multi-camera multiCameraDevice.StartRunning(OnPixelBuffer); // Callback function invoked with pixel buffers void OnPixelBuffer(CameraDevice cameraDevice, PixelBuffer pixelBuffer) { // Process the pixel buffer here // Note: This callback is invoked on a dedicated camera thread, not the Unity main thread. } ``` ### Response #### Success Response (200) This method does not return a value directly, but invokes the provided callback `OnPixelBuffer` when pixel buffers are available. #### Response Example None directly from the method call. The `OnPixelBuffer` callback receives: - **cameraDevice** (CameraDevice) - The camera device that generated the pixel buffer. - **pixelBuffer** (PixelBuffer) - The captured pixel buffer data. ``` -------------------------------- ### Get Device Location Source: https://www.videokit.ai/reference/mediadevice Retrieves the location of the media device relative to the current device. ```csharp /// /// Device location. /// Location location { get; } ``` -------------------------------- ### Create MediaAsset from Generated Transcription (AudioClip) Source: https://www.videokit.ai/reference/mediaasset Create a media asset by transcribing the provided audio clip using a speech-to-text AI model. ```csharp /// /// Create a media asset by transcribing the provided audio clip. /// /// Audio clip to transcribe. /// Transcribed text asset. static Task FromGeneratedTranscription(AudioClip audio); ``` -------------------------------- ### Format Settings Source: https://www.videokit.ai/reference/videokitrecorder Configure the output format and recording actions for the video recorder. ```APIDOC ## Format Settings ### Specifying the Recording Format ```csharp 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 ```csharp bool prepareOnAwake { get; set; } ``` Preparing the recorder on `Awake` prevents a noticeable stutter that occurs on the very first recording. ### Specifying the Recording Action ```csharp RecordingAction recordingAction { get; set; } ``` The `recordingAction` is used to specify what happens once a recording session is completed. The following actions are currently supported: ```csharp [Flags] enum RecordingAction : int { None = 0, CameraRoll = 2, Share = 4, Playback = 8, Custom = 32, } ``` The `RecordingAction.Custom` mode is mutually exclusive with all other recording actions. ### Specifying a Recording Callback ```csharp UnityEvent 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 Stabilization Mode Source: https://www.videokit.ai/reference/cameradevice Gets or sets the video stabilization mode. Supports Off and Standard modes. ```APIDOC ## Video Stabilization Mode ### Description Gets or sets the video stabilization mode of the camera device. ### Property `VideoStabilizationMode videoStabilizationMode { get; set; }` ### Supported Modes - `Off`: Disabled video stabilization. - `Standard`: Standard video stabilization. ``` -------------------------------- ### Discover Available Audio Devices Source: https://www.videokit.ai/microphones After obtaining microphone permissions, discover available audio input devices using `AudioDevice.Discover`. This method returns an array of `AudioDevice` objects. ```csharp // Discover available audio devices AudioDevice[] audioDevices = await AudioDevice.Discover(); // Use the first audio device AudioDevice audioDevice = audioDevices[0]; ``` -------------------------------- ### Exposure Bias Range Source: https://www.videokit.ai/reference/cameradevice Get the supported range for exposure bias in EV (Exposure Value). ```APIDOC ## (float min, float max) exposureBiasRange { get; } ``` -------------------------------- ### Create Media Asset from File Source: https://www.videokit.ai/assets Loads a media asset from a specified file path. ```APIDOC ## Create Media Asset from File ### Description Loads a media asset from a specified file path. ### Method `MediaAsset.FromFile(string path)` ### Parameters #### Path Parameters - **path** (string) - Required - The path to the media file. ### Response #### Success Response - **asset** (MediaAsset) - The loaded media asset. ### Request Example ```csharp string path = "/tmp/video.mp4"; MediaAsset asset = await MediaAsset.FromFile(path); ``` ``` -------------------------------- ### Get Exposure Bias Range Source: https://www.videokit.ai/reference/cameradevice Retrieves the supported range for exposure bias in EV units. ```csharp /// /// Exposure bias range in EV. /// (float min, float max) exposureBiasRange { get; } ``` -------------------------------- ### Create MP4 Recorder: NatCorder vs VideoKit Source: https://www.videokit.ai/upgrades Compare how to instantiate an MP4 recorder in NatCorder versus VideoKit. VideoKit uses a unified `MediaRecorder.Create` method with a specified format. ```csharp using NatML.Recorders; // NatCorder: Create an MP4 recorder IMediaRecorder recorder = new MP4Recorder( width: 1920, height: 1080, frameRate: 30f, sampleRate: 48_000, channelCount: 2 ); ``` ```csharp using VideoKit; // VideoKit: Create an MP4 recorder var recorder = await MediaRecorder.Create( format: MediaRecorder.Format.MP4, width: 1920, height: 1080, frameRate: 30f, sampleRate: 48_000, channelCount: 2 ); ``` -------------------------------- ### Prepare on Awake Property Source: https://www.videokit.ai/reference/videokitrecorder Prepares hardware encoders on awake to prevent stuttering on the first recording. ```csharp /// /// Prepare the hardware encoders on awake. /// bool prepareOnAwake { get; set; } ``` -------------------------------- ### Get Media Asset Type Source: https://www.videokit.ai/reference/mediaasset Retrieves the media type of the asset. This property is always available. ```csharp /// /// Get the asset media type. /// MediaType type { get; } ``` -------------------------------- ### Inspect Buffer Timestamp Source: https://www.videokit.ai/reference/pixelbuffer Get the timestamp of the pixel buffer in nanoseconds. The timebase depends on the source. ```csharp /// /// Pixel buffer timestamp in nanoseconds. /// long timestamp { get; } ``` -------------------------------- ### Inspect Plane Height Source: https://www.videokit.ai/reference/pixelbuffer Get the height of a specific plane. This is useful for formats with sub-sampled planes. ```csharp /// /// Plane height. /// int Plane.height { get; } ``` -------------------------------- ### Create Media Asset from File Source: https://www.videokit.ai/assets Use this method to create a MediaAsset object from a local file path. Ensure the file exists at the specified path. ```csharp // Create a media asset from a file string path = "/tmp/video.mp4"; MediaAsset asset = await MediaAsset.FromFile(path); ``` -------------------------------- ### Share Image with NatShare Source: https://www.videokit.ai/upgrades Create a `SharePayload`, add an image, and call `Share` to share media with NatShare. ```csharp using NatML.Sharing; // NatShare: Share an image Texture2D image = ...; using var payload = new SharePayload(); payload.AddImage(image); await payload.Share(); ``` -------------------------------- ### Inspect Plane Width Source: https://www.videokit.ai/reference/pixelbuffer Get the width of a specific plane. This is useful for formats with sub-sampled planes. ```csharp /// /// Plane width. /// int Plane.width { get; } ``` -------------------------------- ### Create Realtime Clock Instance Source: https://www.videokit.ai/reference/realtimeclock Initializes a new instance of the RealtimeClock. The clock will initialize its internal state upon creation. ```csharp /// /// Create a realtime clock. /// RealtimeClock(); ``` -------------------------------- ### Get Audio Channel Count Source: https://www.videokit.ai/reference/mediarecorder Retrieves the number of audio channels supported by the media recorder. ```csharp /// /// Get the audio channel count. /// int channelCount { get; } ``` -------------------------------- ### PixelBuffer Constructors Source: https://www.videokit.ai/reference/pixelbuffer Demonstrates how to create a PixelBuffer from different data sources including managed memory, native arrays, native pointers, and textures. ```APIDOC ## PixelBuffer Constructors ### From an Managed Buffer ```csharp PixelBuffer( int width, int height, Format format, byte[] data, int rowStride = 0, long timestamp = 0L, bool mirrored = false ); ``` ### From a Native Array ```csharp PixelBuffer( int width, int height, Format format, NativeArray data, int rowStride = 0, long timestamp = 0L, bool mirrored = false ); ``` ### From a Native Buffer ```csharp unsafe PixelBuffer( int width, int height, Format format, byte* data, int rowStride = 0, long timestamp = 0L, bool mirrored = false ); ``` ### From a Texture ```csharp PixelBuffer(Texture2D texture, long timestamp = 0L); ``` ``` -------------------------------- ### Set Camera Torch Mode Source: https://www.videokit.ai/reference/cameradevice Get or set the torch mode. Ensure torch is supported before enabling. ```csharp /// /// Get or set the torch mode. /// TorchMode torchMode { get; set; } ``` ```csharp /// /// Torch mode. /// enum TorchMode : int { /// /// Disabled torch. /// Off = 0, /// /// Maximum supported torch level. /// Maximum = 100 } ``` ```csharp /// /// Whether torch is supported. /// bool torchSupported { get; } ``` -------------------------------- ### Create MediaAsset from Generated Transcription (FilePath) Source: https://www.videokit.ai/reference/mediaasset Create a media asset by transcribing an audio file directly from its path using a speech-to-text AI model. ```csharp /// /// Create a media asset by transcribing the provided audio file. /// /// Path to audio file. /// Transcribed text asset. static Task FromGeneratedTranscription(string path); ``` -------------------------------- ### Exposure Bias Source: https://www.videokit.ai/reference/cameradevice Get or set the exposure bias. The value must be within the range returned by `exposureRange`. ```APIDOC ## float exposureBias { get; set; } ``` -------------------------------- ### Accessing the VideoKitClient Instance Source: https://www.videokit.ai/reference/videokitclient Access the singleton instance of the VideoKit client for the current project. This instance manages the global state. ```csharp /// /// VideoKit client for this project. /// static VideoKitClient? Instance { get; } ``` -------------------------------- ### Set Focus Mode Source: https://www.videokit.ai/reference/cameradevice Gets or sets the focus mode. Use `IsFocusModeSupported` to check compatibility before setting. ```csharp /// /// Get or set the focus mode. /// FocusMode focusMode { get; set; } ``` -------------------------------- ### Get Video Frame Rate Source: https://www.videokit.ai/reference/mediaasset Retrieves the frame rate of a video asset. Only populated for Video types. ```csharp /// /// Video frame rate. /// float frameRate { get; } ``` -------------------------------- ### Finish Recording: NatCorder vs VideoKit Source: https://www.videokit.ai/upgrades Illustrates the process of finalizing a recording. NatCorder returns a file path, while VideoKit returns a `MediaAsset` object containing the path and other metadata. ```csharp // NatCorder: Finish recording string path = await recorder.FinishWriting(); ``` ```csharp // VideoKit: Finish recording MediaAsset asset = await recorder.FinishWriting(); string path = asset.path; ``` -------------------------------- ### Get Media Asset Path Source: https://www.videokit.ai/reference/mediaasset Retrieves the file path of the media asset. This is null for sequence assets. ```csharp /// /// Path to media asset. /// string? path { get; } ``` -------------------------------- ### Create MediaAsset from Text Source: https://www.videokit.ai/reference/mediaasset Creates a MediaAsset from plain text. The text is written to a temporary file. ```APIDOC ## FromText ### Description Create a media asset from plain text. ### Method Signature `static Task FromText(string text)` ### Parameters #### Path Parameters - **text** (string) - Required - The text content for the media asset. ``` -------------------------------- ### Get Audio Device Name Source: https://www.videokit.ai/reference/audiodevice Retrieves the display-friendly name of an audio device, suitable for user interfaces. ```csharp string name { get; } ``` -------------------------------- ### Get Audio Device Unique ID Source: https://www.videokit.ai/reference/audiodevice Retrieves the unique identifier for an audio device, which is reported as a string. ```csharp string uniqueId { get; } ``` -------------------------------- ### Discovering Multi-Camera Devices Source: https://www.videokit.ai/multicameras After obtaining camera permissions, discover available multi-camera devices using the `MultiCameraDevice.Discover` method. ```APIDOC ## Discovering Camera Devices ### Description Discover available multi-camera devices using the `MultiCameraDevice.Discover` method after camera permissions have been granted. ### Method `MultiCameraDevice.Discover()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using System.Linq; // Discover available multi-camera devices MultiCameraDevice[] multiCameraDevices = await MultiCameraDevice.Discover(); // Use the first multi-camera device MultiCameraDevice multiCameraDevice = multiCameraDevices.FirstOrDefault(); ``` ### Response #### Success Response (200) - **multiCameraDevices** (MultiCameraDevice[]) - An array of discovered multi-camera devices. #### Response Example ```json [ { "id": "device_id_1", "name": "Front Camera", "isFrontFacing": true }, { "id": "device_id_2", "name": "Back Camera", "isFrontFacing": false } ] ``` ``` -------------------------------- ### Set Camera Flash Mode Source: https://www.videokit.ai/reference/cameradevice Get or set the photo flash mode. Ensure flash is supported before setting. ```csharp /// /// Get or set the photo flash mode. /// FlashMode flashMode { get; set; } ``` ```csharp /// /// Photo flash mode. /// enum FlashMode : int { /// /// Never use flash. /// Off = 0, /// /// Always use flash. /// On = 1, /// /// Let the sensor detect if it needs flash. /// Auto = 2 } ``` ```csharp /// /// Whether flash is supported for photo capture. /// bool flashSupported { get; } ``` -------------------------------- ### Accessing the App's Instance Source: https://www.videokit.ai/reference/videokitclient The singleton instance of VideoKitClient can be accessed via the static Instance property. ```APIDOC ## Accessing the App's Instance ```csharp static VideoKitClient? Instance { get; } ``` The singleton instance can be accessed with this property. ``` -------------------------------- ### White Balance Mode Source: https://www.videokit.ai/reference/cameradevice Gets or sets the white balance mode of the camera. Supports Continuous and Locked modes. ```APIDOC ## White Balance Mode ### Description Gets or sets the white balance mode of the camera device. ### Property `WhiteBalanceMode whiteBalanceMode { get; set; }` ### Supported Modes - `Continuous`: Continuous auto white balance. - `Locked`: Locked auto white balance. ``` -------------------------------- ### Share Image with VideoKit Source: https://www.videokit.ai/upgrades Create a `MediaAsset` from a texture and call `MediaAsset.Share` to share an image with VideoKit. ```csharp using VideoKit; // VideoKit: Share an image Texture2D image = ...; MediaAsset asset = await MediaAsset.FromTexture(image); await asset.Share(); ``` -------------------------------- ### Check Supported Buffers (Instance Method) Source: https://www.videokit.ai/reference/mediarecorder Checks if the media recorder instance supports appending sample buffers of a specific type. ```APIDOC ## Checking for Supported Buffers (Instance Method) ### Description Check whether the media recorder supports appending sample buffers of the given type. ### Method `bool CanAppend() where T : AudioBuffer | PixelBuffer;` ### Type Parameters * `T`: Sample buffer type. ### Returns Whether the media recorder supports appending sample buffers of the given type. ### Remarks Recorders can be queried on whether they support appending sample buffers of a given type, depending on the recording `format`. ``` -------------------------------- ### Zoom Ratio Source: https://www.videokit.ai/reference/cameradevice Gets or sets the zoom ratio of the camera. The value must be within the range provided by `zoomRange`. ```APIDOC ## Zoom Ratio ### Description Gets or sets the zoom ratio of the camera device. ### Property `float zoomRatio { get; set; }` ### Remarks This value must be in the range returned by `zoomRange`. ``` -------------------------------- ### Set Exposure Bias Source: https://www.videokit.ai/reference/cameradevice Gets or sets the exposure bias. The value must be within the range returned by `exposureRange`. ```csharp /// /// Get or set the exposure bias. /// This value must be in the range returned by `exposureRange`. /// float exposureBias { get; set; } ``` -------------------------------- ### Create MediaAsset from AudioClip Source: https://www.videokit.ai/reference/mediaasset Create a media asset from an AudioClip instance. This requires an active VideoKit plan as the clip is encoded to an audio file. ```csharp /// /// Create a media aseet from an audio clip. /// NOTE: This requires an active VideoKit plan. /// /// Audio clip. /// Media format used to encode the audio. /// Audio asset. static Task FromAudioClip( AudioClip clip, MediaRecorder.Format format = MediaRecorder.Format.WAV ); ``` -------------------------------- ### Get Media Duration Source: https://www.videokit.ai/reference/mediaasset Retrieves the duration of a video or audio asset in seconds. Only populated for Video and Audio types. ```csharp /// /// Video or audio duration in seconds. /// float duration { get; } ``` -------------------------------- ### Set Audio Sample Rate Source: https://www.videokit.ai/reference/audiodevice Gets or sets the preferred audio sample rate for streamed AudioBuffer instances. ```csharp int sampleRate { get; set; } ``` -------------------------------- ### Stream Camera Preview as Pixel Buffer with NatDevice Source: https://www.videokit.ai/upgrades Use `PixelBufferOutput` to convert camera device output into an RGBA8888 pixel buffer with NatDevice. ```csharp using NatML.Devices; using NatML.Devices.Outputs; // NatDevice: Stream the camera preview as an RGBA8888 pixel buffer void OnCameraImage(CameraImage image) { PixelBufferOutput output = new PixelBufferOutput(); output.Update(image); NativeArray pixelBuffer = output.pixelBuffer; // RGBA8888 } cameraDevice.StartRunning(OnCameraImage); ``` -------------------------------- ### Set Photo Resolution Source: https://www.videokit.ai/cameras Configures the desired resolution for high-resolution photo captures. This must be set before starting the camera preview. ```csharp // Set the photo resolution cameraDevice.photoResolution = (3840, 2160); ``` -------------------------------- ### Finish Writing Source: https://www.videokit.ai/reference/mediarecorder Finalizes the recording session and returns the recorded media asset. ```APIDOC ## Finishing a Recording Session ### Description Finish writing. ### Method `Task FinishWriting();` ### Returns Recorded media asset. ### Remarks Once all media buffers have been appended, this method finishes writing asynchronously, returning the recorded media file as a `MediaAsset`. ``` -------------------------------- ### Save Image to Camera Roll with NatShare Source: https://www.videokit.ai/upgrades Create a `SavePayload`, add an image, and call `Save` to save media to the camera roll with NatShare. ```csharp using NatML.Sharing; // NatShare: Save an image Texture2D image = ...; using var payload = new SavePayload(); payload.AddImage(image); await payload.Save(); ```