Search Results for

    Show / Hide Table of Contents

    Scripting

    Before are some useful scripting examples:

    Codec Scripting

        // Iterate over found video codecs
        foreach (Codec codec in CodecManager.VideoCodecs)
        {
            Debug.Log(codec.Name + " - " codec.Index);
        }
    
        // Searching for a specific codec
        Codec h264Codec = CodecManager.FindCodec(CodecType.Video, "H264");
        Codec aacCodec = CodecManager.FindCodec(CodecType.Audio, "AAC");
        if (h264Codec != null && aacCodec != null)
        {
            Debug.Log("Codecs found");
        }
    
        // Assign a specific codec for capture
        capture.NativeForceVideoCodecIndex = h264Codec.Index;
        capture.NativeForceAudioCodecIndex = aacCodec.Index;
    
        // Set a list of acceptable codecs to use, instead of specifying one directly
        capture.NativeForceVideoCodecIndex = -1;
        capture.VideoCodecPriorityWindows = new string[] { "H264", "HEVC" };
    

    Audio Input Device Scripting

        // Iterate over found audio input devices
        foreach (Device device in DeviceManager.AudioInputDevices)
        {
            Debug.Log(device.Name + " - " codec.Index);
        }
    
        // Search for a specific device
        if (CodecManager.AudioInputDevices.Count > 0)
        {
            Device firstDevice = CodecManager.AudioInputDevices.Devices[0];
            if (firstDevice != null)
            {
                Debug.Log("Device found");
            }
        }
    
        // Assign a device for audio capture
        capture.AudioCaptureSource = AudioCaptureSource.Microphone;
        capture.ForceAudioInputDeviceIndex = firstDevice.Index;
    

    Capture From Screen

    using UnityEngine;
    using RenderHeads.Media.AVProMovieCapture;
    
    public class ScreenCaptureExample : MonoBehaviour
    {
        void Start()
        {
            GameObject go = new GameObject();
            CaptureFromScreen capture = go.AddComponent<CaptureFromScreen>();
            capture.IsRealTime = false;
            capture.FrameRate = 60f;
            capture.StopMode = StopMode.FramesEncoded;
            capture.StopAfterFramesElapsed = capture.FrameRate * 10f;
            capture.NativeForceVideoCodecIndex = -1;
            capture.VideoCodecPriorityWindows = new string[] { "H264", "HEVC" };
            capture.StartCapture();
        }
    
        void Update()
        {
            if (KeyCode.GetKeyDown(KeyCode.S))
            {
                _capture.StartCapture();
            }
            if (KeyCode.GetKeyDown(KeyCode.S))
            {
                _capture.StopCapture();
            }
        }
    }
    
    In This Article