Browse Source

fix: discard webm if there is an unsupported codec

Dmitry Lyzo 1 year ago
parent
commit
39088b5ad2
1 changed files with 16 additions and 3 deletions
  1. 16 3
      MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

+ 16 - 3
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -30,6 +30,8 @@ namespace MediaBrowser.MediaEncoding.Probing
         private const string ArtistReplaceValue = " | ";
         private const string ArtistReplaceValue = " | ";
 
 
         private readonly char[] _nameDelimiters = { '/', '|', ';', '\\' };
         private readonly char[] _nameDelimiters = { '/', '|', ';', '\\' };
+        private readonly string[] _webmVideoCodecs = { "vp8", "vp9" };
+        private readonly string[] _webmAudioCodecs = { "opus", "vorbis" };
 
 
         private readonly ILogger _logger;
         private readonly ILogger _logger;
         private readonly ILocalizationManager _localization;
         private readonly ILocalizationManager _localization;
@@ -114,7 +116,7 @@ namespace MediaBrowser.MediaEncoding.Probing
 
 
             if (data.Format is not null)
             if (data.Format is not null)
             {
             {
-                info.Container = NormalizeFormat(data.Format.FormatName);
+                info.Container = NormalizeFormat(data.Format.FormatName, info.MediaStreams);
 
 
                 if (int.TryParse(data.Format.BitRate, CultureInfo.InvariantCulture, out var value))
                 if (int.TryParse(data.Format.BitRate, CultureInfo.InvariantCulture, out var value))
                 {
                 {
@@ -260,7 +262,7 @@ namespace MediaBrowser.MediaEncoding.Probing
             return info;
             return info;
         }
         }
 
 
-        private string NormalizeFormat(string format)
+        private string NormalizeFormat(string format, IReadOnlyList<MediaStream> mediaStreams)
         {
         {
             if (string.IsNullOrWhiteSpace(format))
             if (string.IsNullOrWhiteSpace(format))
             {
             {
@@ -288,9 +290,20 @@ namespace MediaBrowser.MediaEncoding.Probing
                 {
                 {
                     splitFormat[i] = "mkv";
                     splitFormat[i] = "mkv";
                 }
                 }
+
+                // Handle WebM
+                else if (string.Equals(splitFormat[i], "webm", StringComparison.OrdinalIgnoreCase))
+                {
+                    // Limit WebM to supported codecs
+                    if (mediaStreams.Any(stream => (stream.Type == MediaStreamType.Video && !_webmVideoCodecs.Contains(stream.Codec, StringComparison.OrdinalIgnoreCase))
+                        || (stream.Type == MediaStreamType.Audio && !_webmAudioCodecs.Contains(stream.Codec, StringComparison.OrdinalIgnoreCase))))
+                    {
+                        splitFormat[i] = string.Empty;
+                    }
+                }
             }
             }
 
 
-            return string.Join(',', splitFormat);
+            return string.Join(',', splitFormat.Where(s => !string.IsNullOrEmpty(s)));
         }
         }
 
 
         private int? GetEstimatedAudioBitrate(string codec, int? channels)
         private int? GetEstimatedAudioBitrate(string codec, int? channels)