EncoderValidator.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Runtime.Versioning;
  8. using System.Text.RegularExpressions;
  9. using MediaBrowser.Controller.MediaEncoding;
  10. using Microsoft.Extensions.Logging;
  11. namespace MediaBrowser.MediaEncoding.Encoder
  12. {
  13. public partial class EncoderValidator
  14. {
  15. private static readonly string[] _requiredDecoders =
  16. [
  17. "h264",
  18. "hevc",
  19. "vp8",
  20. "libvpx",
  21. "vp9",
  22. "libvpx-vp9",
  23. "av1",
  24. "libdav1d",
  25. "mpeg2video",
  26. "mpeg4",
  27. "msmpeg4",
  28. "dca",
  29. "ac3",
  30. "ac4",
  31. "aac",
  32. "mp3",
  33. "flac",
  34. "truehd",
  35. "h264_qsv",
  36. "hevc_qsv",
  37. "mpeg2_qsv",
  38. "vc1_qsv",
  39. "vp8_qsv",
  40. "vp9_qsv",
  41. "av1_qsv",
  42. "h264_cuvid",
  43. "hevc_cuvid",
  44. "mpeg2_cuvid",
  45. "vc1_cuvid",
  46. "mpeg4_cuvid",
  47. "vp8_cuvid",
  48. "vp9_cuvid",
  49. "av1_cuvid",
  50. "h264_rkmpp",
  51. "hevc_rkmpp",
  52. "mpeg1_rkmpp",
  53. "mpeg2_rkmpp",
  54. "mpeg4_rkmpp",
  55. "vp8_rkmpp",
  56. "vp9_rkmpp",
  57. "av1_rkmpp"
  58. ];
  59. private static readonly string[] _requiredEncoders =
  60. [
  61. "libx264",
  62. "libx265",
  63. "libsvtav1",
  64. "aac",
  65. "aac_at",
  66. "libfdk_aac",
  67. "ac3",
  68. "alac",
  69. "dca",
  70. "libmp3lame",
  71. "libopus",
  72. "libvorbis",
  73. "flac",
  74. "truehd",
  75. "srt",
  76. "h264_amf",
  77. "hevc_amf",
  78. "av1_amf",
  79. "h264_qsv",
  80. "hevc_qsv",
  81. "mjpeg_qsv",
  82. "av1_qsv",
  83. "h264_nvenc",
  84. "hevc_nvenc",
  85. "av1_nvenc",
  86. "h264_vaapi",
  87. "hevc_vaapi",
  88. "av1_vaapi",
  89. "mjpeg_vaapi",
  90. "h264_v4l2m2m",
  91. "h264_videotoolbox",
  92. "hevc_videotoolbox",
  93. "mjpeg_videotoolbox",
  94. "h264_rkmpp",
  95. "hevc_rkmpp",
  96. "mjpeg_rkmpp"
  97. ];
  98. private static readonly string[] _requiredFilters =
  99. [
  100. // sw
  101. "alphasrc",
  102. "zscale",
  103. "tonemapx",
  104. // qsv
  105. "scale_qsv",
  106. "vpp_qsv",
  107. "deinterlace_qsv",
  108. "overlay_qsv",
  109. // cuda
  110. "scale_cuda",
  111. "yadif_cuda",
  112. "bwdif_cuda",
  113. "tonemap_cuda",
  114. "overlay_cuda",
  115. "transpose_cuda",
  116. "hwupload_cuda",
  117. // opencl
  118. "scale_opencl",
  119. "tonemap_opencl",
  120. "overlay_opencl",
  121. "transpose_opencl",
  122. // vaapi
  123. "scale_vaapi",
  124. "deinterlace_vaapi",
  125. "tonemap_vaapi",
  126. "procamp_vaapi",
  127. "overlay_vaapi",
  128. "transpose_vaapi",
  129. "hwupload_vaapi",
  130. // vulkan
  131. "libplacebo",
  132. "scale_vulkan",
  133. "overlay_vulkan",
  134. "transpose_vulkan",
  135. "flip_vulkan",
  136. // videotoolbox
  137. "yadif_videotoolbox",
  138. "bwdif_videotoolbox",
  139. "scale_vt",
  140. "transpose_vt",
  141. "overlay_videotoolbox",
  142. "tonemap_videotoolbox",
  143. // rkrga
  144. "scale_rkrga",
  145. "vpp_rkrga",
  146. "overlay_rkrga"
  147. ];
  148. private static readonly Dictionary<FilterOptionType, (string, string)> _filterOptionsDict = new Dictionary<FilterOptionType, (string, string)>
  149. {
  150. { FilterOptionType.ScaleCudaFormat, ("scale_cuda", "format") },
  151. { FilterOptionType.TonemapCudaName, ("tonemap_cuda", "GPU accelerated HDR to SDR tonemapping") },
  152. { FilterOptionType.TonemapOpenclBt2390, ("tonemap_opencl", "bt2390") },
  153. { FilterOptionType.OverlayOpenclFrameSync, ("overlay_opencl", "Action to take when encountering EOF from secondary input") },
  154. { FilterOptionType.OverlayVaapiFrameSync, ("overlay_vaapi", "Action to take when encountering EOF from secondary input") },
  155. { FilterOptionType.OverlayVulkanFrameSync, ("overlay_vulkan", "Action to take when encountering EOF from secondary input") },
  156. { FilterOptionType.TransposeOpenclReversal, ("transpose_opencl", "rotate by half-turn") },
  157. { FilterOptionType.OverlayOpenclAlphaFormat, ("overlay_opencl", "alpha_format") },
  158. { FilterOptionType.OverlayCudaAlphaFormat, ("overlay_cuda", "alpha_format") }
  159. };
  160. private static readonly Dictionary<BitStreamFilterOptionType, (string, string)> _bsfOptionsDict = new Dictionary<BitStreamFilterOptionType, (string, string)>
  161. {
  162. { BitStreamFilterOptionType.HevcMetadataRemoveDovi, ("hevc_metadata", "remove_dovi") },
  163. { BitStreamFilterOptionType.HevcMetadataRemoveHdr10Plus, ("hevc_metadata", "remove_hdr10plus") },
  164. { BitStreamFilterOptionType.Av1MetadataRemoveDovi, ("av1_metadata", "remove_dovi") },
  165. { BitStreamFilterOptionType.Av1MetadataRemoveHdr10Plus, ("av1_metadata", "remove_hdr10plus") },
  166. { BitStreamFilterOptionType.DoviRpuStrip, ("dovi_rpu", "strip") }
  167. };
  168. // These are the library versions that corresponds to our minimum ffmpeg version 4.4 according to the version table below
  169. // Refers to the versions in https://ffmpeg.org/download.html
  170. private static readonly Dictionary<string, Version> _ffmpegMinimumLibraryVersions = new Dictionary<string, Version>
  171. {
  172. { "libavutil", new Version(56, 70) },
  173. { "libavcodec", new Version(58, 134) },
  174. { "libavformat", new Version(58, 76) },
  175. { "libavdevice", new Version(58, 13) },
  176. { "libavfilter", new Version(7, 110) },
  177. { "libswscale", new Version(5, 9) },
  178. { "libswresample", new Version(3, 9) },
  179. { "libpostproc", new Version(55, 9) }
  180. };
  181. private readonly ILogger _logger;
  182. private readonly string _encoderPath;
  183. private readonly Version _minFFmpegMultiThreadedCli = new Version(7, 0);
  184. public EncoderValidator(ILogger logger, string encoderPath)
  185. {
  186. _logger = logger;
  187. _encoderPath = encoderPath;
  188. }
  189. private enum Codec
  190. {
  191. Encoder,
  192. Decoder
  193. }
  194. // When changing this, also change the minimum library versions in _ffmpegMinimumLibraryVersions
  195. public static Version MinVersion { get; } = new Version(4, 4);
  196. public static Version? MaxVersion { get; } = null;
  197. [GeneratedRegex(@"^ffmpeg version n?((?:[0-9]+\.?)+)")]
  198. private static partial Regex FfmpegVersionRegex();
  199. [GeneratedRegex(@"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))", RegexOptions.Multiline)]
  200. private static partial Regex LibraryRegex();
  201. public bool ValidateVersion()
  202. {
  203. string output;
  204. try
  205. {
  206. output = GetProcessOutput(_encoderPath, "-version", false, null);
  207. }
  208. catch (Exception ex)
  209. {
  210. _logger.LogError(ex, "Error validating encoder");
  211. return false;
  212. }
  213. if (string.IsNullOrWhiteSpace(output))
  214. {
  215. _logger.LogError("FFmpeg validation: The process returned no result");
  216. return false;
  217. }
  218. _logger.LogDebug("ffmpeg output: {Output}", output);
  219. return ValidateVersionInternal(output);
  220. }
  221. internal bool ValidateVersionInternal(string versionOutput)
  222. {
  223. if (versionOutput.Contains("Libav developers", StringComparison.OrdinalIgnoreCase))
  224. {
  225. _logger.LogError("FFmpeg validation: avconv instead of ffmpeg is not supported");
  226. return false;
  227. }
  228. // Work out what the version under test is
  229. var version = GetFFmpegVersionInternal(versionOutput);
  230. _logger.LogInformation("Found ffmpeg version {Version}", version is not null ? version.ToString() : "unknown");
  231. if (version is null)
  232. {
  233. if (MaxVersion is not null) // Version is unknown
  234. {
  235. if (MinVersion == MaxVersion)
  236. {
  237. _logger.LogWarning("FFmpeg validation: We recommend version {MinVersion}", MinVersion);
  238. }
  239. else
  240. {
  241. _logger.LogWarning("FFmpeg validation: We recommend a minimum of {MinVersion} and maximum of {MaxVersion}", MinVersion, MaxVersion);
  242. }
  243. }
  244. else
  245. {
  246. _logger.LogWarning("FFmpeg validation: We recommend minimum version {MinVersion}", MinVersion);
  247. }
  248. return false;
  249. }
  250. if (version < MinVersion) // Version is below what we recommend
  251. {
  252. _logger.LogWarning("FFmpeg validation: The minimum recommended version is {MinVersion}", MinVersion);
  253. return false;
  254. }
  255. if (MaxVersion is not null && version > MaxVersion) // Version is above what we recommend
  256. {
  257. _logger.LogWarning("FFmpeg validation: The maximum recommended version is {MaxVersion}", MaxVersion);
  258. return false;
  259. }
  260. return true;
  261. }
  262. public IEnumerable<string> GetDecoders() => GetCodecs(Codec.Decoder);
  263. public IEnumerable<string> GetEncoders() => GetCodecs(Codec.Encoder);
  264. public IEnumerable<string> GetHwaccels() => GetHwaccelTypes();
  265. public IEnumerable<string> GetFilters() => GetFFmpegFilters();
  266. public IDictionary<FilterOptionType, bool> GetFiltersWithOption() => _filterOptionsDict
  267. .ToDictionary(item => item.Key, item => CheckFilterWithOption(item.Value.Item1, item.Value.Item2));
  268. public IDictionary<BitStreamFilterOptionType, bool> GetBitStreamFiltersWithOption() => _bsfOptionsDict
  269. .ToDictionary(item => item.Key, item => CheckBitStreamFilterWithOption(item.Value.Item1, item.Value.Item2));
  270. public Version? GetFFmpegVersion()
  271. {
  272. string output;
  273. try
  274. {
  275. output = GetProcessOutput(_encoderPath, "-version", false, null);
  276. }
  277. catch (Exception ex)
  278. {
  279. _logger.LogError(ex, "Error validating encoder");
  280. return null;
  281. }
  282. if (string.IsNullOrWhiteSpace(output))
  283. {
  284. _logger.LogError("FFmpeg validation: The process returned no result");
  285. return null;
  286. }
  287. _logger.LogDebug("ffmpeg output: {Output}", output);
  288. return GetFFmpegVersionInternal(output);
  289. }
  290. /// <summary>
  291. /// Using the output from "ffmpeg -version" work out the FFmpeg version.
  292. /// For pre-built binaries the first line should contain a string like "ffmpeg version x.y", which is easy
  293. /// to parse. If this is not available, then we try to match known library versions to FFmpeg versions.
  294. /// If that fails then we test the libraries to determine if they're newer than our minimum versions.
  295. /// </summary>
  296. /// <param name="output">The output from "ffmpeg -version".</param>
  297. /// <returns>The FFmpeg version.</returns>
  298. internal Version? GetFFmpegVersionInternal(string output)
  299. {
  300. // For pre-built binaries the FFmpeg version should be mentioned at the very start of the output
  301. var match = FfmpegVersionRegex().Match(output);
  302. if (match.Success)
  303. {
  304. if (Version.TryParse(match.Groups[1].ValueSpan, out var result))
  305. {
  306. return result;
  307. }
  308. }
  309. var versionMap = GetFFmpegLibraryVersions(output);
  310. var allVersionsValidated = true;
  311. foreach (var minimumVersion in _ffmpegMinimumLibraryVersions)
  312. {
  313. if (versionMap.TryGetValue(minimumVersion.Key, out var foundVersion))
  314. {
  315. if (foundVersion >= minimumVersion.Value)
  316. {
  317. _logger.LogInformation("Found {Library} version {FoundVersion} ({MinimumVersion})", minimumVersion.Key, foundVersion, minimumVersion.Value);
  318. }
  319. else
  320. {
  321. _logger.LogWarning("Found {Library} version {FoundVersion} lower than recommended version {MinimumVersion}", minimumVersion.Key, foundVersion, minimumVersion.Value);
  322. allVersionsValidated = false;
  323. }
  324. }
  325. else
  326. {
  327. _logger.LogError("{Library} version not found", minimumVersion.Key);
  328. allVersionsValidated = false;
  329. }
  330. }
  331. return allVersionsValidated ? MinVersion : null;
  332. }
  333. /// <summary>
  334. /// Grabs the library names and major.minor version numbers from the 'ffmpeg -version' output
  335. /// and condenses them on to one line. Output format is "name1=major.minor,name2=major.minor,etc.".
  336. /// </summary>
  337. /// <param name="output">The 'ffmpeg -version' output.</param>
  338. /// <returns>The library names and major.minor version numbers.</returns>
  339. private static Dictionary<string, Version> GetFFmpegLibraryVersions(string output)
  340. {
  341. var map = new Dictionary<string, Version>();
  342. foreach (Match match in LibraryRegex().Matches(output))
  343. {
  344. var version = new Version(
  345. int.Parse(match.Groups["major"].ValueSpan, CultureInfo.InvariantCulture),
  346. int.Parse(match.Groups["minor"].ValueSpan, CultureInfo.InvariantCulture));
  347. map.Add(match.Groups["name"].Value, version);
  348. }
  349. return map;
  350. }
  351. public bool CheckVaapiDeviceByDriverName(string driverName, string renderNodePath)
  352. {
  353. if (!OperatingSystem.IsLinux())
  354. {
  355. return false;
  356. }
  357. if (string.IsNullOrEmpty(driverName) || string.IsNullOrEmpty(renderNodePath))
  358. {
  359. return false;
  360. }
  361. try
  362. {
  363. var output = GetProcessOutput(_encoderPath, "-v verbose -hide_banner -init_hw_device vaapi=va:" + renderNodePath, true, null);
  364. return output.Contains(driverName, StringComparison.Ordinal);
  365. }
  366. catch (Exception ex)
  367. {
  368. _logger.LogError(ex, "Error detecting the given vaapi render node path");
  369. return false;
  370. }
  371. }
  372. public bool CheckVulkanDrmDeviceByExtensionName(string renderNodePath, string[] vulkanExtensions)
  373. {
  374. if (!OperatingSystem.IsLinux())
  375. {
  376. return false;
  377. }
  378. if (string.IsNullOrEmpty(renderNodePath))
  379. {
  380. return false;
  381. }
  382. try
  383. {
  384. var command = "-v verbose -hide_banner -init_hw_device drm=dr:" + renderNodePath + " -init_hw_device vulkan=vk@dr";
  385. var output = GetProcessOutput(_encoderPath, command, true, null);
  386. foreach (string ext in vulkanExtensions)
  387. {
  388. if (!output.Contains(ext, StringComparison.Ordinal))
  389. {
  390. return false;
  391. }
  392. }
  393. return true;
  394. }
  395. catch (Exception ex)
  396. {
  397. _logger.LogError(ex, "Error detecting the given drm render node path");
  398. return false;
  399. }
  400. }
  401. [SupportedOSPlatform("macos")]
  402. public bool CheckIsVideoToolboxAv1DecodeAvailable()
  403. {
  404. return ApplePlatformHelper.HasAv1HardwareAccel(_logger);
  405. }
  406. private IEnumerable<string> GetHwaccelTypes()
  407. {
  408. string? output = null;
  409. try
  410. {
  411. output = GetProcessOutput(_encoderPath, "-hwaccels", false, null);
  412. }
  413. catch (Exception ex)
  414. {
  415. _logger.LogError(ex, "Error detecting available hwaccel types");
  416. }
  417. if (string.IsNullOrWhiteSpace(output))
  418. {
  419. return [];
  420. }
  421. var found = output.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries).Skip(1).Distinct().ToList();
  422. _logger.LogInformation("Available hwaccel types: {Types}", found);
  423. return found;
  424. }
  425. public bool CheckFilterWithOption(string filter, string option)
  426. {
  427. if (string.IsNullOrEmpty(filter) || string.IsNullOrEmpty(option))
  428. {
  429. return false;
  430. }
  431. string output;
  432. try
  433. {
  434. output = GetProcessOutput(_encoderPath, "-h filter=" + filter, false, null);
  435. }
  436. catch (Exception ex)
  437. {
  438. _logger.LogError(ex, "Error detecting the given filter");
  439. return false;
  440. }
  441. if (output.Contains("Filter " + filter, StringComparison.Ordinal))
  442. {
  443. return output.Contains(option, StringComparison.Ordinal);
  444. }
  445. _logger.LogWarning("Filter: {Name} with option {Option} is not available", filter, option);
  446. return false;
  447. }
  448. public bool CheckBitStreamFilterWithOption(string filter, string option)
  449. {
  450. if (string.IsNullOrEmpty(filter) || string.IsNullOrEmpty(option))
  451. {
  452. return false;
  453. }
  454. string output;
  455. try
  456. {
  457. output = GetProcessOutput(_encoderPath, "-h bsf=" + filter, false, null);
  458. }
  459. catch (Exception ex)
  460. {
  461. _logger.LogError(ex, "Error detecting the given bit stream filter");
  462. return false;
  463. }
  464. if (output.Contains("Bit stream filter " + filter, StringComparison.Ordinal))
  465. {
  466. return output.Contains(option, StringComparison.Ordinal);
  467. }
  468. _logger.LogWarning("Bit stream filter: {Name} with option {Option} is not available", filter, option);
  469. return false;
  470. }
  471. public bool CheckSupportedRuntimeKey(string keyDesc, Version? ffmpegVersion)
  472. {
  473. if (string.IsNullOrEmpty(keyDesc))
  474. {
  475. return false;
  476. }
  477. string output;
  478. try
  479. {
  480. // With multi-threaded cli support, FFmpeg 7 is less sensitive to keyboard input
  481. var duration = ffmpegVersion >= _minFFmpegMultiThreadedCli ? 10000 : 1000;
  482. output = GetProcessOutput(_encoderPath, $"-hide_banner -f lavfi -i nullsrc=s=1x1:d={duration} -f null -", true, "?");
  483. }
  484. catch (Exception ex)
  485. {
  486. _logger.LogError(ex, "Error checking supported runtime key");
  487. return false;
  488. }
  489. return output.Contains(keyDesc, StringComparison.Ordinal);
  490. }
  491. public bool CheckSupportedHwaccelFlag(string flag)
  492. {
  493. return !string.IsNullOrEmpty(flag) && GetProcessExitCode(_encoderPath, $"-loglevel quiet -hwaccel_flags +{flag} -hide_banner -f lavfi -i nullsrc=s=1x1:d=100 -f null -");
  494. }
  495. public bool CheckSupportedProberOption(string option, string proberPath)
  496. {
  497. return !string.IsNullOrEmpty(option) && GetProcessExitCode(proberPath, $"-loglevel quiet -f lavfi -i nullsrc=s=1x1:d=1 -{option}");
  498. }
  499. private IEnumerable<string> GetCodecs(Codec codec)
  500. {
  501. string codecstr = codec == Codec.Encoder ? "encoders" : "decoders";
  502. string output;
  503. try
  504. {
  505. output = GetProcessOutput(_encoderPath, "-" + codecstr, false, null);
  506. }
  507. catch (Exception ex)
  508. {
  509. _logger.LogError(ex, "Error detecting available {Codec}", codecstr);
  510. return [];
  511. }
  512. if (string.IsNullOrWhiteSpace(output))
  513. {
  514. return [];
  515. }
  516. var required = codec == Codec.Encoder ? _requiredEncoders : _requiredDecoders;
  517. var found = CodecRegex()
  518. .Matches(output)
  519. .Select(x => x.Groups["codec"].Value)
  520. .Where(x => required.Contains(x));
  521. _logger.LogInformation("Available {Codec}: {Codecs}", codecstr, found);
  522. return found;
  523. }
  524. private IEnumerable<string> GetFFmpegFilters()
  525. {
  526. string output;
  527. try
  528. {
  529. output = GetProcessOutput(_encoderPath, "-filters", false, null);
  530. }
  531. catch (Exception ex)
  532. {
  533. _logger.LogError(ex, "Error detecting available filters");
  534. return [];
  535. }
  536. if (string.IsNullOrWhiteSpace(output))
  537. {
  538. return [];
  539. }
  540. var found = FilterRegex()
  541. .Matches(output)
  542. .Select(x => x.Groups["filter"].Value)
  543. .Where(x => _requiredFilters.Contains(x));
  544. _logger.LogInformation("Available filters: {Filters}", found);
  545. return found;
  546. }
  547. private string GetProcessOutput(string path, string arguments, bool readStdErr, string? testKey)
  548. {
  549. var redirectStandardIn = !string.IsNullOrEmpty(testKey);
  550. using (var process = new Process
  551. {
  552. StartInfo = new ProcessStartInfo(path, arguments)
  553. {
  554. CreateNoWindow = true,
  555. UseShellExecute = false,
  556. WindowStyle = ProcessWindowStyle.Hidden,
  557. ErrorDialog = false,
  558. RedirectStandardInput = redirectStandardIn,
  559. RedirectStandardOutput = true,
  560. RedirectStandardError = true
  561. }
  562. })
  563. {
  564. _logger.LogDebug("Running {Path} {Arguments}", path, arguments);
  565. process.Start();
  566. if (redirectStandardIn)
  567. {
  568. using var writer = process.StandardInput;
  569. writer.Write(testKey);
  570. }
  571. using var reader = readStdErr ? process.StandardError : process.StandardOutput;
  572. return reader.ReadToEnd();
  573. }
  574. }
  575. private bool GetProcessExitCode(string path, string arguments)
  576. {
  577. using var process = new Process();
  578. process.StartInfo = new ProcessStartInfo(path, arguments)
  579. {
  580. CreateNoWindow = true,
  581. UseShellExecute = false,
  582. WindowStyle = ProcessWindowStyle.Hidden,
  583. ErrorDialog = false
  584. };
  585. _logger.LogDebug("Running {Path} {Arguments}", path, arguments);
  586. try
  587. {
  588. process.Start();
  589. process.WaitForExit();
  590. return process.ExitCode == 0;
  591. }
  592. catch (Exception ex)
  593. {
  594. _logger.LogError("Running {Path} {Arguments} failed with exception {Exception}", path, arguments, ex.Message);
  595. return false;
  596. }
  597. }
  598. [GeneratedRegex("^\\s\\S{6}\\s(?<codec>[\\w|-]+)\\s+.+$", RegexOptions.Multiline)]
  599. private static partial Regex CodecRegex();
  600. [GeneratedRegex("^\\s\\S{3}\\s(?<filter>[\\w|-]+)\\s+.+$", RegexOptions.Multiline)]
  601. private static partial Regex FilterRegex();
  602. }
  603. }