Ejemplo n.º 1
0
        public Task ConvertAsync() {
            if (IsRunning) {
                throw new InvalidOperationException("operation in progress");
            }

            _state = FfmpegState.None;
            _task = new TaskCompletionSource<bool>();

            try {
                _ffmpeg.Start();
                _ffmpeg.BeginErrorReadLine();
            }
            catch (Exception ex) {
                _task.SetException(ex);
            }

            return _task.Task;
        }
Ejemplo n.º 2
0
        public void Cancel() {
            _state = FfmpegState.Cancelled;

            // Press 'q' to quit...
            _ffmpeg.StandardInput.Write('q');
        }
Ejemplo n.º 3
0
        // We have to parse the crappy FFmpeg output.
        private void HandleOutput(string line) {
            // We need to get the duration to work out the percentage complete later.
            if (line.StartsWith("  Duration")) {
                _duration = GetDuration(line);
            }

            // Progress updates start with either of these two things.
            if (line.StartsWith("size=") || line.StartsWith("frame=")) {
                var elapsed = GetElapsed(line);

                if (elapsed < _duration) {
                    // Progress.
                    _state = FfmpegState.Running;
                    var percentage = (int)((elapsed.TotalSeconds / _duration.TotalSeconds) * 100);
                    OnProgress(new FfmpegProgressEventArgs(percentage));
                }
                else {
                    // Finished
                    _state = FfmpegState.Finished;
                    OnProgress(new FfmpegProgressEventArgs(100));
                }
            }
        }