aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
diff options
context:
space:
mode:
authorJMCC <JMCC@localhost>2019-05-11 17:19:20 +0200
committerJMCC <JMCC@localhost>2019-05-11 17:19:20 +0200
commit012e4a3e63f8b0997d5f070b37ac93d257f894e7 (patch)
tree05c448fcf0bb9d68b9327006c0f78bae35a3cfa8 /MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
parent5d85076ad5152b60ca2101177330b24944a65411 (diff)
Fix transcode bitrate control
Diffstat (limited to 'MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs')
-rw-r--r--MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs49
1 files changed, 36 insertions, 13 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
index e378c2b89..849cf7083 100644
--- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
+++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
@@ -1083,27 +1083,50 @@ namespace MediaBrowser.Controller.MediaEncoding
{
var bitrate = request.VideoBitRate;
- // If specific values were requested, then force the caller to supply a bitrate as well
- if (request.Height.HasValue && request.Width.HasValue)
- {
- return bitrate;
- }
-
if (videoStream != null)
{
- if (bitrate.HasValue)
- {
- var inputVideoCodec = videoStream.Codec;
- bitrate = ScaleBitrate(bitrate.Value, inputVideoCodec, outputVideoCodec);
+ var isUpscaling = request.Height.HasValue && videoStream.Height.HasValue &&
+ request.Height.Value > videoStream.Height.Value && request.Width.HasValue && videoStream.Width.HasValue &&
+ request.Width.Value > videoStream.Width.Value;
- // If a max bitrate was requested, don't let the scaled bitrate exceed it
- if (request.VideoBitRate.HasValue)
+ // Don't allow bitrate increases unless upscaling
+ if (!isUpscaling)
+ {
+ if (bitrate.HasValue && videoStream.BitRate.HasValue)
{
- bitrate = Math.Min(bitrate.Value, request.VideoBitRate.Value);
+ bitrate = GetMinBitrate(videoStream.BitRate.Value, bitrate.Value);
}
}
}
+ if (bitrate.HasValue)
+ {
+ var inputVideoCodec = videoStream.Codec;
+ bitrate = ScaleBitrate(bitrate.Value, inputVideoCodec, outputVideoCodec);
+
+ // If a max bitrate was requested, don't let the scaled bitrate exceed it
+ if (request.VideoBitRate.HasValue)
+ {
+ bitrate = Math.Min(bitrate.Value, request.VideoBitRate.Value);
+ }
+ }
+
+ return bitrate;
+ }
+
+ private int GetMinBitrate(int sourceBitrate, int requestedBitrate)
+ {
+ if (sourceBitrate <= 2000000)
+ {
+ sourceBitrate = Convert.ToInt32(sourceBitrate * 2.5);
+ }
+ else if (sourceBitrate <= 3000000)
+ {
+ sourceBitrate = Convert.ToInt32(sourceBitrate * 2);
+ }
+
+ var bitrate = Math.Min(sourceBitrate, requestedBitrate);
+
return bitrate;
}