mirror of https://github.com/n00mkrad/flowframes
Print fractions (like FPS) in a better way, especially if denominator is 1
This commit is contained in:
parent
058820bc8e
commit
5da083bf2c
|
@ -46,7 +46,6 @@ namespace Flowframes.Data
|
|||
Numerator = (value * 10000f).RoundToInt();
|
||||
Denominator = 10000;
|
||||
this = GetReduced();
|
||||
Logger.Log($"Converted float {value} to Fraction {this}", true);
|
||||
}
|
||||
|
||||
public Fraction(string text)
|
||||
|
@ -71,7 +70,7 @@ namespace Flowframes.Data
|
|||
}
|
||||
}
|
||||
|
||||
Logger.Log($"Fraction from String: Fraction(\"{text}\") => {Numerator}/{Denominator}", true);
|
||||
Console.WriteLine($"Fraction from String: Fraction(\"{text}\") => {Numerator}/{Denominator}", true);
|
||||
}
|
||||
|
||||
private static long GetGreatestCommonDenominator(long a, long b)
|
||||
|
|
|
@ -287,7 +287,7 @@ namespace Flowframes.Forms.Main
|
|||
public void UpdateInputInfo()
|
||||
{
|
||||
string str = $"Size: {(!currInRes.IsEmpty ? $"{currInRes.Width}x{currInRes.Height}" : "Unknown")} - ";
|
||||
str += $"FPS: {(currInFpsDetected.GetFloat() > 0f ? $"{currInFpsDetected} ({currInFpsDetected.GetFloat().ToString("0.000")})" : "Unknown")} - ";
|
||||
str += $"FPS: {(currInFpsDetected.GetFloat() > 0f ? FormatUtils.Fraction(currInFpsDetected) : "Unknown")} - ";
|
||||
str += $"Frames: {(currInFrames > 0 ? $"{currInFrames}" : "Unknown")} - ";
|
||||
str += $"Duration: {(currInDuration > 0 ? FormatUtils.MsToTimestamp(currInDuration) : "Unknown")}";
|
||||
inputInfo.Text = str;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Flowframes.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
@ -101,7 +102,7 @@ namespace Flowframes.MiscUtils
|
|||
{
|
||||
ms = hours * 3600000 + minutes * 60000 + seconds * 1000;
|
||||
}
|
||||
|
||||
|
||||
return ms;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -144,7 +145,7 @@ namespace Flowframes.MiscUtils
|
|||
string outStr = "";
|
||||
|
||||
strings = strings.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
|
||||
if(distinct)
|
||||
if (distinct)
|
||||
strings = strings.Distinct().ToArray();
|
||||
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
|
@ -157,7 +158,7 @@ namespace Flowframes.MiscUtils
|
|||
return outStr;
|
||||
}
|
||||
|
||||
public static System.Drawing.Size ParseSize (string str)
|
||||
public static System.Drawing.Size ParseSize(string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -170,13 +171,13 @@ namespace Flowframes.MiscUtils
|
|||
}
|
||||
}
|
||||
|
||||
public static string BeautifyFfmpegStats (string line)
|
||||
public static string BeautifyFfmpegStats(string line)
|
||||
{
|
||||
line = line.Remove("q=-0.0").Remove("q=-1.0").Remove("size=N/A").Remove("bitrate=N/A").Replace("frame=", "Frame: ")
|
||||
.Replace("fps=", "FPS: ").Replace("q=", "QP: ").Replace("time=", "Time: ").Replace("speed=", "Relative Speed: ")
|
||||
.Replace("bitrate=", "Bitrate: ").Replace("Lsize=", "Size: ").Replace("size=", "Size: ").TrimWhitespaces();
|
||||
|
||||
if(!line.Contains("Bitrate: ") && line.Contains(" 0x"))
|
||||
if (!line.Contains("Bitrate: ") && line.Contains(" 0x"))
|
||||
line = line.Split(" QP: ").FirstOrDefault().Trim() + " (Analysing...)";
|
||||
|
||||
return line;
|
||||
|
@ -189,5 +190,19 @@ namespace Flowframes.MiscUtils
|
|||
else
|
||||
return codec.ToTitleCase();
|
||||
}
|
||||
|
||||
/// <summary> Show fraction in a nicely readable way, including a decimal approximation. Tilde symbol will be added before the approx number unless <paramref name="showTildeForApprox"/> is False. </summary>
|
||||
public static string Fraction(Fraction f, bool showTildeForApprox = true)
|
||||
{
|
||||
// No need to show "24/1" since we can just show "24"
|
||||
if (f.Denominator == 1)
|
||||
return f.Numerator.ToString();
|
||||
|
||||
// If number is actually fractional, show the fraction as well as the approx. decimal number
|
||||
string decimalStr = f.GetFloat().ToString("0.###");
|
||||
bool isPrecise = decimalStr == f.GetFloat().ToString("0.####"); // If 0.___ matches with 0.____ it means we have enough decimal places and thus it's precise
|
||||
string t = showTildeForApprox && !isPrecise ? "~" : "";
|
||||
return $"{f} ({t}{decimalStr})";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Flowframes.Data;
|
||||
using Flowframes.MiscUtils;
|
||||
|
||||
namespace Flowframes.Ui
|
||||
{
|
||||
|
@ -43,14 +44,10 @@ namespace Flowframes.Ui
|
|||
await Interpolate.currentMediaFile.Initialize();
|
||||
Program.mainForm.currInDuration = Interpolate.currentMediaFile.DurationMs;
|
||||
Program.mainForm.currInDurationCut = Program.mainForm.currInDuration;
|
||||
string fpsStr = "Not Found";
|
||||
Fraction fps = Interpolate.currentMediaFile.VideoStreams.Count > 0 ? Interpolate.currentMediaFile.VideoStreams[0].Rate : new Fraction();
|
||||
string fpsStr = fps.GetFloat() > 0 ? FormatUtils.Fraction(fps) : "Not Found";
|
||||
Program.mainForm.currInFpsDetected = fps;
|
||||
fpsInTbox.Text = fps.GetString();
|
||||
|
||||
if (fps.GetFloat() > 0)
|
||||
fpsStr = $"{fps} (~{fps.GetFloat()})";
|
||||
|
||||
Logger.Log($"Video FPS: {fpsStr} - Total Number Of Frames: {Interpolate.currentMediaFile.FrameCount}", false, true);
|
||||
Program.mainForm.GetInputFpsTextbox().ReadOnly = (fps.GetFloat() > 0 && !Config.GetBool("allowCustomInputRate", false));
|
||||
Program.mainForm.currInFps = fps;
|
||||
|
|
Loading…
Reference in New Issue