Ejemplo n.º 1
0
        private void Awake()
        {
            bool debug = Debug.isDebugBuild;

                        #if DEBUG
            debug = true;
                        #endif

            if (!debug)
            {
                this.enabled = false;
                return;
            }

            // populate recording path
            populatedRecordingPath_ = recordingPath_;
            populatedRecordingPath_ = SavePathUtil.PopulateDesktopVariable(populatedRecordingPath_);

                        #if DT_DEBUG_MENU
            var inspector = DTDebugMenu.GenericInspectorRegistry.Get("DTMediaCapture");
            inspector.BeginDynamic();
            inspector.RegisterHeader("Recorder");
            string keybindingComment = useKeyBindings_ ? string.Format("({0})", toggleRecordingKey_) : "";
            inspector.RegisterToggleButton((b) => b ? "Stop Recording " + keybindingComment : "Start Recording " + keybindingComment, () => recording_, (b) => { if (b)
                                                                                                                                                                 {
                                                                                                                                                                     StartRecording();
                                                                                                                                                                 }
                                                                                                                                                                 else
                                                                                                                                                                 {
                                                                                                                                                                     StopRecording();
                                                                                                                                                                 } });
            dynamicGroup_ = inspector.EndDynamic();
                        #endif
        }
Ejemplo n.º 2
0
        private void RefreshSequencePath()
        {
            string recordingNameFormat = recordingNameFormat_;

            recordingNameFormat = SavePathUtil.PopulateDateVariable(recordingNameFormat);

            if (!recordingNameFormat.Contains("${INDEX}"))
            {
                Debug.LogWarning("RecordingNameFormat is missing ${INDEX} - adding _${INDEX} to the end!");
                recordingNameFormat = recordingNameFormat + "_${INDEX}";
            }

            string finalRecordingName = null;
            int    index = 0;

            while (true)
            {
                string currentRecordingName = recordingNameFormat.Replace("${INDEX}", index.ToString());
                string currentRecordingPath = Path.Combine(populatedRecordingPath_, currentRecordingName) + ".mp4";

                if (!File.Exists(currentRecordingPath))
                {
                    finalRecordingName = currentRecordingName;
                    break;
                }
                index++;
            }

            Directory.CreateDirectory(Path.Combine(populatedRecordingPath_, finalRecordingName));
            currentRecordingName_ = finalRecordingName;
        }
Ejemplo n.º 3
0
        private void CaptureScreenshot()
        {
            string screenshotPath = screenshotPath_;

            screenshotPath = SavePathUtil.PopulateDesktopVariable(screenshotPath);

            string screenshotName = Path.GetFileNameWithoutExtension(screenshotNameFormat_);

            if (!screenshotName.Contains("${INDEX}"))
            {
                Debug.LogWarning("ScreenshotNameFormat is missing ${INDEX} - adding _${INDEX} to the end!");
                screenshotName = screenshotName + "_${INDEX}";
            }

            screenshotName = screenshotName.Replace("${DATE}", System.DateTime.Now.ToString("MM-dd-yyyy"));

            string finalScreenshotPath = null;
            int    index = 0;

            while (true)
            {
                string currentScreenshotName = screenshotName.Replace("${INDEX}", index.ToString()) + ".png";
                string currentScreenshotPath = Path.Combine(screenshotPath, currentScreenshotName);

                if (!File.Exists(currentScreenshotPath))
                {
                    finalScreenshotPath = currentScreenshotPath;
                    break;
                }
                index++;
            }

            string finalScreenshotDirectoryPath = Path.GetDirectoryName(finalScreenshotPath);

            if (!Directory.Exists(finalScreenshotDirectoryPath))
            {
                Directory.CreateDirectory(finalScreenshotDirectoryPath);
            }

            Application.CaptureScreenshot(finalScreenshotPath, superSizeFactor_);
            Debug.Log("Saved screenshot at: " + finalScreenshotPath + "!");
        }
Ejemplo n.º 4
0
        private void CreateVideoFromCurrentSequence()
        {
            if (string.IsNullOrEmpty(currentRecordingName_))
            {
                Debug.LogWarning("Cannot create video because no current recording name!");
                return;
            }

            string ffmpegDirectoryPath = "";

#if UNITY_EDITOR
            string binPath       = ScriptableObjectEditorUtil.PathForScriptableObjectType <BinMarker>();
            string pathToProject = Application.dataPath.Replace("Assets", "");
            string binFullPath   = Path.Combine(pathToProject, binPath);
            ffmpegDirectoryPath = Path.Combine(binFullPath, "ffmpeg");
#else
            ffmpegDirectoryPath = SavePathUtil.PopulateDesktopVariable(nonEditorFfmpegPath_);
#endif

            string ffmpegPath = "";
                        #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
            ffmpegPath = Path.Combine(ffmpegDirectoryPath, "ffmpeg_mac");
                        #else
            ffmpegPath = Path.Combine(ffmpegDirectoryPath, "ffmpeg_win.exe");
                        #endif

            string arguments = string.Format("-f image2 -r {0} -i ./{1}/Frame%06d.png -c:v libx264 -r {0} -b:v 30M -pix_fmt yuv420p {1}.mp4 -loglevel debug", frameRate_, currentRecordingName_);

            var process = new System.Diagnostics.Process();
            process.StartInfo.FileName         = ffmpegPath;
            process.StartInfo.Arguments        = arguments;
            process.StartInfo.WorkingDirectory = populatedRecordingPath_;
            process.Start();

            process.WaitForExit(5 * 60 * 1000);             // 5 minutes max

            Directory.Delete(Path.Combine(populatedRecordingPath_, currentRecordingName_), recursive: true);
        }