diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index 11939da..6d29303 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -558,23 +558,29 @@ namespace Flowframes.IO } try { + var stream = File.OpenRead(path); + if (hashType == Hash.MD5) { MD5 md5 = MD5.Create(); - var hash = md5.ComputeHash(File.OpenRead(path)); + var hash = md5.ComputeHash(stream); hashStr = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } + if (hashType == Hash.CRC32) { var crc = new Crc32Algorithm(); - var crc32bytes = crc.ComputeHash(File.OpenRead(path)); + var crc32bytes = crc.ComputeHash(stream); hashStr = BitConverter.ToUInt32(crc32bytes, 0).ToString(); } + if (hashType == Hash.xxHash) { - ulong xxh64 = xxHash64.ComputeHash(File.OpenRead(path), 8192, (ulong)GetFilesize(path)); + ulong xxh64 = xxHash64.ComputeHash(stream, 8192, (ulong)GetFilesize(path)); hashStr = xxh64.ToString(); } + + stream.Close(); } catch (Exception e) { diff --git a/Code/IO/ModelDownloader.cs b/Code/IO/ModelDownloader.cs index 75fcb6a..31ad786 100644 --- a/Code/IO/ModelDownloader.cs +++ b/Code/IO/ModelDownloader.cs @@ -41,6 +41,7 @@ namespace Flowframes.IO static async Task DownloadTo (string url, string saveDir, int retries = 3) { string savePath = Path.Combine(saveDir, Path.GetFileName(url)); + IOUtils.TryDeleteIfExists(savePath); Logger.Log($"Downloading '{url}' to '{savePath}'", true); Stopwatch sw = new Stopwatch(); sw.Restart(); @@ -68,6 +69,7 @@ namespace Flowframes.IO if (Interpolate.canceled) { client.CancelAsync(); + client.Dispose(); return; } if (sw.ElapsedMilliseconds > 6000) @@ -106,7 +108,7 @@ namespace Flowframes.IO foreach (KeyValuePair modelFile in fileList) await DownloadTo(GetMdlFileUrl(ai, model, modelFile.Key), mdlDir); - + Logger.Log($"Downloaded \"{model}\" model files.", false, true); } catch (Exception e) @@ -174,7 +176,7 @@ namespace Flowframes.IO string md5 = IOUtils.GetHash(Path.Combine(mdlDir, file.Key), IOUtils.Hash.MD5); if (md5.Trim() != file.Value.Trim()) { - Logger.Log($"Files for model {model} not valid: Local MD5 ({md5.Trim()}) does not equal validation MD5 ({file.Value.Trim()}).", true); + Logger.Log($"Files for model {model} not valid: MD5 of {file.Key} ({md5.Trim()}) does not equal validation MD5 ({file.Value.Trim()}).", true); return false; } } diff --git a/Code/Main/AutoEncode.cs b/Code/Main/AutoEncode.cs index 9ddbda3..b42e5d4 100644 --- a/Code/Main/AutoEncode.cs +++ b/Code/Main/AutoEncode.cs @@ -27,7 +27,8 @@ namespace Flowframes.Main public static void UpdateChunkAndBufferSizes () { chunkSize = GetChunkSize(IOUtils.GetAmountOfFiles(Interpolate.current.framesFolder, false, "*.png") * Interpolate.current.interpFactor); - safetyBufferFrames = Interpolate.current.ai.aiName.ToUpper().Contains("NCNN") ? 60 : 30; // Use bigger safety buffer for NCNN + bool isNcnn = Interpolate.current.ai.aiName.ToUpper().Contains("NCNN"); + safetyBufferFrames = isNcnn ? Config.GetInt("autoEncSafeBufferNcnn", 90) : Config.GetInt("autoEncSafeBufferCuda", 30); // Use bigger safety buffer for NCNN } public static async Task MainLoop(string interpFramesPath) diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index 6513a58..75b0010 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -43,17 +43,14 @@ namespace Flowframes currentInputFrameCount = await Utils.GetInputFrameCountAsync(current.inPath); Program.mainForm.SetStatus("Starting..."); Program.mainForm.SetWorking(true); - await Task.Delay(10); if (!current.inputIsFrames) // Input is video - extract frames first await ExtractFrames(current.inPath, current.framesFolder); else await FFmpegCommands.ImportImages(current.inPath, current.framesFolder, await Utils.GetOutputResolution(current.inPath, true)); if (canceled) return; sw.Restart(); - await Task.Delay(10); await PostProcessFrames(); if (canceled) return; - Program.mainForm.SetStatus("Running AI..."); await RunAi(current.interpFolder, current.ai); if (canceled) return; Program.mainForm.SetProgress(100); @@ -135,6 +132,7 @@ namespace Flowframes public static async Task RunAi(string outpath, AI ai, bool stepByStep = false) { + Program.mainForm.SetStatus("Downloading models..."); await ModelDownloader.DownloadModelFiles(Path.GetFileNameWithoutExtension(ai.pkg.fileName), current.model); if (canceled) return; @@ -156,6 +154,7 @@ namespace Flowframes tasks.Add(AutoEncode.MainLoop(outpath)); } + Program.mainForm.SetStatus("Running AI..."); await Task.WhenAll(tasks); } diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index 463b0f2..866c791 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -354,7 +354,7 @@ namespace Flowframes.Main } } - public static int RoundDiv2(int n) // Round to a number that's divisible by 2 (for h264) + public static int RoundDiv2(int n) // Round to a number that's divisible by 2 (for h264 etc) { int a = (n / 2) * 2; // Smaller multiple int b = a + 2; // Larger multiple