From 2841eba20211c36c17d602e4cc2392bdcf0e33ad Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 24 Dec 2015 15:06:52 -0500 Subject: [PATCH] fixes #1310 - Downscaling 1280x720 to 720x404 --- .../Playback/BaseStreamingService.cs | 5 +++- .../Encoder/EncodingJobFactory.cs | 5 +++- .../Dlna/ResolutionNormalizer.cs | 23 +++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 7939a5976..9eb0f7d45 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1623,7 +1623,10 @@ namespace MediaBrowser.Api.Playback if (state.OutputVideoBitrate.HasValue) { - var resolution = ResolutionNormalizer.Normalize(state.OutputVideoBitrate.Value, + var resolution = ResolutionNormalizer.Normalize( + state.VideoStream == null ? (int?)null : state.VideoStream.BitRate, + state.OutputVideoBitrate.Value, + state.VideoStream == null ? null : state.VideoStream.Codec, state.OutputVideoCodec, videoRequest.MaxWidth, videoRequest.MaxHeight); diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index cf776b3f7..9cdc4a7bf 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -82,7 +82,10 @@ namespace MediaBrowser.MediaEncoding.Encoder if (state.OutputVideoBitrate.HasValue) { - var resolution = ResolutionNormalizer.Normalize(state.OutputVideoBitrate.Value, + var resolution = ResolutionNormalizer.Normalize( + state.VideoStream == null ? (int?)null : state.VideoStream.BitRate, + state.OutputVideoBitrate.Value, + state.VideoStream == null ? null : state.VideoStream.Codec, state.OutputVideoCodec, request.MaxWidth, request.MaxHeight); diff --git a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs index b23c0b20b..8a412ac2c 100644 --- a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs +++ b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs @@ -14,14 +14,29 @@ namespace MediaBrowser.Model.Dlna new ResolutionConfiguration(1280, 2500000) }; - public static ResolutionOptions Normalize(int maxBitrate, - string codec, + public static ResolutionOptions Normalize(int? inputBitrate, + int outputBitrate, + string inputCodec, + string outputCodec, int? maxWidth, int? maxHeight) { - foreach (var config in Configurations) + // If the bitrate isn't changing, then don't downlscale the resolution + if (inputBitrate.HasValue && outputBitrate >= inputBitrate.Value) + { + if (maxWidth.HasValue || maxHeight.HasValue) + { + return new ResolutionOptions + { + MaxWidth = maxWidth, + MaxHeight = maxHeight + }; + } + } + + foreach (var config in Configurations) { - if (maxBitrate <= config.MaxBitrate) + if (outputBitrate <= config.MaxBitrate) { var originvalValue = maxWidth;