예제 #1
0
        private void SinglePass(string argument)
        {
            _ffmpegProcess = new FFmpeg(argument);

            _ffmpegProcess.Process.ErrorDataReceived += ProcessOnErrorDataReceived;
            _ffmpegProcess.Process.OutputDataReceived += ProcessOnOutputDataReceived;
            _ffmpegProcess.Process.Exited += (o, args) => textBoxOutput.Invoke((Action)(() =>
                                                                              {
                                                                                  if (_panic) return; //This should stop that one exception when closing the converter
                                                                                  textBoxOutput.AppendText("\n--- FFMPEG HAS EXITED ---");
                                                                                  buttonCancel.Enabled = false;

                                                                                  _timer = new Timer();
                                                                                  _timer.Interval = 500;
                                                                                  _timer.Tick += Exited;
                                                                                  _timer.Start();
                                                                              }));

            _ffmpegProcess.Start();
        }
예제 #2
0
        private void GeneratePreview()
        {
            string argument = ConstructArguments();

            if (string.IsNullOrWhiteSpace(argument))
                return;

            _generating = true;
            _ffmpegProcess = new FFmpeg(argument);

            _ffmpegProcess.Process.ErrorDataReceived += (sender, args) => Console.WriteLine(args.Data);
            _ffmpegProcess.Process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);

            _ffmpegProcess.Process.Exited += (o, args) => pictureBoxVideo.Invoke((Action)(() =>
                                                                                {
                                                                                    _generating = false;

                                                                                    int exitCode = _ffmpegProcess.Process.ExitCode;

                                                                                    if (exitCode != 0)
                                                                                    {
                                                                                        _message = string.Format("ffmpeg.exe exited with exit code {0}. That's usually bad.", exitCode);
                                                                                        return;
                                                                                    }

                                                                                    if (!File.Exists(_previewFile))
                                                                                    {
                                                                                        _message = "The preview file wasn't generated, that means ffmpeg.exe failed. Confirm the following:\n- Is the input time actually smaller than the length than the input video?";
                                                                                        return;
                                                                                    }

                                                                                    try
                                                                                    {
                                                                                        //_image = Image.FromFile(_previewFile); //Thank you for not releasing the lock on the file afterwards, Microsoft

                                                                                        using (FileStream stream = new FileStream(_previewFile, FileMode.Open, FileAccess.Read))
                                                                                            _image = Image.FromStream(stream);

                                                                                        pictureBoxVideo.BackgroundImage = _image;
                                                                                        File.Delete(_previewFile);

                                                                                        _owner.AssumedInputSize = _image.Size; //We assume the size of the preview will also be the size of the input used for the conversion

                                                                                        float aspectRatio = _image.Width / (float)_image.Height;
                                                                                        ClientSize = new Size((int)(ClientSize.Height * aspectRatio), ClientSize.Height);
                                                                                    }
                                                                                    catch (Exception e)
                                                                                    {
                                                                                        _message = e.ToString();
                                                                                    }
                                                                                }));

            _ffmpegProcess.Process.Start();
        }
예제 #3
0
        private void MultiPass(string[] arguments)
        {
            int passes = arguments.Length;

            _ffmpegProcess = new FFmpeg(arguments[currentPass]);

            _ffmpegProcess.Process.ErrorDataReceived += ProcessOnErrorDataReceived;
            _ffmpegProcess.Process.OutputDataReceived += ProcessOnOutputDataReceived;
            _ffmpegProcess.Process.Exited += (o, args) => textBoxOutput.Invoke((Action)(() =>
            {
                if (_panic) return; //This should stop that one exception when closing the converter
                textBoxOutput.AppendText("\n--- FFMPEG HAS EXITED ---");

                currentPass++;
                if (currentPass < passes && !_cancelMultipass)
                {
                    textBoxOutput.AppendText(string.Format("\n--- ENTERING PASS {0} ---", currentPass + 1));

                    MultiPass(arguments); //Sort of recursion going on here, be careful with stack overflows and shit
                    return;
                }

                buttonCancel.Enabled = false;

                _timer = new Timer();
                _timer.Interval = 500;
                _timer.Tick += Exited;
                _timer.Start();
            }));

            _ffmpegProcess.Start();
        }