public override bool BeginRecording(RecordingSession session) { if (!base.BeginRecording(session)) { return(false); } m_Settings.m_DestinationPath.CreateDirectory(); return(true); }
public override void RecordFrame(RecordingSession session) { if (m_Inputs.Count != 1) { throw new Exception("Unsupported number of sources"); } var input = (BaseRenderTextureInput)m_Inputs[0]; var width = input.outputRT.width; var height = input.outputRT.height; var tex = new Texture2D(width, height, m_Settings.m_OutputFormat != PNGRecordeOutputFormat.EXR ? TextureFormat.RGBA32 : TextureFormat.RGBAFloat, false); var backupActive = RenderTexture.active; RenderTexture.active = input.outputRT; tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); RenderTexture.active = backupActive; byte[] bytes; string ext; switch (m_Settings.m_OutputFormat) { case PNGRecordeOutputFormat.PNG: bytes = tex.EncodeToPNG(); ext = "png"; break; case PNGRecordeOutputFormat.JPEG: bytes = tex.EncodeToJPG(); ext = "jpg"; break; case PNGRecordeOutputFormat.EXR: bytes = tex.EncodeToEXR(); ext = "exr"; break; default: throw new ArgumentOutOfRangeException(); } UnityHelpers.Destroy(tex); var fileName = m_Settings.m_BaseFileName.BuildFileName(session, recordedFramesCount, width, height, ext); var path = Path.Combine(m_Settings.m_DestinationPath.GetFullPath(), fileName); File.WriteAllBytes(path, bytes); }
public override void RecordFrame(RecordingSession session) { if (m_Inputs.Count != 1) { throw new Exception("Unsupported number of sources"); } var input = (BaseRenderTextureInput)m_Inputs[0]; var width = input.outputRT.width; var height = input.outputRT.height; var tex = new Texture2D(width, height, m_Settings.m_OutputFormat != PNGRecordeOutputFormat.EXR ? TextureFormat.RGBA32 : TextureFormat.RGBAFloat, false); var backupActive = RenderTexture.active; RenderTexture.active = input.outputRT; tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); RenderTexture.active = backupActive; //var tex = ScreenCapture.CaptureScreenshotAsTexture(); byte[] bytes; switch (m_Settings.m_OutputFormat) { case PNGRecordeOutputFormat.PNG: bytes = tex.EncodeToPNG(); break; case PNGRecordeOutputFormat.JPEG: bytes = tex.EncodeToJPG(); break; case PNGRecordeOutputFormat.EXR: bytes = tex.EncodeToEXR(); break; default: throw new ArgumentOutOfRangeException(); } UnityHelpers.Destroy(tex); if (!Directory.Exists(m_Settings.m_DestinationPath)) { Directory.CreateDirectory(m_Settings.m_DestinationPath); } File.WriteAllBytes(MakeFileName(session), bytes); }
public virtual bool BeginRecording(RecordingSession session) { if (recording) { throw new Exception("Already recording!"); } if (settings.m_Verbose) { Debug.Log(string.Format("Recorder {0} starting to record", GetType().Name)); } return(recording = true); }
public void OnDisable() { if (session != null) { session.Dispose(); session = null; #if UNITY_EDITOR if (autoExitPlayMode) { UnityEditor.EditorApplication.isPlaying = false; } #endif } }
public void SignalSourcesOfStage(ERecordingSessionStage stage, RecordingSession session) { switch (stage) { case ERecordingSessionStage.BeginRecording: foreach (var input in m_Inputs) { input.BeginRecording(session); } break; case ERecordingSessionStage.NewFrameStarting: foreach (var input in m_Inputs) { input.NewFrameStarting(session); } break; case ERecordingSessionStage.NewFrameReady: foreach (var input in m_Inputs) { input.NewFrameReady(session); } break; case ERecordingSessionStage.FrameDone: foreach (var input in m_Inputs) { input.FrameDone(session); } break; case ERecordingSessionStage.EndRecording: foreach (var input in m_Inputs) { input.EndRecording(session); } break; default: throw new ArgumentOutOfRangeException("stage", stage, null); } }
public string BuildFileName(RecordingSession session, int frame, int width, int height, string ext) { if (string.IsNullOrEmpty(m_projectName)) { #if UNITY_EDITOR var parts = Application.dataPath.Split('/'); m_projectName = parts[parts.Length - 2]; #else m_projectName = "N/A"; #endif } var regEx = new Regex("(<0*>)"); var match = regEx.Match(pattern); if (match.Success) { m_FramePattern = match.Value; m_FramePatternDst = m_FramePattern.Substring(1, m_FramePattern.Length - 2); } else { m_FramePattern = "<0>"; m_FramePatternDst = "0"; } var fileName = pattern.Replace(tags[(int)ETags.Extension], ext) .Replace(tags[(int)ETags.Resolution], string.Format("{0}x{1}", width, height)) .Replace(m_FramePattern, frame.ToString(m_FramePatternDst)) .Replace(tags[(int)ETags.Scene], SceneManager.GetActiveScene().name) .Replace(tags[(int)ETags.Project], m_projectName) #if UNITY_EDITOR .Replace(tags[(int)ETags.Product], UnityEditor.PlayerSettings.productName) #else .Replace(tags[(int)ETags.Product], "(prd-NA)") #endif .Replace(tags[(int)ETags.Time], string.Format("{0}h{1}m", session.m_SessionStartTS.ToString("hh"), session.m_SessionStartTS.ToString("mm"))) .Replace(tags[(int)ETags.Date], session.m_SessionStartTS.ToShortDateString().Replace('/', '-')) ; return(fileName); }
// returns true if recording is starting. false if failed to begin recording or was already recording public virtual bool BeginRecording(RecordingSession session) { if (recording) { return(false); } if (settings.m_Verbose) { Debug.Log(string.Format("Recorder {0} starting to record", GetType().Name)); } m_OriginalCaptureFrameRate = Time.captureFramerate; var fixedRate = settings.m_FrameRateMode == FrameRateMode.Constant ? (int)settings.m_FrameRate : m_OriginalCaptureFrameRate; if (fixedRate != m_OriginalCaptureFrameRate) { if (Time.captureFramerate > 0) { Debug.LogWarning(string.Format("Frame Recorder {0} is set to record at a fixed rate and another component has already set a conflicting value for [Time.captureFramerate], new value being applied : {1}!", GetType().Name, fixedRate)); } Time.captureFramerate = (int)fixedRate; if (settings.m_Verbose) { Debug.Log("Frame recorder set fixed frame rate to " + fixedRate); } } m_Inputs = new List <RecorderInput>(); foreach (var inputSettings in settings.m_SourceSettings) { var input = Activator.CreateInstance(inputSettings.inputType) as RecorderInput; input.settings = inputSettings; m_Inputs.Add(input); } return(recording = true); }
public virtual void SessionCreated(RecordingSession session) { }
public virtual void NewFrameReady(RecordingSession session) { }
public virtual void PrepareNewFrame(RecordingSession ctx) { }
public virtual bool SkipFrame(RecordingSession ctx) { return(!recording || (ctx.m_FrameIndex % settings.m_CaptureEveryNthFrame) != 0); }
public abstract void RecordFrame(RecordingSession ctx);
public virtual void BeginRecording(RecordingSession session) { }
public virtual void EndRecording(RecordingSession session) { }
public virtual void FrameDone(RecordingSession session) { }
public virtual void NewFrameStarting(RecordingSession session) { }