diff options
| author | LogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com> | 2019-08-06 00:26:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-06 00:26:19 -0700 |
| commit | 984e415c66cbd995d12ea95a3a9d3e2561ce4869 (patch) | |
| tree | 1799942f3836641786c0e29249801bdb46aac0f4 /MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | |
| parent | c2667f99f4d50f4f7d9bbeec50e8491e52468962 (diff) | |
| parent | 89f592687ee7ae7f0e0fffd884dbf2890476410a (diff) | |
Merge pull request #5 from jellyfin/master
Merge up to latest master
Diffstat (limited to 'MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs')
| -rw-r--r-- | MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index e378c2b89..b9ccc93ef 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -573,7 +573,9 @@ namespace MediaBrowser.Controller.MediaEncoding } // TODO: Perhaps also use original_size=1920x800 ?? - return string.Format("subtitles=filename='{0}'{1}{2}{3}", + return string.Format( + CultureInfo.InvariantCulture, + "subtitles=filename='{0}'{1}{2}", _mediaEncoder.EscapeSubtitleFilterPath(subtitlePath), charsetParam, // fallbackFontParam, @@ -582,7 +584,9 @@ namespace MediaBrowser.Controller.MediaEncoding var mediaPath = state.MediaPath ?? string.Empty; - return string.Format("subtitles='{0}:si={1}'{2}", + return string.Format( + CultureInfo.InvariantCulture, + "subtitles='{0}:si={1}'{2}", _mediaEncoder.EscapeSubtitleFilterPath(mediaPath), state.InternalSubtitleStreamOffset.ToString(_usCulture), // fallbackFontParam, @@ -1083,27 +1087,51 @@ 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) + { + // these values were chosen from testing to improve low bitrate streams + 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; } |
