Update .NET 5 code

This commit is contained in:
Dankrushen
2021-02-08 15:39:10 -05:00
parent b4251f9f88
commit 8a1c7d3295
47 changed files with 1684 additions and 1061 deletions

View File

@@ -19,8 +19,7 @@ namespace Flowframes.Data
public AI(string aiNameArg, string friendlyNameArg, string descArg, FlowPackage pkgArg, bool supportsAnyExpArg)
{
aiName = aiNameArg;
aiNameShort = aiNameArg.Split(' ')[0];
aiNameShort = aiNameArg.Split('_')[0];
aiNameShort = aiNameArg.Split(' ')[0].Split('_')[0];
friendlyName = friendlyNameArg;
description = descArg;
pkg = pkgArg;

View File

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

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

@@ -1,12 +1,14 @@
using Flowframes.AudioVideo;
using Flowframes.Media;
using Flowframes.Data;
using Flowframes.IO;
using Flowframes.Main;
using Flowframes.MiscUtils;
using Flowframes.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Flowframes
@@ -18,7 +20,7 @@ namespace Flowframes
public AI ai;
public float inFps;
public float outFps;
public int interpFactor;
public float interpFactor;
public Interpolate.OutMode outMode;
public string model;
@@ -31,6 +33,7 @@ namespace Flowframes
public Size scaledResolution;
public bool alpha;
public bool stepByStep;
public InterpSettings(string inPathArg, string outPathArg, AI aiArg, float inFpsArg, int interpFactorArg, Interpolate.OutMode outModeArg, string modelArg)
{
@@ -44,6 +47,7 @@ namespace Flowframes
model = modelArg;
alpha = false;
stepByStep = false;
try
{
@@ -67,6 +71,68 @@ namespace Flowframes
scaledResolution = new Size(0, 0);
}
public InterpSettings (string serializedData)
{
inPath = "";
outPath = "";
ai = Networks.networks[0];
inFps = 0;
interpFactor = 0;
outFps = 0;
outMode = Interpolate.OutMode.VidMp4;
model = "";
alpha = false;
stepByStep = false;
inputResolution = new Size(0, 0);
scaledResolution = new Size(0, 0);
Dictionary<string, string> entries = new Dictionary<string, string>();
foreach(string line in serializedData.SplitIntoLines())
{
if (line.Length < 3) continue;
string[] keyValuePair = line.Split('|');
entries.Add(keyValuePair[0], keyValuePair[1]);
}
foreach (KeyValuePair<string, string> entry in entries)
{
switch (entry.Key)
{
case "INPATH": inPath = entry.Value; break;
case "OUTPATH": outPath = entry.Value; break;
case "AI": ai = Networks.GetAi(entry.Value); break;
case "INFPS": inFps = float.Parse(entry.Value); break;
case "OUTFPS": outFps = float.Parse(entry.Value); break;
case "INTERPFACTOR": interpFactor = float.Parse(entry.Value); break;
case "OUTMODE": outMode = (Interpolate.OutMode)Enum.Parse(typeof(Interpolate.OutMode), entry.Value); break;
case "MODEL": model = entry.Value; break;
case "INPUTRES": inputResolution = FormatUtils.ParseSize(entry.Value); break;
case "OUTPUTRES": scaledResolution = FormatUtils.ParseSize(entry.Value); break;
case "ALPHA": alpha = bool.Parse(entry.Value); break;
case "STEPBYSTEP": stepByStep = bool.Parse(entry.Value); break;
}
}
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 = "";
}
}
public void UpdatePaths (string inPathArg, string outPathArg)
{
inPath = inPathArg;
@@ -99,16 +165,50 @@ namespace Flowframes
}
}
public int GetTargetFrameCount(string overrideInputDir = "", int overrideFactor = -1)
public int GetTargetFrameCount(string overrideInputDir = "", float 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);
float factor = (overrideFactor > 0) ? overrideFactor : interpFactor;
int targetFrameCount = ((frames * factor) - (interpFactor - 1)).RoundToInt();
return targetFrameCount;
}
public void RefreshAlpha ()
{
try
{
bool alphaEnabled = Config.GetBool("enableAlpha", false);
bool outputSupportsAlpha = (outMode == Interpolate.OutMode.ImgPng || outMode == Interpolate.OutMode.VidGif);
string ext = inputIsFrames ? Path.GetExtension(IOUtils.GetFilesSorted(inPath).First()).ToLower() : Path.GetExtension(inPath).ToLower();
alpha = (alphaEnabled && outputSupportsAlpha && (ext == ".gif" || ext == ".png" || ext == ".apng"));
}
catch (Exception e)
{
Logger.Log("RefreshAlpha Error: " + e.Message, true);
alpha = false;
}
}
public string Serialize ()
{
string s = $"INPATH|{inPath}\n";
s += $"OUTPATH|{outPath}\n";
s += $"AI|{ai.aiName}\n";
s += $"INFPS|{inFps.ToStringDot()}\n";
s += $"OUTFPS|{outFps.ToStringDot()}\n";
s += $"INTERPFACTOR|{interpFactor}\n";
s += $"OUTMODE|{outMode}\n";
s += $"MODEL|{model}\n";
s += $"INPUTRES|{inputResolution.Width}x{inputResolution.Height}\n";
s += $"OUTPUTRES|{scaledResolution.Width}x{scaledResolution.Height}\n";
s += $"ALPHA|{alpha}\n";
s += $"STEPBYSTEP|{stepByStep}\n";
return s;
}
}
}

View File

@@ -19,5 +19,16 @@ namespace Flowframes.Data
networks.Add(rifeNcnn);
networks.Add(dainNcnn);
}
public static AI GetAi (string aiName)
{
foreach(AI ai in networks)
{
if (ai.aiName == aiName)
return ai;
}
return networks[0];
}
}
}

View File

@@ -9,6 +9,7 @@ namespace Flowframes.Data
class Padding
{
public const int inputFrames = 9;
public const int inputFramesRenamed = 8;
public const int interpFrames = 8;
}
}

57
Code5/Data/Paths.cs Normal file
View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Flowframes.IO
{
class Paths
{
public const string framesDir = "frames";
public const string interpDir = "interp";
public const string chunksDir = "vchunks";
public const string resumeDir = "resumedata";
public const string scenesDir = "scenes";
public const string alphaSuffix = "-a";
public const string prevSuffix = "-previous";
public const string frameOrderPrefix = "frames";
public static string GetFrameOrderFilename(float factor)
{
return $"{frameOrderPrefix}-{factor.ToStringDot()}x.ini";
}
public static string GetFrameOrderFilenameChunk (int from, int to)
{
return $"{frameOrderPrefix}-chunk-{from}-{to}.ini";
}
public static string GetVerPath()
{
return Path.Combine(GetDataPath(), "ver.ini");
}
public static string GetDataPath ()
{
string path = Path.Combine(IOUtils.GetExeDir(), "FlowframesData");
Directory.CreateDirectory(path);
return path;
}
public static string GetPkgPath()
{
string path = Path.Combine(GetDataPath(), "pkgs");
Directory.CreateDirectory(path);
return path;
}
public static string GetLogPath()
{
string path = Path.Combine(GetDataPath(), "logs");
Directory.CreateDirectory(path);
return path;
}
}
}

56
Code5/Data/ResumeState.cs Normal file
View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
public struct ResumeState
{
public bool autoEncode;
public int interpolatedInputFrames;
public ResumeState (bool autoEncArg, int lastInterpInFrameArg)
{
autoEncode = autoEncArg;
interpolatedInputFrames = lastInterpInFrameArg;
}
public ResumeState(string serializedData)
{
autoEncode = false;
interpolatedInputFrames = 0;
Dictionary<string, string> entries = new Dictionary<string, string>();
foreach (string line in serializedData.SplitIntoLines())
{
if (line.Length < 3) continue;
string[] keyValuePair = line.Split('|');
entries.Add(keyValuePair[0], keyValuePair[1]);
}
foreach (KeyValuePair<string, string> entry in entries)
{
switch (entry.Key)
{
case "AUTOENC": autoEncode = bool.Parse(entry.Value); break;
case "INTERPOLATEDINPUTFRAMES": interpolatedInputFrames = entry.Value.GetInt(); break;
}
}
}
public override string ToString ()
{
string s = $"AUTOENC|{autoEncode}\n";
if (!autoEncode)
{
s += $"INTERPOLATEDINPUTFRAMES|{interpolatedInputFrames}";
}
return s;
}
}
}

View File

@@ -1,32 +0,0 @@
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}";
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace Flowframes.Data
{
class SubtitleTrack
{
public int streamIndex;
public string lang;
public string langFriendly;
public string encoding;
public SubtitleTrack (int streamNum, string langStr, string encodingStr)
{
streamIndex = streamNum;
lang = langStr;
langFriendly = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(langStr.ToLower());
encoding = encodingStr.Trim();
}
}
}