Example #1
0
        public static async void PerformCrop(
            Window window,
            string inputPath,
            string outputPath,
            uint x,
            uint y,
            uint width,
            uint height)
        {
            // Lock the window during the operation
            window.IsEnabled = false;

            // TODO: Create a progress window

            Process cropProcess;

            if (!FF_Crop(out cropProcess, inputPath, outputPath, x, y, width, height))
            {
                Console.WriteLine("Error starting FF_Crop");
                return;
            }

            ProgressWindow progressWindow = new ProgressWindow("Cropping");

            progressWindow.Show();

            // Parse process output and update progress bar

            window.IsEnabled = false;

            await Task.Run(() =>
            {
                string line;
                int p          = 0;
                bool gotCancel = false;

                // Set up progress window cancel
                progressWindow.OnGetCancel += (s, ee) =>
                {
                    gotCancel = true;
                    cropProcess.Kill();
                };
                while ((line = cropProcess.StandardError.ReadLine()) != null)
                {
                    if (gotCancel)
                    {
                        break;
                    }
                    // TODO: Parse output and update percent
                    p++;
                    if (progressWindow.progress != null)
                    {
                        progressWindow.progress.Report(p);
                    }

                    Console.WriteLine("FFMPEG: " + line);
                }
            });

            // Complete
            window.IsEnabled = true;
            //this.Closing -= ProgressWindow_Closing;
            cropProcess.Close();
            Console.WriteLine("Task Complete.");
            progressWindow.Complete();
        }