diff options
author | sr55 <[email protected]> | 2011-01-07 21:19:49 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-01-07 21:19:49 +0000 |
commit | 9f60eb35c21d513c6ce6b272e371a279b8a32ae5 (patch) | |
tree | 8663ceb2de2b74c05bc639fdcdd720034005a1af /win/C#/HandBrake.ApplicationServices/Functions | |
parent | ee94883ba1b2e3d0dc432c84a2c05db5812fe1c6 (diff) |
WinGui:
- First of many check-ins to refactor the ApplicationServices library to make it more friendly and reliable.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3737 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/HandBrake.ApplicationServices/Functions')
-rw-r--r-- | win/C#/HandBrake.ApplicationServices/Functions/Converters.cs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/Functions/Converters.cs b/win/C#/HandBrake.ApplicationServices/Functions/Converters.cs new file mode 100644 index 000000000..c4ba59f14 --- /dev/null +++ b/win/C#/HandBrake.ApplicationServices/Functions/Converters.cs @@ -0,0 +1,70 @@ +namespace HandBrake.ApplicationServices.Functions
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Text.RegularExpressions;
+
+ /// <summary>
+ /// A class to convert various things to native C# objects
+ /// </summary>
+ public class Converters
+ {
+ /// <summary>
+ /// Convert HandBrakes time remaining into a TimeSpan
+ /// </summary>
+ /// <param name="time">
+ /// The time remaining for the encode.
+ /// </param>
+ /// <returns>
+ /// A TimepSpan object
+ /// </returns>
+ public static TimeSpan EncodeToTimespan(string time)
+ {
+ TimeSpan converted = new TimeSpan(0, 0, 0, 0);
+
+ Match m = Regex.Match(time.Trim(), @"^([0-9]{2}:[0-9]{2}:[0-9]{2})");
+ if (m.Success)
+ {
+ TimeSpan.TryParse(m.Groups[0].Value, out converted);
+ }
+
+ return converted;
+ }
+
+ /// <summary>
+ /// Video Framerate Converter
+ /// </summary>
+ private static readonly Dictionary<double, int> vrates = new Dictionary<double, int>
+ {
+ {5, 5400000},
+ {10, 2700000},
+ {12, 2250000},
+ {15, 1800000},
+ {23.976, 1126125},
+ {24, 1125000},
+ {25, 1080000},
+ {29.97, 900900}
+ };
+
+ /// <summary>
+ /// Convert the desired framerate to the video rate.
+ /// </summary>
+ /// <param name="framerate">
+ /// The framerate.
+ /// </param>
+ /// <returns>
+ /// The Video Rate.
+ /// </returns>
+ /// <exception cref="ArgumentException">
+ /// </exception>
+ public static int FramerateToVrate(double framerate)
+ {
+ if (!vrates.ContainsKey(framerate))
+ {
+ throw new ArgumentException("Framerate not recognized.", "framerate");
+ }
+
+ return vrates[framerate];
+ }
+ }
+}
|