/// <summary> /// Kills the Ffmpeg process. /// </summary> public void Abort() { if ((FfmpegProcess_ != null) && !FfmpegProcess_.HasExited) { try { FfmpegProcess_.Kill(); } finally { FfmpegProcess_.Dispose(); FfmpegProcess_ = null; } } }
/// <summary> /// Spawns a new Ffmpeg process using the specified options in this instance. /// </summary> /// <param name="inputFiles">Media files to be processed.</param> /// <param name="outputFiles">Output files.</param> public void Process(InputFile[] inputFiles, OutputFile[] outputFiles) { FfmpegProcess_ = FfmpegProcess.Create(Path); try { FfmpegProcess_.ErrorDataReceived += OnFfmpegOutputReceived; List <string> args = new List <string>(); args.Add("-hide_banner"); args.Add("-nostdin"); args.Add("-stats"); args.Add("-loglevel fatal"); // Avoid FFmpeg asking for overwrite if a specified output file already exists. args.Add(OverwriteOutput ? "-y" : "-n"); // Global options. foreach (var customArg in CustomArgs) { if (string.IsNullOrEmpty(customArg.Value)) { args.Add("-" + customArg.Key); } else { args.Add(string.Format("-{0} {1}", customArg.Key, customArg.Value)); } } // Input options and files. if ((inputFiles != null) && (inputFiles.Length > 0)) { foreach (InputFile inputFile in inputFiles) { args.Add(inputFile.ToString()); } } else { throw new FfmpegException("No input files specified"); } // Output options and files. if ((outputFiles != null) && (outputFiles.Length > 0)) { foreach (OutputFile outputFile in outputFiles) { args.Add(outputFile.ToString()); } } else { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { args.Add("NUL"); } else { args.Add("/dev/null"); } } FfmpegProcess_.StartInfo.Arguments = String.Join(" ", args); LastCommand = Path + " " + FfmpegProcess_.StartInfo.Arguments; try { FfmpegProcess_.Start(); FfmpegProcess_.BeginErrorReadLine(); FfmpegProcess_.WaitForExit(); } catch (Exception ex) { throw new FfmpegException("Cannot spawn FFmpeg process", ex); } } finally { if (FfmpegProcess_ != null) { FfmpegProcess_.Dispose(); FfmpegProcess_ = null; } } }