示例#1
0
        /// <summary>
        /// Run the FFmpeg executable with the specified command line arguments.
        /// </summary>
        private void Execute()
        {
            bool processCompletedSuccessfully = false;

            InitializeOutput();

            ProcessStartInfo info = new ProcessStartInfo(AppSetting.Instance.FFmpegPath, MediaSettings.FFmpegArgs);
            info.UseShellExecute = false;
            info.CreateNoWindow = true;
            info.RedirectStandardError = true;
            info.RedirectStandardOutput = true;

            using (Process p = new Process())
            {
                try
                {
                    p.StartInfo = info;
                    // For some reason, FFmpeg sends data to the ErrorDataReceived event rather than OutputDataReceived.
                    p.ErrorDataReceived += ErrorDataReceived;
                    //p.OutputDataReceived += new DataReceivedEventHandler(OutputDataReceived);
                    p.Start();

                    //p.BeginOutputReadLine();
                    p.BeginErrorReadLine();

                    processCompletedSuccessfully = p.WaitForExit(MediaSettings.TimeoutMs);

                    if (!processCompletedSuccessfully)
                        p.Kill();

                    p.WaitForExit();

                    if (!processCompletedSuccessfully || MediaSettings.CancellationToken.IsCancellationRequested)
                    {
                        File.Delete(MediaSettings.FilePathDestination);
                    }
                }
                catch (Exception ex)
                {
                    ErrorHandler.Error.Record(ex, MediaSettings.GalleryId, Factory.LoadGallerySettings(), AppSetting.Instance);
                }
            }

            if (!processCompletedSuccessfully)
            {
                Exception ex = new BusinessException(String.Format(CultureInfo.CurrentCulture, "FFmpeg timed out while processing the video or audio file. Consider increasing the timeout value. It is currently set to {0} milliseconds.", MediaSettings.TimeoutMs));
                ex.Data.Add("FFmpeg args", MediaSettings.FFmpegArgs);
                ex.Data.Add("FFmpeg output", Output);
                ex.Data.Add("StackTrace", Environment.StackTrace);
                ErrorHandler.Error.Record(ex, MediaSettings.GalleryId, Factory.LoadGallerySettings(), AppSetting.Instance);
            }
        }
 private static void RecordEvent(string msg, MediaConversionSettings settings)
 {
     Exception ex = new BusinessException(msg);
     ex.Data.Add("FFmpeg args", settings.FFmpegArgs);
     ex.Data.Add("FFmpeg output", settings.FFmpegOutput);
     ex.Data.Add("StackTrace", Environment.StackTrace);
     ErrorHandler.Error.Record(ex, settings.GalleryId, Factory.LoadGallerySettings(), AppSetting.Instance);
 }