Пример #1
0
        static public bool StartVideoCapture(string filePath, VideoRecorder recorder,
                                             UsdPathSerializer usdPathSerializer, bool offlineRender = false)
        {
            // Only one video at a time.
            if (m_ActiveVideoRecording != null)
            {
                return(false);
            }

            // Don't start recording unless there is enough space left.
            if (!FileUtils.InitializeDirectoryWithUserError(
                    Path.GetDirectoryName(filePath),
                    "Failed to start video capture"))
            {
                return(false);
            }

            // Vertical video is disabled.
            recorder.IsPortrait = false;

            // Start the capture first, which may fail, so do this before toggling any state.
            // While the state below is important for the actual frame capture, starting the capture process
            // does not require it.
            int sampleRate = 0;

            if (AudioCaptureManager.m_Instance.IsCapturingAudio)
            {
                sampleRate = AudioCaptureManager.m_Instance.SampleRate;
            }

            if (!recorder.StartCapture(filePath, sampleRate,
                                       AudioCaptureManager.m_Instance.IsCapturingAudio, offlineRender,
                                       offlineRender ? App.UserConfig.Video.OfflineFPS : App.UserConfig.Video.FPS))
            {
                OutputWindowScript.ReportFileSaved("Failed to start capture!", null,
                                                   OutputWindowScript.InfoCardSpawnPos.Brush);
                return(false);
            }

            m_ActiveVideoRecording = recorder;

            // Perform any necessary VR camera rendering optimizations to reduce CPU & GPU workload

            // Debug reduce quality for capture.
            // XXX This should just be ADAPTIVE RENDERING
            if (m_DebugVideoCaptureQualityLevel != -1)
            {
                m_PreCaptureQualityLevel = QualityControls.m_Instance.QualityLevel;
                QualityControls.m_Instance.QualityLevel = m_DebugVideoCaptureQualityLevel;
            }

            App.VrSdk.SetHmdScalingFactor(m_VideoCaptureResolutionScale);

            // Setup SSAA
            RenderWrapper wrapper = recorder.gameObject.GetComponent <RenderWrapper>();

            m_PreCaptureSuperSampling = wrapper.SuperSampling;
            wrapper.SuperSampling     = m_SuperSampling;

#if USD_SUPPORTED
            // Read from the Usd serializer if we're recording offline.  Write to it otherwise.
            m_UsdPathSerializer = usdPathSerializer;
            if (!offlineRender)
            {
                m_UsdPath = SaveLoadScript.m_Instance.SceneFile.Valid ?
                            Path.ChangeExtension(filePath, "usda") : null;
                m_RecordingStopwatch = new System.Diagnostics.Stopwatch();
                m_RecordingStopwatch.Start();
                if (!m_UsdPathSerializer.StartRecording(m_UsdPath))
                {
                    UnityEngine.Object.Destroy(m_UsdPathSerializer);
                    m_UsdPathSerializer = null;
                }
            }
            else
            {
                recorder.SetCaptureFramerate(Mathf.RoundToInt(App.UserConfig.Video.OfflineFPS));
                m_UsdPath = null;
                if (m_UsdPathSerializer.Load(App.Config.m_VideoPathToRender))
                {
                    m_UsdPathSerializer.StartPlayback();
                }
                else
                {
                    UnityEngine.Object.Destroy(m_UsdPathSerializer);
                    m_UsdPathSerializer = null;
                }
            }
#endif

            return(true);
        }
Пример #2
0
        public void BeginRender()
        {
            IsRendering = true;

            // Turn off shadows, until depth disparity can be fixed.
            // See http://b/68952256 for details
            UnityEngine.QualitySettings.shadows = ShadowQuality.Disable;
            for (int i = 0; i < App.Scene.GetNumLights(); i++)
            {
                App.Scene.GetLight(i).shadows = LightShadows.None;
            }

            for (int i = 0; ; ++i)
            {
                string o      = string.Format("{0}_{1:00}", m_outputBasename, i);
                string outVid = Path.Combine(m_outputFolder, o + ".mp4");
                string outDir = Path.Combine(m_outputFolder, o + "/");

                if (!File.Exists(outVid) && !File.Exists(outDir))
                {
                    m_videoPath  = outVid;
                    m_imagesPath = outDir + m_outputBasename;

                    m_odsCamera.outputFolder = outDir;
                    m_odsCamera.basename     = m_outputBasename;

                    // Touch the destination folder.
                    Directory.CreateDirectory(outDir);

                    // Touch the destination file.
                    FileStream fs = File.Open(m_videoPath, FileMode.OpenOrCreate,
                                              FileAccess.Write, FileShare.ReadWrite);
                    fs.Close();
                    fs.Dispose();
                    File.SetLastWriteTimeUtc(m_videoPath, System.DateTime.UtcNow);
                    break;
                }
            }

            if (!string.IsNullOrEmpty(CameraPath) && File.Exists(CameraPath))
            {
#if USD_SUPPORTED
                m_PathSerializer = gameObject.AddComponent <UsdPathSerializer>();
                if (m_PathSerializer.Load(CameraPath))
                {
                    m_PathSerializer.StartPlayback("/Sketch", "/VideoCamera");
                    FramesToCapture       = Mathf.FloorToInt((float)(m_PathSerializer.Duration) * m_fps);
                    m_PathSerializer.Time = 0;
                    m_PathSerializer.Deserialize();
                }
                else
                {
                    Destroy(m_PathSerializer);
                    m_PathSerializer = null;
                }
#else
                throw new System.NotImplementedException("CameraPath requires USD support");
#endif
            }

            Debug.LogFormat("ODS Output Video: {0}" + System.Environment.NewLine +
                            "ODS Output Path: {1}" + System.Environment.NewLine +
                            "ODS Basename: {2}"
                            , m_videoPath, m_odsCamera.outputFolder, m_odsCamera.basename);

            Shader.SetGlobalFloat("ODS_PoleCollapseAmount", App.UserConfig.Video.OdsPoleCollapsing);


            gameObject.SetActive(true);

            App.Instance.FrameCountDisplay.gameObject.SetActive(true);
        }