Files
Chronos/src/Titano.Core/Video/Rational.cs
T
Claude 83a54fb57b chore: bootstrap repository foundation
Solution layout, build rules with zero-package guard, in-house test
framework, localization runtime, brand mark rasteriser with ICO/PNG
generation, Core contracts (imaging, video, domain model, TIFF reader),
Titano.Tools (make-icon, i18n, xaml-lint, package-guard) and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 08:59:40 +00:00

30 lines
1.2 KiB
C#

using System.Globalization;
namespace Titano.Core.Video;
/// <summary>An exact frame rate such as 24000/1001.</summary>
public readonly record struct Rational(int Numerator, int Denominator)
{
public double Value => (double)Numerator / Denominator;
public static Rational Fps23976 { get; } = new(24000, 1001);
public static Rational Fps2997 { get; } = new(30000, 1001);
public static Rational Fps5994 { get; } = new(60000, 1001);
public static Rational FromFps(double fps)
{
if (Math.Abs(fps - 23.976) < 0.01) return Fps23976;
if (Math.Abs(fps - 29.97) < 0.01) return Fps2997;
if (Math.Abs(fps - 59.94) < 0.01) return Fps5994;
if (Math.Abs(fps - Math.Round(fps)) < 1e-6) return new((int)Math.Round(fps), 1);
return new((int)Math.Round(fps * 1000), 1000);
}
/// <summary>Duration of one frame in 90 kHz ticks (MP4 timescale used by Titano).</summary>
public long FrameTicks90k => (long)Math.Round(90000.0 * Denominator / Numerator);
public override string ToString() => Denominator == 1
? Numerator.ToString(CultureInfo.InvariantCulture)
: Value.ToString("0.###", CultureInfo.InvariantCulture);
}