Fixed GetHash file lock, AE safety buffers in config, increased to 90 for ncnn

This commit is contained in:
N00MKRAD
2021-01-17 20:05:39 +01:00
parent 9e52c25b2b
commit f13dffbeb8
5 changed files with 18 additions and 10 deletions

View File

@@ -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)
{

View File

@@ -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<string, string> 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;
}
}

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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