EncoderValidator.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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 = new[]
  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 = new[]
  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 = new[]
  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<int, string[]> _filterOptionsDict = new Dictionary<int, string[]>
  149. {
  150. { 0, new string[] { "scale_cuda", "format" } },
  151. { 1, new string[] { "tonemap_cuda", "GPU accelerated HDR to SDR tonemapping" } },
  152. { 2, new string[] { "tonemap_opencl", "bt2390" } },
  153. { 3, new string[] { "overlay_opencl", "Action to take when encountering EOF from secondary input" } },
  154. { 4, new string[] { "overlay_vaapi", "Action to take when encountering EOF from secondary input" } },
  155. { 5, new string[] { "overlay_vulkan", "Action to take when encountering EOF from secondary input" } },
  156. { 6, new string[] { "transpose_opencl", "rotate by half-turn" } }
  157. };
  158. private static readonly Dictionary<BitStreamFilterOptionType, (string, string)> _bsfOptionsDict = new Dictionary<BitStreamFilterOptionType, (string, string)>
  159. {
  160. { BitStreamFilterOptionType.HevcMetadataRemoveDovi, ("hevc_metadata", "remove_dovi") },
  161. { BitStreamFilterOptionType.HevcMetadataRemoveHdr10Plus, ("hevc_metadata", "remove_hdr10plus") },
  162. { BitStreamFilterOptionType.Av1MetadataRemoveDovi, ("av1_metadata", "remove_dovi") },
  163. { BitStreamFilterOptionType.Av1MetadataRemoveHdr10Plus, ("av1_metadata", "remove_hdr10plus") },
  164. { BitStreamFilterOptionType.DoviRpuStrip, ("dovi_rpu", "strip") }
  165. };
  166. // These are the library versions that corresponds to our minimum ffmpeg version 4.4 according to the version table below
  167. // Refers to the versions in https://ffmpeg.org/download.html
  168. private static readonly Dictionary<string, Version> _ffmpegMinimumLibraryVersions = new Dictionary<string, Version>
  169. {
  170. { "libavutil", new Version(56, 70) },
  171. { "libavcodec", new Version(58, 134) },
  172. { "libavformat", new Version(58, 76) },
  173. { "libavdevice", new Version(58, 13) },
  174. { "libavfilter", new Version(7, 110) },
  175. { "libswscale", new Version(5, 9) },
  176. { "libswresample", new Version(3, 9) },
  177. { "libpostproc", new Version(55, 9) }
  178. };
  179. private readonly ILogger _logger;
  180. private readonly string _encoderPath;
  181. private readonly Version _minFFmpegMultiThreadedCli = new Version(7, 0);
  182. public EncoderValidator(ILogger logger, string encoderPath)
  183. {
  184. _logger = logger;
  185. _encoderPath = encoderPath;
  186. }
  187. private enum Codec
  188. {
  189. Encoder,
  190. Decoder
  191. }
  192. // When changing this, also change the minimum library versions in _ffmpegMinimumLibraryVersions
  193. public static Version MinVersion { get; } = new Version(4, 4);
  194. public static Version? MaxVersion { get; } = null;
  195. [GeneratedRegex(@"^ffmpeg version n?((?:[0-9]+\.?)+)")]
  196. private static partial Regex FfmpegVersionRegex();
  197. [GeneratedRegex(@"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))", RegexOptions.Multiline)]
  198. private static partial Regex LibraryRegex();
  199. public bool ValidateVersion()
  200. {
  201. string output;
  202. try
  203. {
  204. output = GetProcessOutput(_encoderPath, "-version", false, null);
  205. }
  206. catch (Exception ex)
  207. {
  208. _logger.LogError(ex, "Error validating encoder");
  209. return false;
  210. }
  211. if (string.IsNullOrWhiteSpace(output))
  212. {
  213. _logger.LogError("FFmpeg validation: The process returned no result");
  214. return false;
  215. }
  216. _logger.LogDebug("ffmpeg output: {Output}", output);
  217. return ValidateVersionInternal(output);
  218. }
  219. internal bool ValidateVersionInternal(string versionOutput)
  220. {
  221. if (versionOutput.Contains("Libav developers", StringComparison.OrdinalIgnoreCase))
  222. {
  223. _logger.LogError("FFmpeg validation: avconv instead of ffmpeg is not supported");
  224. return false;
  225. }
  226. // Work out what the version under test is
  227. var version = GetFFmpegVersionInternal(versionOutput);
  228. _logger.LogInformation("Found ffmpeg version {Version}", version is not null ? version.ToString() : "unknown");
  229. if (version is null)
  230. {
  231. if (MaxVersion is not null) // Version is unknown
  232. {
  233. if (MinVersion == MaxVersion)
  234. {
  235. _logger.LogWarning("FFmpeg validation: We recommend version {MinVersion}", MinVersion);
  236. }
  237. else
  238. {
  239. _logger.LogWarning("FFmpeg validation: We recommend a minimum of {MinVersion} and maximum of {MaxVersion}", MinVersion, MaxVersion);
  240. }
  241. }
  242. else
  243. {
  244. _logger.LogWarning("FFmpeg validation: We recommend minimum version {MinVersion}", MinVersion);
  245. }
  246. return false;
  247. }
  248. if (version < MinVersion) // Version is below what we recommend
  249. {
  250. _logger.LogWarning("FFmpeg validation: The minimum recommended version is {MinVersion}", MinVersion);
  251. return false;
  252. }
  253. if (MaxVersion is not null && version > MaxVersion) // Version is above what we recommend
  254. {
  255. _logger.LogWarning("FFmpeg validation: The maximum recommended version is {MaxVersion}", MaxVersion);
  256. return false;
  257. }
  258. return true;
  259. }
  260. public IEnumerable<string> GetDecoders() => GetCodecs(Codec.Decoder);
  261. public IEnumerable<string> GetEncoders() => GetCodecs(Codec.Encoder);
  262. public IEnumerable<string> GetHwaccels() => GetHwaccelTypes();
  263. public IEnumerable<string> GetFilters() => GetFFmpegFilters();
  264. public IDictionary<int, bool> GetFiltersWithOption() => GetFFmpegFiltersWithOption();
  265. public IDictionary<BitStreamFilterOptionType, bool> GetBitStreamFiltersWithOption() => _bsfOptionsDict
  266. .ToDictionary(item => item.Key, item => CheckBitStreamFilterWithOption(item.Value.Item1, item.Value.Item2));
  267. public Version? GetFFmpegVersion()
  268. {
  269. string output;
  270. try
  271. {
  272. output = GetProcessOutput(_encoderPath, "-version", false, null);
  273. }
  274. catch (Exception ex)
  275. {
  276. _logger.LogError(ex, "Error validating encoder");
  277. return null;
  278. }
  279. if (string.IsNullOrWhiteSpace(output))
  280. {
  281. _logger.LogError("FFmpeg validation: The process returned no result");
  282. return null;
  283. }
  284. _logger.LogDebug("ffmpeg output: {Output}", output);
  285. return GetFFmpegVersionInternal(output);
  286. }
  287. /// <summary>
  288. /// Using the output from "ffmpeg -version" work out the FFmpeg version.
  289. /// For pre-built binaries the first line should contain a string like "ffmpeg version x.y", which is easy
  290. /// to parse. If this is not available, then we try to match known library versions to FFmpeg versions.
  291. /// If that fails then we test the libraries to determine if they're newer than our minimum versions.
  292. /// </summary>
  293. /// <param name="output">The output from "ffmpeg -version".</param>
  294. /// <returns>The FFmpeg version.</returns>
  295. internal Version? GetFFmpegVersionInternal(string output)
  296. {
  297. // For pre-built binaries the FFmpeg version should be mentioned at the very start of the output
  298. var match = FfmpegVersionRegex().Match(output);
  299. if (match.Success)
  300. {
  301. if (Version.TryParse(match.Groups[1].ValueSpan, out var result))
  302. {
  303. return result;
  304. }
  305. }
  306. var versionMap = GetFFmpegLibraryVersions(output);
  307. var allVersionsValidated = true;
  308. foreach (var minimumVersion in _ffmpegMinimumLibraryVersions)
  309. {
  310. if (versionMap.TryGetValue(minimumVersion.Key, out var foundVersion))
  311. {
  312. if (foundVersion >= minimumVersion.Value)
  313. {
  314. _logger.LogInformation("Found {Library} version {FoundVersion} ({MinimumVersion})", minimumVersion.Key, foundVersion, minimumVersion.Value);
  315. }
  316. else
  317. {
  318. _logger.LogWarning("Found {Library} version {FoundVersion} lower than recommended version {MinimumVersion}", minimumVersion.Key, foundVersion, minimumVersion.Value);
  319. allVersionsValidated = false;
  320. }
  321. }
  322. else
  323. {
  324. _logger.LogError("{Library} version not found", minimumVersion.Key);
  325. allVersionsValidated = false;
  326. }
  327. }
  328. return allVersionsValidated ? MinVersion : null;
  329. }
  330. /// <summary>
  331. /// Grabs the library names and major.minor version numbers from the 'ffmpeg -version' output
  332. /// and condenses them on to one line. Output format is "name1=major.minor,name2=major.minor,etc.".
  333. /// </summary>
  334. /// <param name="output">The 'ffmpeg -version' output.</param>
  335. /// <returns>The library names and major.minor version numbers.</returns>
  336. private static Dictionary<string, Version> GetFFmpegLibraryVersions(string output)
  337. {
  338. var map = new Dictionary<string, Version>();
  339. foreach (Match match in LibraryRegex().Matches(output))
  340. {
  341. var version = new Version(
  342. int.Parse(match.Groups["major"].ValueSpan, CultureInfo.InvariantCulture),
  343. int.Parse(match.Groups["minor"].ValueSpan, CultureInfo.InvariantCulture));
  344. map.Add(match.Groups["name"].Value, version);
  345. }
  346. return map;
  347. }
  348. public bool CheckVaapiDeviceByDriverName(string driverName, string renderNodePath)
  349. {
  350. if (!OperatingSystem.IsLinux())
  351. {
  352. return false;
  353. }
  354. if (string.IsNullOrEmpty(driverName) || string.IsNullOrEmpty(renderNodePath))
  355. {
  356. return false;
  357. }
  358. try
  359. {
  360. var output = GetProcessOutput(_encoderPath, "-v verbose -hide_banner -init_hw_device vaapi=va:" + renderNodePath, true, null);
  361. return output.Contains(driverName, StringComparison.Ordinal);
  362. }
  363. catch (Exception ex)
  364. {
  365. _logger.LogError(ex, "Error detecting the given vaapi render node path");
  366. return false;
  367. }
  368. }
  369. public bool CheckVulkanDrmDeviceByExtensionName(string renderNodePath, string[] vulkanExtensions)
  370. {
  371. if (!OperatingSystem.IsLinux())
  372. {
  373. return false;
  374. }
  375. if (string.IsNullOrEmpty(renderNodePath))
  376. {
  377. return false;
  378. }
  379. try
  380. {
  381. var command = "-v verbose -hide_banner -init_hw_device drm=dr:" + renderNodePath + " -init_hw_device vulkan=vk@dr";
  382. var output = GetProcessOutput(_encoderPath, command, true, null);
  383. foreach (string ext in vulkanExtensions)
  384. {
  385. if (!output.Contains(ext, StringComparison.Ordinal))
  386. {
  387. return false;
  388. }
  389. }
  390. return true;
  391. }
  392. catch (Exception ex)
  393. {
  394. _logger.LogError(ex, "Error detecting the given drm render node path");
  395. return false;
  396. }
  397. }
  398. [SupportedOSPlatform("macos")]
  399. public bool CheckIsVideoToolboxAv1DecodeAvailable()
  400. {
  401. return ApplePlatformHelper.HasAv1HardwareAccel(_logger);
  402. }
  403. private IEnumerable<string> GetHwaccelTypes()
  404. {
  405. string? output = null;
  406. try
  407. {
  408. output = GetProcessOutput(_encoderPath, "-hwaccels", false, null);
  409. }
  410. catch (Exception ex)
  411. {
  412. _logger.LogError(ex, "Error detecting available hwaccel types");
  413. }
  414. if (string.IsNullOrWhiteSpace(output))
  415. {
  416. return Enumerable.Empty<string>();
  417. }
  418. var found = output.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).Distinct().ToList();
  419. _logger.LogInformation("Available hwaccel types: {Types}", found);
  420. return found;
  421. }
  422. public bool CheckFilterWithOption(string filter, string option)
  423. {
  424. if (string.IsNullOrEmpty(filter) || string.IsNullOrEmpty(option))
  425. {
  426. return false;
  427. }
  428. string output;
  429. try
  430. {
  431. output = GetProcessOutput(_encoderPath, "-h filter=" + filter, false, null);
  432. }
  433. catch (Exception ex)
  434. {
  435. _logger.LogError(ex, "Error detecting the given filter");
  436. return false;
  437. }
  438. if (output.Contains("Filter " + filter, StringComparison.Ordinal))
  439. {
  440. return output.Contains(option, StringComparison.Ordinal);
  441. }
  442. _logger.LogWarning("Filter: {Name} with option {Option} is not available", filter, option);
  443. return false;
  444. }
  445. public bool CheckBitStreamFilterWithOption(string filter, string option)
  446. {
  447. if (string.IsNullOrEmpty(filter) || string.IsNullOrEmpty(option))
  448. {
  449. return false;
  450. }
  451. string output;
  452. try
  453. {
  454. output = GetProcessOutput(_encoderPath, "-h bsf=" + filter, false, null);
  455. }
  456. catch (Exception ex)
  457. {
  458. _logger.LogError(ex, "Error detecting the given bit stream filter");
  459. return false;
  460. }
  461. if (output.Contains("Bit stream filter " + filter, StringComparison.Ordinal))
  462. {
  463. return output.Contains(option, StringComparison.Ordinal);
  464. }
  465. _logger.LogWarning("Bit stream filter: {Name} with option {Option} is not available", filter, option);
  466. return false;
  467. }
  468. public bool CheckSupportedRuntimeKey(string keyDesc, Version? ffmpegVersion)
  469. {
  470. if (string.IsNullOrEmpty(keyDesc))
  471. {
  472. return false;
  473. }
  474. string output;
  475. try
  476. {
  477. // With multi-threaded cli support, FFmpeg 7 is less sensitive to keyboard input
  478. var duration = ffmpegVersion >= _minFFmpegMultiThreadedCli ? 10000 : 1000;
  479. output = GetProcessOutput(_encoderPath, $"-hide_banner -f lavfi -i nullsrc=s=1x1:d={duration} -f null -", true, "?");
  480. }
  481. catch (Exception ex)
  482. {
  483. _logger.LogError(ex, "Error checking supported runtime key");
  484. return false;
  485. }
  486. return output.Contains(keyDesc, StringComparison.Ordinal);
  487. }
  488. public bool CheckSupportedHwaccelFlag(string flag)
  489. {
  490. return !string.IsNullOrEmpty(flag) && GetProcessExitCode(_encoderPath, $"-loglevel quiet -hwaccel_flags +{flag} -hide_banner -f lavfi -i nullsrc=s=1x1:d=100 -f null -");
  491. }
  492. public bool CheckSupportedProberOption(string option, string proberPath)
  493. {
  494. return !string.IsNullOrEmpty(option) && GetProcessExitCode(proberPath, $"-loglevel quiet -f lavfi -i nullsrc=s=1x1:d=1 -{option}");
  495. }
  496. private IEnumerable<string> GetCodecs(Codec codec)
  497. {
  498. string codecstr = codec == Codec.Encoder ? "encoders" : "decoders";
  499. string output;
  500. try
  501. {
  502. output = GetProcessOutput(_encoderPath, "-" + codecstr, false, null);
  503. }
  504. catch (Exception ex)
  505. {
  506. _logger.LogError(ex, "Error detecting available {Codec}", codecstr);
  507. return Enumerable.Empty<string>();
  508. }
  509. if (string.IsNullOrWhiteSpace(output))
  510. {
  511. return Enumerable.Empty<string>();
  512. }
  513. var required = codec == Codec.Encoder ? _requiredEncoders : _requiredDecoders;
  514. var found = CodecRegex()
  515. .Matches(output)
  516. .Select(x => x.Groups["codec"].Value)
  517. .Where(x => required.Contains(x));
  518. _logger.LogInformation("Available {Codec}: {Codecs}", codecstr, found);
  519. return found;
  520. }
  521. private IEnumerable<string> GetFFmpegFilters()
  522. {
  523. string output;
  524. try
  525. {
  526. output = GetProcessOutput(_encoderPath, "-filters", false, null);
  527. }
  528. catch (Exception ex)
  529. {
  530. _logger.LogError(ex, "Error detecting available filters");
  531. return Enumerable.Empty<string>();
  532. }
  533. if (string.IsNullOrWhiteSpace(output))
  534. {
  535. return Enumerable.Empty<string>();
  536. }
  537. var found = FilterRegex()
  538. .Matches(output)
  539. .Select(x => x.Groups["filter"].Value)
  540. .Where(x => _requiredFilters.Contains(x));
  541. _logger.LogInformation("Available filters: {Filters}", found);
  542. return found;
  543. }
  544. private Dictionary<int, bool> GetFFmpegFiltersWithOption()
  545. {
  546. Dictionary<int, bool> dict = new Dictionary<int, bool>();
  547. for (int i = 0; i < _filterOptionsDict.Count; i++)
  548. {
  549. if (_filterOptionsDict.TryGetValue(i, out var val) && val.Length == 2)
  550. {
  551. dict.Add(i, CheckFilterWithOption(val[0], val[1]));
  552. }
  553. }
  554. return dict;
  555. }
  556. private string GetProcessOutput(string path, string arguments, bool readStdErr, string? testKey)
  557. {
  558. var redirectStandardIn = !string.IsNullOrEmpty(testKey);
  559. using (var process = new Process
  560. {
  561. StartInfo = new ProcessStartInfo(path, arguments)
  562. {
  563. CreateNoWindow = true,
  564. UseShellExecute = false,
  565. WindowStyle = ProcessWindowStyle.Hidden,
  566. ErrorDialog = false,
  567. RedirectStandardInput = redirectStandardIn,
  568. RedirectStandardOutput = true,
  569. RedirectStandardError = true
  570. }
  571. })
  572. {
  573. _logger.LogDebug("Running {Path} {Arguments}", path, arguments);
  574. process.Start();
  575. if (redirectStandardIn)
  576. {
  577. using var writer = process.StandardInput;
  578. writer.Write(testKey);
  579. }
  580. using var reader = readStdErr ? process.StandardError : process.StandardOutput;
  581. return reader.ReadToEnd();
  582. }
  583. }
  584. private bool GetProcessExitCode(string path, string arguments)
  585. {
  586. using var process = new Process();
  587. process.StartInfo = new ProcessStartInfo(path, arguments)
  588. {
  589. CreateNoWindow = true,
  590. UseShellExecute = false,
  591. WindowStyle = ProcessWindowStyle.Hidden,
  592. ErrorDialog = false
  593. };
  594. _logger.LogDebug("Running {Path} {Arguments}", path, arguments);
  595. try
  596. {
  597. process.Start();
  598. process.WaitForExit();
  599. return process.ExitCode == 0;
  600. }
  601. catch (Exception ex)
  602. {
  603. _logger.LogError("Running {Path} {Arguments} failed with exception {Exception}", path, arguments, ex.Message);
  604. return false;
  605. }
  606. }
  607. [GeneratedRegex("^\\s\\S{6}\\s(?<codec>[\\w|-]+)\\s+.+$", RegexOptions.Multiline)]
  608. private static partial Regex CodecRegex();
  609. [GeneratedRegex("^\\s\\S{3}\\s(?<filter>[\\w|-]+)\\s+.+$", RegexOptions.Multiline)]
  610. private static partial Regex FilterRegex();
  611. }
  612. }