aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-11-05 12:30:58 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-11-05 12:30:58 -0500
commit3b63b7fa6101724fad9f1cba859667ce99313bc1 (patch)
tree967dee14d147a1e4d29369fff8688474f86330bb
parentc41e50b4959bfd5860771dc236c62d07d1bc6064 (diff)
fixes #613 - Translate aspect ratios
-rw-r--r--MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs64
1 files changed, 63 insertions, 1 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs
index 17cb9f971..323fa20e6 100644
--- a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs
+++ b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs
@@ -212,7 +212,7 @@ namespace MediaBrowser.Providers.MediaInfo
stream.Width = streamInfo.width;
stream.Height = streamInfo.height;
- stream.AspectRatio = streamInfo.display_aspect_ratio;
+ stream.AspectRatio = GetAspectRatio(streamInfo);
stream.AverageFrameRate = GetFrameRate(streamInfo.avg_frame_rate);
stream.RealFrameRate = GetFrameRate(streamInfo.r_frame_rate);
@@ -249,6 +249,68 @@ namespace MediaBrowser.Providers.MediaInfo
return stream;
}
+ private string GetAspectRatio(MediaStreamInfo info)
+ {
+ if (info.height > 0 && info.width > 0)
+ {
+ double ratio = info.width;
+ ratio /= info.height;
+
+ if (IsClose(ratio, 1.777777778))
+ {
+ return "16:9";
+ }
+
+ if (IsClose(ratio, 1.3333333333))
+ {
+ return "4:3";
+ }
+
+ if (IsClose(ratio, 1.41))
+ {
+ return "1.41:1";
+ }
+
+ if (IsClose(ratio, 1.5))
+ {
+ return "1.5:1";
+ }
+
+ if (IsClose(ratio, 1.6))
+ {
+ return "1.6:1";
+ }
+
+ if (IsClose(ratio, 1.66666666667))
+ {
+ return "5:3";
+ }
+
+ if (IsClose(ratio, 1.85))
+ {
+ return "1.85:1";
+ }
+
+ if (IsClose(ratio, 2.39))
+ {
+ return "2.39:1";
+ }
+
+ if (IsClose(ratio, 2.4))
+ {
+ return "2.4:1";
+ }
+ }
+
+ return info.display_aspect_ratio;
+ }
+
+ private bool IsClose(double d1, double d2)
+ {
+ return Math.Abs(d1 - d2) <= .005;
+ }
+
+
/// <summary>
/// Gets a frame rate from a string value in ffprobe output
/// This could be a number or in the format of 2997/125.