Last active
April 9, 2020 03:54
-
-
Save olokobayusuf/a4f13816f8808bae74996221220102a3 to your computer and use it in GitHub Desktop.
Pseudocode example illustrating recording multiple game cameras with NatCorder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * NatCorder | |
| * Copyright (c) 2019 Yusuf Olokoba | |
| */ | |
| namespace NatCorder.Inputs { | |
| using UnityEngine; | |
| using System; | |
| using Clocks; | |
| using Dispatch; | |
| /// <summary> | |
| /// Recorder input for recording multiple game cameras | |
| /// </summary> | |
| public sealed class MultiCameraInput : IDisposable { | |
| #region --Client API-- | |
| /// <summary> | |
| /// Create a video recording input from multiple game cameras | |
| /// </summary> | |
| /// <param name="mediaRecorder">Media recorder to receive committed frames</param> | |
| /// <param name="clock">Clock for generating timestamps</param> | |
| /// <param name="cameras">Game cameras to record</param> | |
| public static MultiCameraInput Create (IMediaRecorder mediaRecorder, IClock clock, params Camera[] cameras) { | |
| if (mediaRecorder == null) { | |
| Debug.LogError("NatCorder Error: Cannot create camera input for null media recorder"); | |
| return null; | |
| } | |
| if (clock == null) { | |
| Debug.LogError("NatCorder Error: Cannot create multi-camera recorder with no clock"); | |
| return null; | |
| } | |
| if (cameras.Length < 2) { | |
| Debug.LogError("NatCorder Error: Cannot create multi-camera recorder with less than two cameras"); | |
| return null; | |
| } | |
| return new MultiCameraInput(mediaRecorder, clock, cameras); | |
| } | |
| /// <summary> | |
| /// Stop recorder input and teardown resources | |
| /// </summary> | |
| public void Dispose () { | |
| DispatchUtility.onFrame -= OnFrame; | |
| } | |
| #endregion | |
| #region --Operations-- | |
| private readonly IMediaRecorder mediaRecorder; | |
| private readonly IClock clock; | |
| private readonly Camera[] cameras; | |
| private MultiCameraRecorder (IMediaRecorder mediaRecorder, IClock clock, Camera[] cameras) { | |
| this.mediaRecorder = mediaRecorder; | |
| this.clock = clock; | |
| this.cameras = cameras; | |
| DispatchUtility.onFrame += OnFrame; | |
| } | |
| private void OnFrame () { | |
| var encoderFrame = mediaRecorder.AcquireFrame(); | |
| foreach (var camera in cameras) { | |
| var prevTarget = camera.targetTexture; | |
| camera.targetTexture = encoderFrame; | |
| camera.Render(); | |
| camera.targetTexture = prevTarget; | |
| } | |
| mediaRecorder.CommitFrame(encoderFrame, clock.Timestamp); | |
| } | |
| #endregion | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am getting the error Assets\Scripts\MultiCameraInput.cs(12,11): error CS0246: The type or namespace name 'Dispatch' could not be found (are you missing a using directive or an assembly reference?).