mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* fix cropping jellyfin and emby content that is too small * fix transcoding tests with nvidia * update dependenciespull/2484/head
11 changed files with 111 additions and 35 deletions
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
using System.Globalization; |
||||
|
||||
namespace ErsatzTV.FFmpeg; |
||||
|
||||
public static class AspectRatio |
||||
{ |
||||
public static string CalculateSAR(int width, int height, string displayAspectRatio) |
||||
{ |
||||
// first check for decimal DAR
|
||||
if (!double.TryParse(displayAspectRatio, out double dar)) |
||||
{ |
||||
// if not, assume it's a ratio
|
||||
string[] split = displayAspectRatio.Split(':'); |
||||
var num = double.Parse(split[0], CultureInfo.InvariantCulture); |
||||
var den = double.Parse(split[1], CultureInfo.InvariantCulture); |
||||
dar = num / den; |
||||
} |
||||
|
||||
double res = width / (double)height; |
||||
var formattedDar = string.Format( |
||||
CultureInfo.InvariantCulture, |
||||
dar % 1 == 0 ? "{0:F0}" : "{0:0.############}", |
||||
dar); |
||||
var formattedRes = string.Format( |
||||
CultureInfo.InvariantCulture, |
||||
res % 1 == 0 ? "{0:F0}" : "{0:0.############}", |
||||
res); |
||||
return $"{formattedDar}:{formattedRes}"; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue