diff --git a/Code/Forms/BatchForm.cs b/Code/Forms/BatchForm.cs index 95e1c72..681f4ab 100644 --- a/Code/Forms/BatchForm.cs +++ b/Code/Forms/BatchForm.cs @@ -129,7 +129,7 @@ namespace Flowframes.Forms InterpSettings current = Program.mainForm.GetCurrentSettings(); current.UpdatePaths(path, path.GetParentDir()); - current.inFps = GetFramerate(path); + current.inFps = await GetFramerate(path); current.outFps = current.inFps * current.interpFactor; Program.batchQueue.Enqueue(current); RefreshGui(); @@ -137,10 +137,10 @@ namespace Flowframes.Forms } } - float GetFramerate (string path) + async Task GetFramerate (string path) { float fps = Interpolate.current.inFps; - float fpsFromFile = IOUtils.GetFpsFolderOrVideo(path); + float fpsFromFile = await IOUtils.GetFpsFolderOrVideo(path); if (fpsFromFile > 0) return fpsFromFile; diff --git a/Code/Forms/SettingsForm.Designer.cs b/Code/Forms/SettingsForm.Designer.cs index fb88dd7..608d300 100644 --- a/Code/Forms/SettingsForm.Designer.cs +++ b/Code/Forms/SettingsForm.Designer.cs @@ -1244,9 +1244,9 @@ this.label58.Location = new System.Drawing.Point(420, 301); this.label58.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label58.Name = "label58"; - this.label58.Size = new System.Drawing.Size(255, 13); + this.label58.Size = new System.Drawing.Size(221, 13); this.label58.TabIndex = 65; - this.label58.Text = "Lower is better. Use slightly higher values than h265!"; + this.label58.Text = "Lower is better. Use higher values than h265!"; // // vp9Crf // diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index db3bdfe..0a4295a 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -300,7 +300,7 @@ namespace Flowframes.IO } } - public static float GetVideoFramerate (string path) + public static async Task GetVideoFramerate (string path) { float fps = 0; try @@ -316,7 +316,7 @@ namespace Flowframes.IO Logger.Log("Failed to read FPS - Trying alternative method...", true); try { - fps = FfmpegCommands.GetFramerate(path); + fps = await FfmpegCommands.GetFramerate(path); Logger.Log("Detected FPS of " + Path.GetFileName(path) + " as " + fps + " FPS", true); } catch @@ -478,19 +478,21 @@ namespace Flowframes.IO return null; } - public static float GetFpsFolderOrVideo(string path) + public static async Task GetFpsFolderOrVideo(string path) { try { if (IsPathDirectory(path)) { float dirFps = GetVideoFramerateForDir(path); + if (dirFps > 0) return dirFps; } else { - float vidFps = GetVideoFramerate(path); + float vidFps = await GetVideoFramerate(path); + if (vidFps > 0) return vidFps; } @@ -499,6 +501,7 @@ namespace Flowframes.IO { Logger.Log("GetFpsFolderOrVideo() Error: " + e.Message); } + return 0; } diff --git a/Code/Media/FfmpegCommands.cs b/Code/Media/FfmpegCommands.cs index b75d296..48346ba 100644 --- a/Code/Media/FfmpegCommands.cs +++ b/Code/Media/FfmpegCommands.cs @@ -61,23 +61,32 @@ namespace Flowframes return FormatUtils.MsFromTimestamp(info); } - public static float GetFramerate(string inputFile) + public static async Task GetFramerate(string inputFile) { - Logger.Log("Reading FPS using ffmpeg.", true, false, "ffmpeg"); - string args = $" -i {inputFile.Wrap()}"; - string output = GetFfmpegOutput(args); - string[] entries = output.Split(','); - foreach (string entry in entries) + Logger.Log($"GetFramerate('{inputFile}')", true, false, "ffmpeg"); + + try { - if (entry.Contains(" fps") && !entry.Contains("Input ")) // Avoid reading FPS from the filename, in case filename contains "fps" + string args = $" -i {inputFile.Wrap()}"; + string output = await GetFfmpegOutputAsync(args); + string[] entries = output.Split(','); + + foreach (string entry in entries) { - Logger.Log("[FFCmds] FPS Entry: " + entry, true); - string num = entry.Replace(" fps", "").Trim().Replace(",", "."); - float value; - float.TryParse(num, NumberStyles.Any, CultureInfo.InvariantCulture, out value); - return value; + if (entry.Contains(" fps") && !entry.Contains("Input ")) // Avoid reading FPS from the filename, in case filename contains "fps" + { + string num = entry.Replace(" fps", "").Trim().Replace(",", "."); + float value; + float.TryParse(num, NumberStyles.Any, CultureInfo.InvariantCulture, out value); + return value; + } } } + catch(Exception e) + { + Logger.Log("GetFramerate Error: " + e.Message, true, false); + } + return 0f; } diff --git a/Code/UI/MainUiFunctions.cs b/Code/UI/MainUiFunctions.cs index 76dfc64..427e630 100644 --- a/Code/UI/MainUiFunctions.cs +++ b/Code/UI/MainUiFunctions.cs @@ -37,7 +37,7 @@ namespace Flowframes.UI int frameCount = await InterpolateUtils.GetInputFrameCountAsync(path); string fpsStr = "Not Found"; - float fps = IOUtils.GetFpsFolderOrVideo(path); + float fps = await IOUtils.GetFpsFolderOrVideo(path); fpsInTbox.Text = fps.ToString(); if (fps > 0)