The Free Software Media System - Server Backend & API
update video audio encoding
Luke Pulverentia5ffea5752a6
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.csindex 5e450567a7..252eadbe8d 100644--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs@@ -870,33 +870,47 @@ namespace MediaBrowser.Api.PlaybackinputChannels = null;}- int? resultChannels = null;+ int? transcoderChannelLimit = null;var codec = outputAudioCodec ?? string.Empty;if (codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1){// wmav2 currently only supports two channel output- resultChannels = Math.Min(2, inputChannels ?? 2);+ transcoderChannelLimit = 2;}- else if (request.MaxAudioChannels.HasValue)+ else if (codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1)+ {+ // libmp3lame currently only supports two channel output+ transcoderChannelLimit = 2;+ }+ else{- var channelLimit = codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1- ? 2- : 6;+ // If we don't have any media info then limit it to 6 to prevent encoding errors due to asking for too many channels+ transcoderChannelLimit = 6;+ }- if (inputChannels.HasValue)- {- channelLimit = Math.Min(channelLimit, inputChannels.Value);- }+ var isTranscodingAudio = !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase);++ int? resultChannels = null;+ if (isTranscodingAudio)+ {+ resultChannels = request.TranscodingMaxAudioChannels;+ }+ resultChannels = resultChannels ?? request.MaxAudioChannels ?? request.AudioChannels;- // If we don't have any media info then limit it to 5 to prevent encoding errors due to asking for too many channels- resultChannels = Math.Min(request.MaxAudioChannels.Value, channelLimit);+ if (inputChannels.HasValue)+ {+ resultChannels = resultChannels.HasValue+ ? Math.Min(resultChannels.Value, inputChannels.Value)+ : inputChannels.Value;}- if (request.TranscodingMaxAudioChannels.HasValue && !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))+ if (isTranscodingAudio && transcoderChannelLimit.HasValue){- resultChannels = Math.Min(request.TranscodingMaxAudioChannels.Value, resultChannels ?? inputChannels ?? request.TranscodingMaxAudioChannels.Value);+ resultChannels = resultChannels.HasValue+ ? Math.Min(resultChannels.Value, transcoderChannelLimit.Value)+ : transcoderChannelLimit.Value;}return resultChannels ?? request.AudioChannels;diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.csindex 844fafcdec..d5fe790b9f 100644--- a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs+++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs@@ -35,6 +35,7 @@ namespace MediaBrowser.Controller.MediaEncodingpublic string VideoCodec { get; set; }+ public int? TranscodingMaxAudioChannels { get; set; }public int? VideoBitRate { get; set; }public int? AudioStreamIndex { get; set; }public int? VideoStreamIndex { get; set; }@@ -86,6 +87,7 @@ namespace MediaBrowser.Controller.MediaEncodingMaxVideoBitDepth = info.MaxVideoBitDepth;SubtitleMethod = info.SubtitleDeliveryMethod;Context = info.Context;+ TranscodingMaxAudioChannels = info.TranscodingMaxAudioChannels;if (info.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External){diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.csindex e197bdb6fd..d6340d4abf 100644--- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs+++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs@@ -370,30 +370,50 @@ namespace MediaBrowser.MediaEncoding.EncoderinputChannels = null;}+ int? transcoderChannelLimit = null;var codec = outputAudioCodec ?? string.Empty;if (codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1){// wmav2 currently only supports two channel output- return Math.Min(2, inputChannels ?? 2);+ transcoderChannelLimit = 2;}- if (request.MaxAudioChannels.HasValue)+ else if (codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1){- var channelLimit = codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1- ? 2- : 6;+ // libmp3lame currently only supports two channel output+ transcoderChannelLimit = 2;+ }+ else+ {+ // If we don't have any media info then limit it to 6 to prevent encoding errors due to asking for too many channels+ transcoderChannelLimit = 6;+ }- if (inputChannels.HasValue)- {- channelLimit = Math.Min(channelLimit, inputChannels.Value);- }+ var isTranscodingAudio = !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase);- // If we don't have any media info then limit it to 5 to prevent encoding errors due to asking for too many channels- return Math.Min(request.MaxAudioChannels.Value, channelLimit);+ int? resultChannels = null;+ if (isTranscodingAudio)+ {+ resultChannels = request.TranscodingMaxAudioChannels;+ }+ resultChannels = resultChannels ?? request.MaxAudioChannels ?? request.AudioChannels;++ if (inputChannels.HasValue)+ {+ resultChannels = resultChannels.HasValue+ ? Math.Min(resultChannels.Value, inputChannels.Value)+ : inputChannels.Value;+ }++ if (isTranscodingAudio && transcoderChannelLimit.HasValue)+ {+ resultChannels = resultChannels.HasValue+ ? Math.Min(resultChannels.Value, transcoderChannelLimit.Value)+ : transcoderChannelLimit.Value;}- return request.AudioChannels;+ return resultChannels ?? request.AudioChannels;}private int? GetVideoBitrateParamValue(EncodingJobOptions request, MediaStream videoStream, string outputVideoCodec)