aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-11-06 10:45:25 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-11-06 10:45:25 -0500
commitec3caf5865d073f4eaba5642c761e237de456710 (patch)
treec005ee90e04c645d153661bf01456ea63db81c0a
parent33c0b0e99c3df88906aac2f9fc2b363105bff0b1 (diff)
adjusted aspect ratio normalization
-rw-r--r--MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs43
1 files changed, 29 insertions, 14 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs
index 323fa20e6..f65bf9ea3 100644
--- a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs
+++ b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs
@@ -251,17 +251,33 @@ namespace MediaBrowser.Providers.MediaInfo
private string GetAspectRatio(MediaStreamInfo info)
{
- if (info.height > 0 && info.width > 0)
+ var original = info.display_aspect_ratio;
+
+ int height;
+ int width;
+
+ var parts = (original ?? string.Empty).Split(':');
+ if (!(parts.Length == 2 &&
+ int.TryParse(parts[0], NumberStyles.Any, UsCulture, out width) &&
+ int.TryParse(parts[1], NumberStyles.Any, UsCulture, out height) &&
+ width > 0 &&
+ height > 0))
+ {
+ width = info.width;
+ height = info.height;
+ }
+
+ if (width > 0 && height > 0)
{
- double ratio = info.width;
- ratio /= info.height;
+ double ratio = width;
+ ratio /= height;
- if (IsClose(ratio, 1.777777778))
+ if (IsClose(ratio, 1.777777778, .03))
{
return "16:9";
}
- if (IsClose(ratio, 1.3333333333))
+ if (IsClose(ratio, 1.3333333333, .05))
{
return "4:3";
}
@@ -286,31 +302,30 @@ namespace MediaBrowser.Providers.MediaInfo
return "5:3";
}
- if (IsClose(ratio, 1.85))
+ if (IsClose(ratio, 1.85, .02))
{
return "1.85:1";
}
- if (IsClose(ratio, 2.39))
+ if (IsClose(ratio, 2.35, .025))
{
- return "2.39:1";
+ return "2.35:1";
}
- if (IsClose(ratio, 2.4))
+ if (IsClose(ratio, 2.4, .025))
{
- return "2.4:1";
+ return "2.40:1";
}
}
- return info.display_aspect_ratio;
+ return original;
}
- private bool IsClose(double d1, double d2)
+ private bool IsClose(double d1, double d2, double variance = .005)
{
- return Math.Abs(d1 - d2) <= .005;
+ return Math.Abs(d1 - d2) <= variance;
}
-
/// <summary>
/// Gets a frame rate from a string value in ffprobe output
/// This could be a number or in the format of 2997/125.