aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
diff options
context:
space:
mode:
authorMarc Brooks <IDisposable@gmail.com>2025-02-03 19:48:59 -0600
committerGitHub <noreply@github.com>2025-02-03 19:48:59 -0600
commite8cbcde02ebd930a5eeb6c95e0875a9e30acb3e8 (patch)
tree2ecd43f232012c8f037f4cd6fee4168e46d01aa3 /MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
parent6dc61a430ba3a8480399309f277e5debfd6403ba (diff)
parentd376b5fbc7cf3ae7440a606a9e885d70605956bd (diff)
Merge branch 'master' into sort-nfo-data
Diffstat (limited to 'MediaBrowser.Model/Dlna/ResolutionNormalizer.cs')
-rw-r--r--MediaBrowser.Model/Dlna/ResolutionNormalizer.cs69
1 files changed, 36 insertions, 33 deletions
diff --git a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
index 5d7daa81a..1a636b240 100644
--- a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
+++ b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
@@ -2,28 +2,33 @@
#pragma warning disable CS1591
using System;
+using System.Linq;
namespace MediaBrowser.Model.Dlna
{
public static class ResolutionNormalizer
{
- private static readonly ResolutionConfiguration[] Configurations =
- new[]
- {
- new ResolutionConfiguration(426, 320000),
- new ResolutionConfiguration(640, 400000),
- new ResolutionConfiguration(720, 950000),
- new ResolutionConfiguration(1280, 2500000),
- new ResolutionConfiguration(1920, 4000000),
- new ResolutionConfiguration(2560, 20000000),
- new ResolutionConfiguration(3840, 35000000)
- };
+ // Please note: all bitrate here are in the scale of SDR h264 bitrate at 30fps
+ private static readonly ResolutionConfiguration[] _configurations =
+ [
+ new ResolutionConfiguration(416, 365000),
+ new ResolutionConfiguration(640, 730000),
+ new ResolutionConfiguration(768, 1100000),
+ new ResolutionConfiguration(960, 3000000),
+ new ResolutionConfiguration(1280, 6000000),
+ new ResolutionConfiguration(1920, 13500000),
+ new ResolutionConfiguration(2560, 28000000),
+ new ResolutionConfiguration(3840, 50000000)
+ ];
public static ResolutionOptions Normalize(
int? inputBitrate,
int outputBitrate,
+ int h264EquivalentOutputBitrate,
int? maxWidth,
- int? maxHeight)
+ int? maxHeight,
+ float? targetFps,
+ bool isHdr = false) // We are not doing HDR transcoding for now, leave for future use
{
// If the bitrate isn't changing, then don't downscale the resolution
if (inputBitrate.HasValue && outputBitrate >= inputBitrate.Value)
@@ -38,16 +43,26 @@ namespace MediaBrowser.Model.Dlna
}
}
- var resolutionConfig = GetResolutionConfiguration(outputBitrate);
- if (resolutionConfig is not null)
+ var referenceBitrate = h264EquivalentOutputBitrate * (30.0f / (targetFps ?? 30.0f));
+
+ if (isHdr)
{
- var originvalValue = maxWidth;
+ referenceBitrate *= 0.8f;
+ }
- maxWidth = Math.Min(resolutionConfig.MaxWidth, maxWidth ?? resolutionConfig.MaxWidth);
- if (!originvalValue.HasValue || originvalValue.Value != maxWidth.Value)
- {
- maxHeight = null;
- }
+ var resolutionConfig = GetResolutionConfiguration(Convert.ToInt32(referenceBitrate));
+
+ if (resolutionConfig is null)
+ {
+ return new ResolutionOptions { MaxWidth = maxWidth, MaxHeight = maxHeight };
+ }
+
+ var originWidthValue = maxWidth;
+
+ maxWidth = Math.Min(resolutionConfig.MaxWidth, maxWidth ?? resolutionConfig.MaxWidth);
+ if (!originWidthValue.HasValue || originWidthValue.Value != maxWidth.Value)
+ {
+ maxHeight = null;
}
return new ResolutionOptions
@@ -59,19 +74,7 @@ namespace MediaBrowser.Model.Dlna
private static ResolutionConfiguration GetResolutionConfiguration(int outputBitrate)
{
- ResolutionConfiguration previousOption = null;
-
- foreach (var config in Configurations)
- {
- if (outputBitrate <= config.MaxBitrate)
- {
- return previousOption ?? config;
- }
-
- previousOption = config;
- }
-
- return null;
+ return _configurations.FirstOrDefault(config => outputBitrate <= config.MaxBitrate);
}
}
}