Skip to content

The Free Software Media System - Server Backend & API

Merge branch 'master' into feature/ffmpeg-version-check

Bond-0095160e627f18f
diff --cc MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
index 5a7fabf843,75123a843e..0e9a5e502a
--- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
@@@ -204,15 -197,16 +213,15 @@@ namespace MediaBrowser.MediaEncoding.En
/// <summary>
/// Using the output from "ffmpeg -version" work out the FFmpeg version.
/// For pre-built binaries the first line should contain a string like "ffmpeg version x.y", which is easy
- /// to parse. If this is not available, then we try to match known library versions to FFmpeg versions.
- /// If that fails then we use one of the main libraries to determine if it's new/older than the latest
- /// we have stored.
+ /// to parse. If this is not available, then we try to match known library versions to FFmpeg versions.
+ /// If that fails then we test the libraries to determine if they're newer than our minimum versions.
/// </summary>
- /// <param name="output"></param>
- /// <returns></returns>
+ /// <param name="output">The output from "ffmpeg -version".</param>
+ /// <returns>The FFmpeg version.</returns>
- internal static Version GetFFmpegVersion(string output)
+ internal Version GetFFmpegVersion(string output)
{
// For pre-built binaries the FFmpeg version should be mentioned at the very start of the output
- var match = Regex.Match(output, @"^ffmpeg version n?((?:\d+\.?)+)");
+ var match = Regex.Match(output, @"^ffmpeg version n?((?:[0-9]+\.?)+)");
if (match.Success)
{
@@@ -238,78 -222,31 +247,71 @@@
}
}
+ private Version TestMinimumFFmpegLibraryVersions(IReadOnlyDictionary<string, Version> versionMap)
+ {
+ var allVersionsValidated = true;
+
+ foreach (var minimumVersion in _ffmpegMinimumLibraryVersions)
+ {
+ if (versionMap.TryGetValue(minimumVersion.Key, out var foundVersion))
+ {
+ if (foundVersion >= minimumVersion.Value)
+ {
+ _logger.LogInformation("Found {Library} version {FoundVersion} ({MinimumVersion})", minimumVersion.Key, foundVersion, minimumVersion.Value);
+ }
+ else
+ {
+ _logger.LogWarning("Found {Library} version {FoundVersion} lower than recommended version {MinimumVersion}", minimumVersion.Key, foundVersion, minimumVersion.Value);
+ allVersionsValidated = false;
+ }
+ }
+ else
+ {
+ _logger.LogError("{Library} version not found", minimumVersion.Key);
+ allVersionsValidated = false;
+ }
+ }
+
+ return allVersionsValidated ? MinVersion : null;
+ }
+
/// <summary>
/// Grabs the library names and major.minor version numbers from the 'ffmpeg -version' output
+ /// and condenses them on to one line. Output format is "name1=major.minor,name2=major.minor,etc.".
/// </summary>
- /// <param name="output"></param>
- /// <param name="versionString"></param>
- /// <param name="versionMap"></param>
- /// <returns></returns>
+ /// <param name="output">The 'ffmpeg -version' output.</param>
+ /// <returns>The library names and major.minor version numbers.</returns>
- private static string GetLibrariesVersionString(string output)
+ private static bool TryGetFFmpegLibraryVersions(string output, out string versionString, out IReadOnlyDictionary<string, Version> versionMap)
{
- var rc = new StringBuilder(144);
- foreach (Match m in Regex.Matches(
+ var sb = new StringBuilder(144);
+
+ var map = new Dictionary<string, Version>();
+
+ foreach (Match match in Regex.Matches(
output,
- @"((?<name>lib\w+)\s+(?<major>\d+)\.\s*(?<minor>\d+))",
+ @"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))",
RegexOptions.Multiline))
{
- rc.Append(m.Groups["name"])
+ sb.Append(match.Groups["name"])
.Append('=')
- .Append(m.Groups["major"])
+ .Append(match.Groups["major"])
.Append('.')
- .Append(m.Groups["minor"])
+ .Append(match.Groups["minor"])
.Append(',');
+
+ var str = $"{match.Groups["major"]}.{match.Groups["minor"]}";
+
+ var version = Version.Parse(str);
+
+ map.Add(match.Groups["name"].Value, version);
}
- return rc.Length == 0 ? null : rc.ToString();
+ versionString = sb.ToString();
+ versionMap = map;
+
+ return sb.Length > 0;
}
- private enum Codec
- {
- Encoder,
- Decoder
- }
-
private IEnumerable<string> GetHwaccelTypes()
{
string output = null;