예제 #1
0
        public static bool Combine(string audio,
                                   string video,
                                   string title,
                                   OperationLogger logger,
                                   out Exception exception,
                                   Action <int, object> reportProgress)
        {
            // Remove '_video' from video file to get a final filename.
            string error  = string.Empty;
            string output = video.Replace("_video", string.Empty);
            FFmpegResult <bool> result = null;

            try
            {
                // Raise events on main thread
                reportProgress(-1, new Dictionary <string, object>()
                {
                    { "ProgressText", "Combining..." }
                });

                result = FFmpeg.Combine(video, audio, output, delegate(int percentage)
                {
                    // Combine progress
                    reportProgress(percentage, null);
                }, logger);

                // Save errors if combining failed
                if (!result.Value)
                {
                    var sb = new StringBuilder();

                    sb.AppendLine(title);
                    sb.AppendLine(string.Join(
                                      Environment.NewLine,
                                      result.Errors.Select(err => $" - {err}")));

                    error = sb.ToString();
                }

                // Cleanup the separate audio and video files
                Helper.DeleteFiles(audio, video);
            }
            catch (Exception ex)
            {
                exception = ex;
                Common.SaveException(ex);
                return(false);
            }
            finally
            {
                // Raise events on main thread
                reportProgress(-1, new Dictionary <string, object>()
                {
                    { "ProgressText", null }
                });
            }

            exception = new Exception(error);

            return(result.Value);
        }
예제 #2
0
        protected override void WorkerDoWork(DoWorkEventArgs e)
        {
            downloader.Start();

            while (downloader?.IsBusy == true)
            {
                Thread.Sleep(200);
            }

            if (_combine && _downloadSuccessful)
            {
                string audio = downloader.Files[0].Path;
                string video = downloader.Files[1].Path;

                this.ReportProgress(-1, new Dictionary <string, object>()
                {
                    { nameof(Progress), 0 }
                });
                this.ReportProgress(ProgressMax, null);

                try
                {
                    FFmpegResult <bool> result;

                    this.ReportProgress(-1, new Dictionary <string, object>()
                    {
                        { nameof(ProgressText), "Combining..." }
                    });

                    using (var logger = OperationLogger.Create(OperationLogger.FFmpegDLogFile))
                    {
                        result = FFmpeg.Combine(video, audio, this.Output, delegate(int percentage)
                        {
                            // Combine progress
                            this.ReportProgress(percentage, null);
                        }, logger);
                    }

                    if (result.Value)
                    {
                        e.Result = OperationStatus.Success;
                    }
                    else
                    {
                        e.Result = OperationStatus.Failed;
                        this.ErrorsInternal.AddRange(result.Errors);
                    }

                    // Cleanup the separate audio and video files
                    Helper.DeleteFiles(audio, video);
                }
                catch (Exception ex)
                {
                    Common.SaveException(ex);
                    e.Result = OperationStatus.Failed;
                }
            }
            else
            {
                e.Result = this.Status;
            }
        }