EncoderValidator.cs 24 KB

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