Пример #1
0
        private void WorkerThread()
        {
            while (!StopRequest)
            {
                if (currentTask == null && tasks.TryDequeue(out currentTask))
                {
                    var ffmpeg = new Engine(MainForm.VideoCutterSettings.FFmpegPath);
                    ffmpeg.Complete += (object sender, FFmpeg.NET.Events.ConversionCompleteEventArgs e) =>
                    {
                        currentTask = null;
                        OnPropertyChanged("Tasks");
                        OnTaskProgress("Done");
                    };
                    ffmpeg.Error += (object sender, FFmpeg.NET.Events.ConversionErrorEventArgs e) =>
                    {
                        currentTask = null;
                        OnPropertyChanged("Tasks");
                        OnTaskProgress("Failure: " + e.Exception.Message);
                    };

                    ffmpeg.Progress += (object sender, FFmpeg.NET.Events.ConversionProgressEventArgs e) =>
                    {
                        var msg = string.Format("Processed {0} seconds", e.ProcessedDuration.TotalSeconds);
                        OnTaskProgress(msg);
                    };

                    var options = new ConversionOptions();
                    options.CutMedia(TimeSpan.FromMilliseconds(currentTask.SelectionStart), TimeSpan.FromMilliseconds(currentTask.Duration));

                    Task <MediaFile> taskConversion = ffmpeg.ConvertAsync(new MediaFile(currentTask.InputFilePath), new MediaFile(currentTask.OutputFilePath), options);
                    taskConversion.Wait();
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }
Пример #2
0
 public void EnqueueTask(FFmpegTask task)
 {
     tasks.Enqueue(task);
     OnPropertyChanged("Tasks");
 }