Port to .NET 5

This commit is contained in:
Dankrushen
2021-01-26 02:37:16 -05:00
parent 0a236361e0
commit 72dcf90b68
95 changed files with 24769 additions and 1 deletions

30
Code5/Data/AI.cs Normal file
View File

@@ -0,0 +1,30 @@
using Flowframes.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
public struct AI
{
public string aiName;
public string aiNameShort;
public string friendlyName;
public string description;
public FlowPackage pkg;
public bool supportsAnyExp;
public AI(string aiNameArg, string friendlyNameArg, string descArg, FlowPackage pkgArg, bool supportsAnyExpArg)
{
aiName = aiNameArg;
aiNameShort = aiNameArg.Split(' ')[0];
aiNameShort = aiNameArg.Split('_')[0];
friendlyName = friendlyNameArg;
description = descArg;
pkg = pkgArg;
supportsAnyExp = supportsAnyExpArg;
}
}
}

24
Code5/Data/FlowPackage.cs Normal file
View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.IO
{
public struct FlowPackage
{
public string friendlyName;
public string fileName;
public int downloadSizeMb;
public string desc;
public FlowPackage(string friendlyNameStr, string fileNameStr, int downloadSizeMbInt, string description)
{
friendlyName = friendlyNameStr;
fileName = fileNameStr;
downloadSizeMb = downloadSizeMbInt;
desc = description;
}
}
}

10
Code5/Data/Formats.cs Normal file
View File

@@ -0,0 +1,10 @@

namespace Flowframes.IO
{
class Formats
{
public static string[] supported = { ".mp4", ".m4v", ".gif", ".mkv", ".mpg", ".webm", ".avi", ".wmv", ".ts", ".bik" }; // Supported formats
public static string[] noEncodeSupport = { ".bik" }; // Files that have no encode support, but decode
}
}

View File

@@ -0,0 +1,114 @@
using Flowframes.AudioVideo;
using Flowframes.Data;
using Flowframes.IO;
using Flowframes.Main;
using Flowframes.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
namespace Flowframes
{
public struct InterpSettings
{
public string inPath;
public string outPath;
public AI ai;
public float inFps;
public float outFps;
public int interpFactor;
public Interpolate.OutMode outMode;
public string model;
public string tempFolder;
public string framesFolder;
public string interpFolder;
public bool inputIsFrames;
public string outFilename;
public Size inputResolution;
public Size scaledResolution;
public bool alpha;
public InterpSettings(string inPathArg, string outPathArg, AI aiArg, float inFpsArg, int interpFactorArg, Interpolate.OutMode outModeArg, string modelArg)
{
inPath = inPathArg;
outPath = outPathArg;
ai = aiArg;
inFps = inFpsArg;
interpFactor = interpFactorArg;
outFps = inFpsArg * interpFactorArg;
outMode = outModeArg;
model = modelArg;
alpha = false;
try
{
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
inputIsFrames = IOUtils.IsPathDirectory(inPath);
outFilename = Path.Combine(outPath, Path.GetFileNameWithoutExtension(inPath) + IOUtils.GetExportSuffix(interpFactor, ai, model) + FFmpegUtils.GetExt(outMode));
}
catch
{
Logger.Log("Tried to create InterpSettings struct without an inpath. Can't set tempFolder, framesFolder and interpFolder.", true);
tempFolder = "";
framesFolder = "";
interpFolder = "";
inputIsFrames = false;
outFilename = "";
}
inputResolution = new Size(0, 0);
scaledResolution = new Size(0, 0);
}
public void UpdatePaths (string inPathArg, string outPathArg)
{
inPath = inPathArg;
outPath = outPathArg;
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
inputIsFrames = IOUtils.IsPathDirectory(inPath);
outFilename = Path.Combine(outPath, Path.GetFileNameWithoutExtension(inPath) + IOUtils.GetExportSuffix(interpFactor, ai, model) + FFmpegUtils.GetExt(outMode));
}
public async Task<Size> GetInputRes()
{
await RefreshResolutions();
return inputResolution;
}
public async Task<Size> GetScaledRes()
{
await RefreshResolutions();
return scaledResolution;
}
async Task RefreshResolutions ()
{
if (inputResolution.IsEmpty || scaledResolution.IsEmpty)
{
inputResolution = await IOUtils.GetVideoOrFramesRes(inPath);
scaledResolution = InterpolateUtils.GetOutputResolution(inputResolution, false);
}
}
public int GetTargetFrameCount(string overrideInputDir = "", int overrideFactor = -1)
{
if (framesFolder == null || !Directory.Exists(framesFolder))
return 0;
string framesDir = (!string.IsNullOrWhiteSpace(overrideInputDir)) ? overrideInputDir : framesFolder;
int frames = IOUtils.GetAmountOfFiles(framesDir, false, "*.png");
int factor = (overrideFactor > 0) ? overrideFactor : interpFactor;
int targetFrameCount = (frames * factor) - (interpFactor - 1);
return targetFrameCount;
}
}
}

23
Code5/Data/Networks.cs Normal file
View File

@@ -0,0 +1,23 @@
using Flowframes.IO;
using System;
using System.Collections.Generic;
namespace Flowframes.Data
{
class Networks
{
public static AI rifeCuda = new AI("RIFE_CUDA", "RIFE", "CUDA/Pytorch Implementation of RIFE", Packages.rifeCuda, true);
public static AI rifeNcnn = new AI("RIFE_NCNN", "RIFE (NCNN)", "Vulkan/NCNN Implementation of RIFE", Packages.rifeNcnn, false);
public static AI dainNcnn = new AI("DAIN_NCNN", "DAIN (NCNN)", "Vulkan/NCNN Implementation of DAIN", Packages.dainNcnn, true);
public static List<AI> networks = new List<AI>();
public static void Init ()
{
networks.Clear();
networks.Add(rifeCuda);
networks.Add(rifeNcnn);
networks.Add(dainNcnn);
}
}
}

15
Code5/Data/Packages.cs Normal file
View File

@@ -0,0 +1,15 @@

namespace Flowframes.IO
{
class Packages
{
public static FlowPackage dainNcnn = new FlowPackage("DAIN-NCNN (AMD/Nvidia)", "dain-ncnn.7z", 40, "NCNN/Vulkan implementation of DAIN. Very slow and VRAM-hungry.");
//public static FlowPackage cainNcnn = new FlowPackage("CAIN-NCNN (AMD/Nvidia)", "cain-ncnn.7z", 75, "NCNN/Vulkan implementation of CAIN. About 8x faster than DAIN and very lightweight on VRAM.");
public static FlowPackage rifeCuda = new FlowPackage("RIFE (Nvidia)", "rife-cuda.7z", 50, "Pytorch implementation of RIFE. Very fast (~2x CAIN, >16x DAIN) and not too VRAM-heavy.");
public static FlowPackage rifeNcnn = new FlowPackage("RIFE-NCNN (AMD/Nvidia) [EXPERIMENTAL]", "rife-ncnn.7z", 25, "NCNN/Vulkan implementation of RIFE. Similar speed and VRAM usage as CAIN, but can have better quality.");
//public static FlowPackage python = new FlowPackage("Python Runtime", "py.7z", 640, "Embedded Python runtime including Pytorch and all other dependencies. Install this if you don't have system Python.");
public static FlowPackage audioVideo = new FlowPackage("Audio/Video Tools (Required)", "av.7z", 10, "Utilities for extracting frames, analysing videos, encoding videos and GIFs.");
public static FlowPackage licenses = new FlowPackage("Licenses (Required)", "licenses.7z", 1, "License files for redistributed software.");
}
}

14
Code5/Data/Padding.cs Normal file
View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
class Padding
{
public const int inputFrames = 9;
public const int interpFrames = 8;
}
}

32
Code5/Data/SemVer.cs Normal file
View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
namespace Flowframes.Data
{
public struct SemVer
{
public int major;
public int minor;
public int patch;
public SemVer(int majorNum, int minorNum, int patchNum)
{
major = majorNum;
minor = minorNum;
patch = patchNum;
}
public SemVer(string versionStr)
{
string[] nums = versionStr.Trim().Split('.');
major = nums[0].GetInt();
minor = nums[1].GetInt();
patch = nums[2].GetInt();
}
public override string ToString ()
{
return $"{major}.{minor}.{patch}";
}
}
}