protected override void WorkerCompleted(RunWorkerCompletedEventArgs e) { if (this.IsSuccessful) { this.Duration = (long)FFmpeg.GetDuration(this.Input).Value.TotalSeconds; this.FileSize = Helper.GetFileSize(this.Output); } }
public ConvertOperation(string input, string output, TimeSpan start, TimeSpan end) : this(input, output) { _mode = ConvertingMode.File; _start = start; _end = end; this.Duration = (long)FFmpeg.GetDuration(this.Input).Value.TotalSeconds; }
public CroppingOperation(string input, string output, TimeSpan start, TimeSpan end) { this.ReportsProgress = true; this.Input = input; this.Output = output; _start = start; _end = end; this.Duration = (long)FFmpeg.GetDuration(this.Input).Value.TotalSeconds; this.Title = Path.GetFileName(this.Output); this.ProgressText = "Cropping..."; }
protected override void WorkerDoWork(DoWorkEventArgs e) { if (_mode == ConvertingMode.File) { try { using (var logger = OperationLogger.Create(OperationLogger.FFmpegDLogFile)) { FFmpeg.Convert(this.Input, this.Output, this.ReportProgress, _cts.Token, logger); // Crop if not operation wasn't canceled and _start has a valid value if (!this.CancellationPending && _start != TimeSpan.MinValue) { // Crop to end of file, unless _end has a valid value if (_end == TimeSpan.MinValue) { FFmpeg.Crop(this.Output, this.Output, _start, this.ReportProgress, _cts.Token, logger); } else { FFmpeg.Crop(this.Output, this.Output, _start, _end, this.ReportProgress, _cts.Token, logger); } } } // Reset variables _start = _end = TimeSpan.MinValue; } catch (Exception ex) { Common.SaveException(ex); Helper.DeleteFiles(this.Output); e.Result = OperationStatus.Failed; } } else { using (var logger = OperationLogger.Create(OperationLogger.FFmpegDLogFile)) { foreach (string input in Directory.GetFiles(this.Input, _searchPattern)) { if (this.CancellationPending) { break; } _count++; try { string output = string.Format("{0}\\{1}.mp3", this.Output, Path.GetFileNameWithoutExtension(input)); this.ReportProgress(UpdateProperties, new Dictionary <string, object>() { { nameof(Operation.Title), Path.GetFileName(input) }, { nameof(Operation.Duration), (int)FFmpeg.GetDuration(input).Value.TotalSeconds }, { nameof(Operation.FileSize), Helper.GetFileSize(input) } }); _currentOutput = output; FFmpeg.Convert(input, output, this.ReportProgress, _cts.Token, logger); _currentOutput = null; this.ProcessedFiles.Add(output); } catch (Exception ex) { _failures++; Common.SaveException(ex); Helper.DeleteFiles(_currentOutput); continue; } } } } // Set operation result e.Result = this.CancellationPending ? OperationStatus.Canceled : OperationStatus.Success; }