コード例 #1
0
        private async Task <string[]> Execute(string command, string arguments, StandardStream standardStream, bool logOutput)
        {
            // prep the process arguments
            var processStartInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                FileName    = command,
                Arguments   = arguments
            };

            if (standardStream == StandardStream.Error)
            {
                processStartInfo.RedirectStandardError = true;
            }
            else
            {
                processStartInfo.RedirectStandardOutput = true;
            }

            // log what we're about to do
            _Logger.LogInformation(arguments);

            try
            {
                // let 'er rip
                var process = Process.Start(processStartInfo);

                // process each line
                var lines  = new List <string>();
                var stream = standardStream == StandardStream.Error ? process.StandardError : process.StandardOutput;
                while (!stream.EndOfStream)
                {
                    var line = await stream.ReadLineAsync();

                    if (line != null)
                    {
                        if (logOutput)
                        {
                            _Logger.LogInformation(line);
                        }
                        lines.Add(line);
                    }
                }

                // make sure everything is finished
                process.WaitForExit();

                return(lines.ToArray());
            }
            catch (Exception ex)
            {
                throw new ExecuteException($"Could not start {command}. Is ffmpeg installed and available on your PATH?", ex);
            }
        }
コード例 #2
0
 /// <summary>
 /// Call FFprobe while capturing and logging the standard output or error stream.
 /// </summary>
 /// <param name="arguments">The FFprobe arguments.</param>
 /// <param name="standardStream">The standard stream to read.</param>
 /// <returns>The lines written to the standard output or error stream.</returns>
 public Task <string[]> FFprobe(string arguments, StandardStream standardStream)
 {
     return(FFprobe(arguments, standardStream, false));
 }
コード例 #3
0
 /// <summary>
 /// Call FFprobe while capturing and optionally logging the standard output or error stream.
 /// </summary>
 /// <param name="arguments">The FFprobe arguments.</param>
 /// <param name="standardStream">The standard stream to read.</param>
 /// <param name="logOutput">Whether to log output from the standard stream.</param>
 /// <returns>The lines written to the standard output or error stream.</returns>
 public Task <string[]> FFprobe(string arguments, StandardStream standardStream, bool logOutput)
 {
     return(Execute("ffprobe", arguments, standardStream, logOutput));
 }
コード例 #4
0
 /// <summary>
 /// Call FFmpeg while capturing and logging the standard error or output stream.
 /// </summary>
 /// <param name="arguments">The FFmpeg arguments.</param>
 /// <param name="standardStream">The standard stream to read.</param>
 /// <returns>The lines written to the standard error or output stream.</returns>
 public Task <string[]> FFmpeg(string arguments, StandardStream standardStream)
 {
     return(FFmpeg(arguments, standardStream, true));
 }