Bläddra i källkod

Fix ffmpeg version check for unknown versions

Bond_009 5 år sedan
förälder
incheckning
3e1aab6b29

+ 11 - 8
MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs

@@ -118,15 +118,18 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
             _logger.LogInformation("Found ffmpeg version {0}", version != null ? version.ToString() : "unknown");
 
-            if (version == null && MinVersion != null && MaxVersion != null) // Version is unknown
+            if (version == null)
             {
-                if (MinVersion == MaxVersion)
+                if (MinVersion != null && MaxVersion != null) // Version is unknown
                 {
-                    _logger.LogWarning("FFmpeg validation: We recommend ffmpeg version {0}", MinVersion);
-                }
-                else
-                {
-                    _logger.LogWarning("FFmpeg validation: We recommend a minimum of {0} and maximum of {1}", MinVersion, MaxVersion);
+                    if (MinVersion == MaxVersion)
+                    {
+                        _logger.LogWarning("FFmpeg validation: We recommend ffmpeg version {0}", MinVersion);
+                    }
+                    else
+                    {
+                        _logger.LogWarning("FFmpeg validation: We recommend a minimum of {0} and maximum of {1}", MinVersion, MaxVersion);
+                    }
                 }
 
                 return false;
@@ -161,7 +164,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
         internal static 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 ((?:\d+\.?)+)");
+            var match = Regex.Match(output, @"^ffmpeg version n?((?:\d+\.?)+)");
 
             if (match.Success)
             {

+ 4 - 0
tests/Jellyfin.MediaEncoding.Tests/EncoderValidatorTests.cs

@@ -13,9 +13,11 @@ namespace Jellyfin.MediaEncoding.Tests
         {
             public IEnumerator<object[]> GetEnumerator()
             {
+                yield return new object[] { EncoderValidatorTestsData.FFmpegV421Output, new Version(4, 2, 1) };
                 yield return new object[] { EncoderValidatorTestsData.FFmpegV42Output, new Version(4, 2) };
                 yield return new object[] { EncoderValidatorTestsData.FFmpegV414Output, new Version(4, 1, 4) };
                 yield return new object[] { EncoderValidatorTestsData.FFmpegV404Output, new Version(4, 0, 4) };
+                yield return new object[] { EncoderValidatorTestsData.FFmpegGitUnknownOutput, null };
             }
 
             IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
@@ -29,9 +31,11 @@ namespace Jellyfin.MediaEncoding.Tests
         }
 
         [Theory]
+        [InlineData(EncoderValidatorTestsData.FFmpegV421Output, true)]
         [InlineData(EncoderValidatorTestsData.FFmpegV42Output, true)]
         [InlineData(EncoderValidatorTestsData.FFmpegV414Output, true)]
         [InlineData(EncoderValidatorTestsData.FFmpegV404Output, true)]
+        [InlineData(EncoderValidatorTestsData.FFmpegGitUnknownOutput, false)]
         public void ValidateVersionInternalTest(string versionOutput, bool valid)
         {
             var val = new EncoderValidator(new NullLogger<EncoderValidatorTests>());

+ 26 - 6
tests/Jellyfin.MediaEncoding.Tests/EncoderValidatorTestsData.cs

@@ -2,6 +2,18 @@ namespace Jellyfin.MediaEncoding.Tests
 {
     internal static class EncoderValidatorTestsData
     {
+        public const string FFmpegV421Output = @"ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
+built with gcc 9.1.1 (GCC) 20190807
+configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
+libavutil      56. 31.100 / 56. 31.100
+libavcodec     58. 54.100 / 58. 54.100
+libavformat    58. 29.100 / 58. 29.100
+libavdevice    58.  8.100 / 58.  8.100
+libavfilter     7. 57.100 /  7. 57.100
+libswscale      5.  5.100 /  5.  5.100
+libswresample   3.  5.100 /  3.  5.100
+libpostproc    55.  5.100 / 55.  5.100";
+
         public const string FFmpegV42Output = @"ffmpeg version n4.2 Copyright (c) 2000-2019 the FFmpeg developers
 built with gcc 9.1.0 (GCC)
 configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
@@ -12,8 +24,7 @@ libavdevice    58.  8.100 / 58.  8.100
 libavfilter     7. 57.100 /  7. 57.100
 libswscale      5.  5.100 /  5.  5.100
 libswresample   3.  5.100 /  3.  5.100
-libpostproc    55.  5.100 / 55.  5.100
-";
+libpostproc    55.  5.100 / 55.  5.100";
 
     public const string FFmpegV414Output = @"ffmpeg version 4.1.4-1~deb10u1 Copyright (c) 2000-2019 the FFmpeg developers
 built with gcc 8 (Raspbian 8.3.0-6+rpi1)
@@ -26,8 +37,7 @@ libavfilter     7. 40.101 /  7. 40.101
 libavresample   4.  0.  0 /  4.  0.  0
 libswscale      5.  3.100 /  5.  3.100
 libswresample   3.  3.100 /  3.  3.100
-libpostproc    55.  3.100 / 55.  3.100
-";
+libpostproc    55.  3.100 / 55.  3.100";
 
     public const string FFmpegV404Output = @"ffmpeg version 4.0.4 Copyright (c) 2000-2019 the FFmpeg developers
 built with gcc 8 (Debian 8.3.0-6)
@@ -39,8 +49,18 @@ libavdevice    58.  3.100 / 58.  3.100
 libavfilter     7. 16.100 /  7. 16.100
 libswscale      5.  1.100 /  5.  1.100
 libswresample   3.  1.100 /  3.  1.100
-libpostproc    55.  1.100 / 55.  1.100
-";
+libpostproc    55.  1.100 / 55.  1.100";
 
+    public const string FFmpegGitUnknownOutput = @"ffmpeg version N-94303-g7cb4f8c962 Copyright (c) 2000-2019 the FFmpeg developers
+built with gcc 9.1.1 (GCC) 20190716
+configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
+libavutil      56. 30.100 / 56. 30.100
+libavcodec     58. 53.101 / 58. 53.101
+libavformat    58. 28.102 / 58. 28.102
+libavdevice    58.  7.100 / 58.  7.100
+libavfilter     7. 56.101 /  7. 56.101
+libswscale      5.  4.101 /  5.  4.101
+libswresample   3.  4.100 /  3.  4.100
+libpostproc    55.  4.100 / 55.  4.100";
     }
 }