예제 #1
0
            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);
            }
예제 #2
0
        public bool BeginRecording()
        {
            if (m_recording)
            {
                return(false);
            }

            m_outputDir.CreateDirectory();

            // initialize encoder
            {
                string outPath = m_outputDir.GetFullPath() + "/" + DateTime.Now.ToString("yyyyMMdd_HHmmss");

                m_encoderConfigs.Setup();
                m_encoder = AudioEncoder.Create(m_encoderConfigs, outPath);
                if (m_encoder == null)
                {
                    EndRecording();
                    return(false);
                }
            }

            m_recording = true;
            Debug.Log("AudioMRecorder: BeginRecording()");
            return(true);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool ro = property.FindPropertyRelative("m_readOnly").boolValue;

            if (ro)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            float buttonWidth = 22;
            float rootWidth   = 70;
            float leafWidth   = position.width - rootWidth - 5 - buttonWidth;
            var   rootRect    = new Rect(position.x, position.y, rootWidth, position.height);
            var   leafRect    = new Rect(position.x + rootWidth + 5, position.y, leafWidth, position.height);
            var   buttonRect  = new Rect(position.x + rootWidth + 5 + leafWidth, position.y, buttonWidth, position.height);

            var pRoot = property.FindPropertyRelative("m_root");
            var pLeaf = property.FindPropertyRelative("m_leaf");

            EditorGUI.PropertyField(rootRect, pRoot, GUIContent.none);
            EditorGUI.PropertyField(leafRect, pLeaf, GUIContent.none);
            if (GUI.Button(buttonRect, "..."))
            {
                var tmp  = new DataPath((DataPath.Root)pRoot.intValue, pLeaf.stringValue);
                var path = EditorUtility.OpenFolderPanel("Select Directory", tmp.GetFullPath(), "");
                if (path.Length > 0)
                {
                    var newPath = new DataPath(path);
                    pRoot.intValue    = (int)newPath.root;
                    pLeaf.stringValue = newPath.leaf;
                }
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();

            if (ro)
            {
                EditorGUI.EndDisabledGroup();
            }
        }
예제 #4
0
        public 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");
            }


            m_numVideoFrames = 0;

            // create scratch buffer
            {
                int targetWidth   = cam.pixelWidth;
                int targetHeight  = cam.pixelHeight;
                int captureWidth  = targetWidth;
                int captureHeight = targetHeight;

                if (m_resolutionWidth > 0)
                {
                    captureWidth  = m_resolutionWidth;
                    captureHeight = (int)((float)m_resolutionWidth / ((float)targetWidth / (float)targetHeight));
                }
                else if (m_resolutionWidth < 0)
                {
                    int div = System.Math.Abs(m_resolutionWidth);
                    captureWidth  = targetWidth / div;
                    captureHeight = targetHeight / div;
                }

                if (m_encoderConfigs.format == MovieEncoder.Type.MP4)
                {
                    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.Setup(m_scratchBuffer.width, m_scratchBuffer.height, 3, targetFramerate);
                m_encoder = MovieEncoder.Create(m_encoderConfigs, outPath);
                if (m_encoder == null)
                {
                    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);

            m_recording = true;
            Debug.Log("MovieMRecorder: BeginRecording()");
            return(true);
        }