FFmpegService.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Diagnostics;
  3. using Vinno.IUS.Common.Log;
  4. namespace Vinno.IUS.Common.Media.FFmpeg
  5. {
  6. public static class FFmpegService
  7. {
  8. private static string _ffmpegPath = "ffmpeg";
  9. public static void SetFFmpegPath(string ffmpegPath)
  10. {
  11. _ffmpegPath = ffmpegPath;
  12. }
  13. public static void StartFFmpeg(out Process process,string arguments, FFmpegLog logItem = null)
  14. {
  15. process = new Process
  16. {
  17. StartInfo =
  18. {
  19. FileName = _ffmpegPath,
  20. Arguments = arguments,
  21. UseShellExecute = false,
  22. Verb = "runas",
  23. CreateNoWindow = true,
  24. RedirectStandardError = true,
  25. RedirectStandardInput = true
  26. },
  27. EnableRaisingEvents = true
  28. };
  29. if (logItem != null)
  30. {
  31. process.ErrorDataReceived += (s, e) => Logger.WriteLineWarn("ErrorDataReceived:" + e.Data);
  32. }
  33. process.Start();
  34. process.BeginErrorReadLine();
  35. }
  36. }
  37. }