Beispiel #1
0
        void OnGUI()
        {
            // show processing options. some of them are editable while running.
            GUILayout.Label("Duplicate frame remover (MJPEG/PCM AVI remux)", EditorStyles.boldLabel);

            if (!running)
            {
                srcPath      = MpEditorUtil.OpenFileField(srcPath, "Source path", "Source file");
                dstPath      = MpEditorUtil.SaveFileField(dstPath, "Destination path", "Destination file");
                discardAudio = EditorGUILayout.Toggle("Discard audio", discardAudio);
            }
            else
            {
                EditorGUILayout.LabelField("Source path", srcPath);
                EditorGUILayout.LabelField("Destination path", dstPath);
                EditorGUILayout.LabelField("Discard audio", discardAudio ? "true" : "false");
            }
            options.maxLookbackFrames = EditorGUILayout.IntField("Max lookback frames", options.maxLookbackFrames);

            // advances procession options
            advancedSettingsFoldout = EditorGUILayout.Foldout(advancedSettingsFoldout, "Advanced settings");
            if (advancedSettingsFoldout)
            {
                options.maxImageDiff        = EditorGUILayout.Slider("  Max image diff", options.maxImageDiff, 0, MAX_IMAGE_DIFF);
                options.maxPixelDiff        = EditorGUILayout.IntSlider("  Max pixel diff", options.maxPixelDiff, 0, MAX_PIXEL_DIFF);
                options.toneCompareDistrust = EditorGUILayout.IntSlider("  Tone compare distrust", options.toneCompareDistrust, 0, MAX_TONE_COMPARE_DISTRUST);
                if (!running)
                {
                    options.pixelCacheSize = EditorGUILayout.IntField("  Pixel cache size", options.pixelCacheSize);
                    EditorGUILayout.LabelField(" ", (int)(3.69f * options.pixelCacheSize) + "Mb (720p estimate)");
                    if (options.pixelCacheSize < options.maxLookbackFrames || options.pixelCacheSize > 1000)
                    {
                        EditorGUILayout.HelpBox("For optimal performance, pixel cache should be larger than \"max lookback frames\"," +
                                                "but if it's too large, you may get out of memory errors", MessageType.Warning);
                    }

                    logDuplicatesPath = MpEditorUtil.SaveFileField(logDuplicatesPath, "  Log duplicates to file", "Log duplicates to file");
                }
                else
                {
                    int pixelCacheMb = movie.demux.videoStreamInfo.width * movie.demux.videoStreamInfo.height * 4 * options.pixelCacheSize / 1000000;
                    EditorGUILayout.LabelField("  Pixel cache size", options.pixelCacheSize.ToString() + " (" + pixelCacheMb + "Mb)");
                    EditorGUILayout.LabelField("  Log duplicates to file", logDuplicatesPath);
                }
            }

            // controls
            if (!running)
            {
                GUI.enabled = File.Exists(srcPath) && !string.IsNullOrEmpty(dstPath);
                if (GUILayout.Button("Process file"))
                {
                    running = true;
                    if (File.Exists(dstPath))
                    {
                        running = EditorUtility.DisplayDialog("File exists. Overwrite?", dstPath, "Yes", "No");
                    }
                    if (running)
                    {
                        File.WriteAllText(dstPath, "");                          // just empty the file
                        StartProcessing();
                        Debug.Log("AVI remux started");
                    }
                }
                GUI.enabled = true;
            }
            else
            {
                if (GUILayout.Button("Stop"))
                {
                    StopProcessing();
                    Debug.Log("AVI remux stopped");
                    running = false;
                }
            }

            // if we have a duplicate finder (we're not necessarily running), then show progress and stats
            if (dupFinder != null)
            {
                // progress bar
                string progressStr = dupFinder.framesProcessed + "/" + (float)movie.demux.videoStreamInfo.frameCount;

                                #if (UNITY_4_0 || UNITY_4_1 || UNITY_4_2)
                EditorGUILayout.LabelField("Progress", progressStr);
                                #else
                float progress = (float)dupFinder.framesProcessed / (float)movie.demux.videoStreamInfo.frameCount;
                var   rect     = EditorGUILayout.GetControlRect();
                EditorGUI.ProgressBar(rect, progress, progressStr);
                                #endif

                // duplicates found so far
                EditorGUILayout.LabelField("Duplicates found", dupFinder.stats.duplicateCount.ToString());

                // love preview and stats foldout
                livePreviewFoldout = EditorGUILayout.Foldout(livePreviewFoldout, "Live preview and stats");
                if (livePreviewFoldout && framebuffer != null)
                {
                    int height = 160 * movie.demux.videoStreamInfo.height / movie.demux.videoStreamInfo.width;
                    GUILayout.Box(framebuffer, GUILayout.Width(160), GUILayout.Height(height));

                    EditorGUILayout.LabelField("Frames partially compared", dupFinder.stats.framesPartiallyComparedPercent.ToString("0.00") + " %");
                    EditorGUILayout.LabelField("Frames fully compared", dupFinder.stats.framesFullyComparedPercent.ToString("0.00") + " %");
                    EditorGUILayout.LabelField("Pixel cache hits", dupFinder.stats.pixelCacheHitPercent.ToString("0.00") + " %");
                }
            }
        }
Beispiel #2
0
        void OnGUI()
        {
            GUILayout.Label("FFMPEG options", EditorStyles.boldLabel);

            infile  = MpEditorUtil.OpenFileField(infile, "Infile", "Open video file");
            outfile = MpEditorUtil.SaveFileField(outfile, "Outfile", "Save video file", "avi");

            EditorGUILayout.Space();

            videoCodec   = EditorGUILayout.Popup("Video codec", videoCodec, videoCodecList);
            videoQuality = EditorGUILayout.IntSlider("Video quality", videoQuality, 1, 10);
            videoResize  = EditorGUILayout.Toggle("Video resize", videoResize);
            if (videoResize)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(" ");
                videoNewWidth  = EditorGUILayout.IntField(videoNewWidth);
                videoNewHeight = EditorGUILayout.IntField(videoNewHeight);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            audioCodec = EditorGUILayout.Popup("Audio codec", audioCodec, audioCodecList);
            if (audioCodec > 0)
            {
                audioChannels = EditorGUILayout.Popup("Audio channels", audioChannels - 1, audioChannelList) + 1;
                audioRate     = EditorGUILayout.IntField("Audio rate", audioRate);
            }

            EditorGUILayout.Space();

            otherArgs = EditorGUILayout.TextField("Other ffmpeg options", otherArgs);

            showFfmpegCmd = EditorGUILayout.Toggle("Show command", showFfmpegCmd);
            if (showFfmpegCmd)
            {
                var style = new GUIStyle(GUI.skin.textArea);
                style.wordWrap = true;
                //style.stretchHeight = true;
                GUILayout.TextArea(ffmpegPath + " " + BuildFfmpegArgs(), style, GUILayout.MinHeight(60));
            }

            EditorGUILayout.Space();
            appendBytesExtension      = EditorGUILayout.Toggle("Append .bytes extension", appendBytesExtension);
            openDuplicateFrameRemover = EditorGUILayout.Toggle("Open dup frame remover", openDuplicateFrameRemover);

            // show some helpful tips
            if (!string.IsNullOrEmpty(outfile) && outfile.Contains("Assets") && !appendBytesExtension)
            {
                EditorGUILayout.HelpBox("Helpful tip. The outfile is saved to Assets/ folder, you may want to tick" +
                                        "\"append .bytes extension\"", MessageType.Info);
            }
            if (openDuplicateFrameRemover)
            {
                EditorGUILayout.HelpBox("The Duplicate Frame Remover will help to further reduce file size " +
                                        "of MJPEG encoded video. This option conveniently opens DFM window after FFMPEG is done", MessageType.Info);
            }

            if (!ffmpegDetected)
            {
                detectedFfmpegVersion = DetectFfmpeg();
                ffmpegDetected        = true;
            }

            if (detectedFfmpegVersion != null)
            {
                if (worker == null)
                {
                    GUI.enabled = !string.IsNullOrEmpty(infile) && !string.IsNullOrEmpty(outfile);
                    if (GUILayout.Button("Run ffmpeg"))
                    {
                        RunFfmpegCmd();
                    }
                    GUI.enabled = true;
                }
                else
                {
                    if (GUILayout.Button("Kill ffmpeg process"))
                    {
                        KillFfmpeg();
                    }
                }

                EditorGUILayout.LabelField("Detected", detectedFfmpegVersion);
            }
            else
            {
                                #if UNITY_EDITOR_OSX
                EditorGUILayout.HelpBox("This tool depends on FFMPEG. Can't find it from default install location " + ffmpegPath,
                                        MessageType.Error);
                                #else
                EditorGUILayout.HelpBox("This tool depends on FFMPEG. Please install it and add it to your PATH",
                                        MessageType.Error);
                                #endif
                if (GUILayout.Button("ffmpeg.org/download.html"))
                {
                    Application.OpenURL("http://www.ffmpeg.org/download.html");
                }
            }
        }