Last active
July 31, 2018 16:56
-
-
Save caseypugh/b2b1e2a0fd4eb4f6e825d8bbc8b674be to your computer and use it in GitHub Desktop.
How to synchronize playback and recording with the Vimeo Unity SDK.
This file contains 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
using UnityEngine; | |
using Vimeo.Recorder; | |
using Vimeo.Player; | |
using System.Collections; | |
namespace Vimeo.Recorder | |
{ | |
public class SyncRecorderAndPlayer : MonoBehaviour { | |
private VimeoRecorder recorder; | |
public VimeoPlayer vimeoPlayer; | |
public bool syncDuration = false; | |
void Awake() | |
{ | |
vimeoPlayer.OnVideoStart += VideoStart; | |
} | |
void Start() | |
{ | |
recorder = gameObject.GetComponent<VimeoRecorder>(); | |
recorder.defaultVideoInput = Vimeo.Recorder.VideoInputType.Screen; | |
recorder.frameRate = 30; | |
recorder.realTime = false; | |
} | |
void VideoStart() | |
{ | |
recorder.videoName = vimeoPlayer.videoName + " (Tiny Planet)"; | |
// Setup the video controller to inform us when a new frame is being displayed | |
vimeoPlayer.controller.SendFrameReadyEvents(); | |
vimeoPlayer.controller.EnableFrameStepping(); | |
vimeoPlayer.controller.OnFrameReady += FrameReady; | |
// Sync the frame rate and record duration to the video. Not necessary, but nice to have | |
recorder.frameRate = (int)vimeoPlayer.controller.videoPlayer.frameRate; | |
if (syncDuration) { | |
recorder.recordMode = Vimeo.Recorder.RecordMode.Duration; | |
recorder.recordDuration = vimeoPlayer.controller.GetDuration(); | |
} | |
// This method is used specifically for letting us trigger when we want to capture | |
recorder.BeginManualRecording(); | |
} | |
void FrameReady(VideoController controller) | |
{ | |
// When the frame is ready, we will manually trigger the recorder to capture the frame | |
StartCoroutine(RecordFrame()); | |
} | |
IEnumerator RecordFrame() | |
{ | |
yield return new WaitForEndOfFrame(); | |
recorder.encoder.AddFrame(); | |
} | |
void OnDisable() | |
{ | |
if (vimeoPlayer != null) { | |
vimeoPlayer.controller.OnFrameReady -= FrameReady; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment