diff options
| author | Dmitry Lyzo <ashephard0@gmail.com> | 2023-12-25 20:52:39 +0300 |
|---|---|---|
| committer | Dmitry Lyzo <ashephard0@gmail.com> | 2024-01-09 10:39:31 +0300 |
| commit | 39088b5ad29cf098729c31f0be90a387df5debf6 (patch) | |
| tree | e8a1b7b1594a5d1939f86b1ce9f8ca41c48db864 /MediaBrowser.MediaEncoding/Probing | |
| parent | 2f1b7d0988520d9341692f235b8adf1e4e10ebd7 (diff) | |
fix: discard webm if there is an unsupported codec
Diffstat (limited to 'MediaBrowser.MediaEncoding/Probing')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 629c30060..1ec0622f8 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -30,6 +30,8 @@ namespace MediaBrowser.MediaEncoding.Probing private const string ArtistReplaceValue = " | "; private readonly char[] _nameDelimiters = { '/', '|', ';', '\\' }; + private readonly string[] _webmVideoCodecs = { "vp8", "vp9" }; + private readonly string[] _webmAudioCodecs = { "opus", "vorbis" }; private readonly ILogger _logger; private readonly ILocalizationManager _localization; @@ -114,7 +116,7 @@ namespace MediaBrowser.MediaEncoding.Probing 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)) { @@ -260,7 +262,7 @@ namespace MediaBrowser.MediaEncoding.Probing return info; } - private string NormalizeFormat(string format) + private string NormalizeFormat(string format, IReadOnlyList<MediaStream> mediaStreams) { if (string.IsNullOrWhiteSpace(format)) { @@ -288,9 +290,20 @@ namespace MediaBrowser.MediaEncoding.Probing { 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) |
