diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index f4684a2218..a4714e7bf8 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -71,6 +71,21 @@ namespace MediaBrowser.Controller.MediaEncoding "m4v", }; + // Set max transcoding channels for encoders that can't handle more than a set amount of channels + // AAC, FLAC, ALAC, libopus, libvorbis encoders all support at least 8 channels + private static readonly Dictionary _audioTranscodeChannelLookup = new(StringComparer.OrdinalIgnoreCase) + { + { "wmav2", 2 }, + { "libmp3lame", 2 }, + { "libfdk_aac", 6 }, + { "aac_at", 6 }, + { "ac3", 6 }, + { "eac3", 6 }, + { "dts", 6 }, + { "mlp", 6 }, + { "truehd", 6 }, + }; + public EncodingHelper( IApplicationPaths appPaths, IMediaEncoder mediaEncoder, @@ -2231,25 +2246,14 @@ namespace MediaBrowser.Controller.MediaEncoding if (isTranscodingAudio) { - // Set max transcoding channels for encoders that can't handle more than a set amount of channels - // AAC, FLAC, ALAC, libopus, libvorbis encoders all support at least 8 channels - int transcoderChannelLimit = GetAudioEncoder(state) switch - { - string audioEncoder when audioEncoder.Equals("wmav2", StringComparison.OrdinalIgnoreCase) - || audioEncoder.Equals("libmp3lame", StringComparison.OrdinalIgnoreCase) => 2, - string audioEncoder when audioEncoder.Equals("libfdk_aac", StringComparison.OrdinalIgnoreCase) - || audioEncoder.Equals("aac_at", StringComparison.OrdinalIgnoreCase) - || audioEncoder.Equals("ac3", StringComparison.OrdinalIgnoreCase) - || audioEncoder.Equals("eac3", StringComparison.OrdinalIgnoreCase) - || audioEncoder.Equals("dts", StringComparison.OrdinalIgnoreCase) - || audioEncoder.Equals("mlp", StringComparison.OrdinalIgnoreCase) - || audioEncoder.Equals("truehd", StringComparison.OrdinalIgnoreCase) => 6, - // Set default max transcoding channels to 8 to prevent encoding errors due to asking for too many channels - _ => 8, - }; + var audioEncoder = GetAudioEncoder(state); + if (!_audioTranscodeChannelLookup.TryGetValue(audioEncoder, out var transcoderChannelLimit)) + { + // Set default max transcoding channels to 8 to prevent encoding errors due to asking for too many channels. + transcoderChannelLimit = 8; + } // Set resultChannels to minimum between resultChannels, TranscodingMaxAudioChannels, transcoderChannelLimit - resultChannels = transcoderChannelLimit < resultChannels ? transcoderChannelLimit : resultChannels ?? transcoderChannelLimit; if (request.TranscodingMaxAudioChannels < resultChannels)