public override void EndRecording() { if (m_encoder != null) { m_encoder.Release(); m_encoder = null; } if (m_cb != null) { GetComponent <Camera>().RemoveCommandBuffer(CameraEvent.AfterEverything, m_cb); m_cb.Release(); m_cb = null; } if (m_scratchBuffer != null) { m_scratchBuffer.Release(); m_scratchBuffer = null; } if (m_recording) { Debug.Log("MovieRecorder: EndRecording()"); } base.EndRecording(); }
public void Initialize(MovieEncoderConfigs c, DataPath p) { string path = p.GetFullPath() + "/" + m_name; c.Setup(m_rt.width, m_rt.height, m_channels, m_targetFramerate); m_encoder = MovieEncoder.Create(c, path); }
public void Release() { if (m_encoder != null) { m_encoder.Release(); m_encoder = null; } }
public override bool BeginRecording() { if (m_recording) { return(false); } if (m_shCopy == null) { Debug.LogError("MovieRecorder: copy shader is missing!"); return(false); } if (m_captureTarget == CaptureTarget.RenderTexture && m_targetRT == null) { Debug.LogError("MovieRecorder: target RenderTexture is null!"); return(false); } m_outputDir.CreateDirectory(); if (m_quad == null) { m_quad = fcAPI.CreateFullscreenQuad(); } if (m_matCopy == null) { m_matCopy = new Material(m_shCopy); } var cam = GetComponent <Camera>(); if (cam.targetTexture != null) { m_matCopy.EnableKeyword("OFFSCREEN"); } else { m_matCopy.DisableKeyword("OFFSCREEN"); } // create scratch buffer { int captureWidth = cam.pixelWidth; int captureHeight = cam.pixelHeight; GetCaptureResolution(ref captureWidth, ref captureHeight); if (m_encoderConfigs.format == MovieEncoder.Type.MP4 || m_encoderConfigs.format == MovieEncoder.Type.WebM) { captureWidth = (captureWidth + 1) & ~1; captureHeight = (captureHeight + 1) & ~1; } m_scratchBuffer = new RenderTexture(captureWidth, captureHeight, 0, RenderTextureFormat.ARGB32); m_scratchBuffer.wrapMode = TextureWrapMode.Repeat; m_scratchBuffer.Create(); } // initialize encoder { int targetFramerate = 60; if (m_framerateMode == FrameRateMode.Constant) { targetFramerate = m_targetFramerate; } string outPath = m_outputDir.GetFullPath() + "/" + DateTime.Now.ToString("yyyyMMdd_HHmmss"); m_encoderConfigs.captureVideo = m_captureVideo; m_encoderConfigs.captureAudio = m_captureAudio; m_encoderConfigs.Setup(m_scratchBuffer.width, m_scratchBuffer.height, 3, targetFramerate); m_encoder = MovieEncoder.Create(m_encoderConfigs, outPath); if (m_encoder == null || !m_encoder.IsValid()) { EndRecording(); return(false); } } // create command buffer { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb = new CommandBuffer(); m_cb.name = "MovieRecorder: copy frame buffer"; if (m_captureTarget == CaptureTarget.FrameBuffer) { m_cb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Bilinear); m_cb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb.SetRenderTarget(m_scratchBuffer); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_matCopy, 0, 0); m_cb.ReleaseTemporaryRT(tid); } else if (m_captureTarget == CaptureTarget.RenderTexture) { m_cb.SetRenderTarget(m_scratchBuffer); m_cb.SetGlobalTexture("_TmpRenderTarget", m_targetRT); m_cb.DrawMesh(m_quad, Matrix4x4.identity, m_matCopy, 0, 1); } cam.AddCommandBuffer(CameraEvent.AfterEverything, m_cb); } base.BeginRecording(); Debug.Log("MovieRecorder: BeginRecording()"); return(true); }