mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-25 04:39:25 +01:00
Port to .NET 5
This commit is contained in:
70
Code5/UI/GetWebInfo.cs
Normal file
70
Code5/UI/GetWebInfo.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Flowframes.UI
|
||||
{
|
||||
class GetWebInfo
|
||||
{
|
||||
public static async Task LoadNews (Label newsLabel)
|
||||
{
|
||||
string url = $"http://dl.nmkd.de/flowframes/changelog.txt";
|
||||
var client = new WebClient();
|
||||
var str = await client.DownloadStringTaskAsync(new Uri(url));
|
||||
newsLabel.Text = str;
|
||||
}
|
||||
|
||||
public static async Task LoadPatronList(Label patronsLabel)
|
||||
{
|
||||
string url = $"http://dl.nmkd.de/flowframes/patreon.txt";
|
||||
var client = new WebClient();
|
||||
var str = await client.DownloadStringTaskAsync(new Uri(url));
|
||||
patronsLabel.Text = str;
|
||||
}
|
||||
|
||||
public static async Task LoadPatronListCsv(Label patronsLabel)
|
||||
{
|
||||
string url = $"http://dl.nmkd.de/flowframes/patrons.csv";
|
||||
var client = new WebClient();
|
||||
var csvData = await client.DownloadStringTaskAsync(new Uri(url));
|
||||
patronsLabel.Text = ParsePatreonCsv(csvData);
|
||||
}
|
||||
|
||||
public static string ParsePatreonCsv(string csvData)
|
||||
{
|
||||
List<string> goldPatrons = new List<string>();
|
||||
List<string> silverPatrons = new List<string>();
|
||||
string str = "Gold:\n";
|
||||
string[] lines = csvData.SplitIntoLines();
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
string line = lines[i];
|
||||
string[] values = line.Split(',');
|
||||
if (i == 0 || line.Length < 10 || values.Length < 5) continue;
|
||||
string name = values[0];
|
||||
float amount = float.Parse(values[7], System.Globalization.CultureInfo.InvariantCulture);
|
||||
if(amount >= 4.5f)
|
||||
{
|
||||
if (amount >= 11f)
|
||||
goldPatrons.Add(name);
|
||||
else
|
||||
silverPatrons.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string pat in goldPatrons)
|
||||
str += pat + "\n";
|
||||
|
||||
str += "\nSilver:\n";
|
||||
|
||||
foreach (string pat in silverPatrons)
|
||||
str += pat + "\n";
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
125
Code5/UI/MainUiFunctions.cs
Normal file
125
Code5/UI/MainUiFunctions.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using Flowframes.IO;
|
||||
using Flowframes.Magick;
|
||||
using Flowframes.Main;
|
||||
using Flowframes.OS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Flowframes.UI
|
||||
{
|
||||
class MainUiFunctions
|
||||
{
|
||||
public static async Task InitInput (TextBox outputTbox, TextBox inputTbox, TextBox fpsInTbox)
|
||||
{
|
||||
Program.mainForm.SetTab("interpolate");
|
||||
|
||||
if (Config.GetBool("clearLogOnInput"))
|
||||
Logger.ClearLogBox();
|
||||
|
||||
outputTbox.Text = inputTbox.Text.Trim().GetParentDir();
|
||||
string path = inputTbox.Text.Trim();
|
||||
Program.lastInputPath = path;
|
||||
|
||||
Program.lastInputPathIsSsd = OSUtils.DriveIsSSD(path);
|
||||
if (!Program.lastInputPathIsSsd)
|
||||
Logger.Log("Your file seems to be on an HDD or USB device. It is recommended to interpolate videos on an SSD drive for best performance.");
|
||||
|
||||
Logger.Log("Loading metadata...");
|
||||
int frameCount = await InterpolateUtils.GetInputFrameCountAsync(path);
|
||||
|
||||
string fpsStr = "Not Found";
|
||||
float fps = IOUtils.GetFpsFolderOrVideo(path);
|
||||
if (fps > 0)
|
||||
{
|
||||
fpsStr = fps.ToString();
|
||||
fpsInTbox.Text = fpsStr;
|
||||
}
|
||||
|
||||
if (IOUtils.IsPathDirectory(path))
|
||||
Logger.Log($"Video FPS (Loaded from fps.ini): {fpsStr} - Total Number Of Frames: {frameCount}", false, true);
|
||||
else
|
||||
Logger.Log($"Video FPS: {fpsStr} - Total Number Of Frames: {frameCount}", false, true);
|
||||
|
||||
Program.mainForm.currInFps = fps;
|
||||
Program.mainForm.currInFrames = frameCount;
|
||||
Program.mainForm.UpdateInputInfo();
|
||||
CheckExistingFolder(path, outputTbox.Text.Trim());
|
||||
await Task.Delay(10);
|
||||
await PrintResolution(path);
|
||||
Dedupe.ClearCache();
|
||||
await Task.Delay(10);
|
||||
InterpolateUtils.SetPreviewImg(await GetThumbnail(path));
|
||||
}
|
||||
|
||||
static void CheckExistingFolder (string inpath, string outpath)
|
||||
{
|
||||
if (Config.GetInt("processingMode") == 0) return;
|
||||
string tmpFolder = InterpolateUtils.GetTempFolderLoc(inpath, outpath);
|
||||
if (Directory.Exists(tmpFolder))
|
||||
{
|
||||
int scnFrmAmount = IOUtils.GetAmountOfFiles(Path.Combine(tmpFolder, Paths.scenesDir), false, "*.png");
|
||||
string scnFrames = scnFrmAmount > 0 ? $"{scnFrmAmount} scene frames" : "no scene frames";
|
||||
int srcFrmAmount = IOUtils.GetAmountOfFiles(Path.Combine(tmpFolder, Paths.framesDir), false, "*.png");
|
||||
string srcFrames = srcFrmAmount > 1 ? $"{srcFrmAmount} source frames" : "no source frames";
|
||||
int interpFrmAmount = IOUtils.GetAmountOfFiles(Path.Combine(tmpFolder, Paths.interpDir), false);
|
||||
string interpFrames = interpFrmAmount > 2 ? $"{interpFrmAmount} interpolated frames" : "no interpolated frames";
|
||||
string msg = $"A temporary folder for this video already exists. It contains {scnFrames}, {srcFrames}, {interpFrames}.";
|
||||
|
||||
DialogResult dialogResult = MessageBox.Show($"{msg}\n\nClick \"Yes\" to use the existing files or \"No\" to delete them.", "Use files from existing temp folder?", MessageBoxButtons.YesNo);
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (dialogResult == DialogResult.No)
|
||||
{
|
||||
IOUtils.TryDeleteIfExists(tmpFolder);
|
||||
Logger.Log("Deleted old temp folder.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async Task PrintResolution (string path)
|
||||
{
|
||||
Size res = new Size();
|
||||
|
||||
if(path == Interpolate.current.inPath)
|
||||
res = await Interpolate.current.GetInputRes();
|
||||
else
|
||||
res = await IOUtils.GetVideoOrFramesRes(path);
|
||||
|
||||
if (res.Width > 1 && res.Height > 1)
|
||||
Logger.Log($"Input Resolution: {res.Width}x{res.Height}");
|
||||
|
||||
Program.mainForm.currInRes = res;
|
||||
Program.mainForm.UpdateInputInfo();
|
||||
}
|
||||
|
||||
public static async Task<Image> GetThumbnail (string path)
|
||||
{
|
||||
string imgOnDisk = Path.Combine(Paths.GetDataPath(), "thumb-temp.jpg");
|
||||
try
|
||||
{
|
||||
if (!IOUtils.IsPathDirectory(path)) // If path is video - Extract first frame
|
||||
{
|
||||
await FFmpegCommands.ExtractSingleFrame(path, imgOnDisk, 1);
|
||||
return IOUtils.GetImage(imgOnDisk);
|
||||
}
|
||||
else // Path is frame folder - Get first frame
|
||||
{
|
||||
return IOUtils.GetImage(IOUtils.GetFilesSorted(path)[0]);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log("GetThumbnail Error: " + e.Message, true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Code5/UI/UIUtils.cs
Normal file
63
Code5/UI/UIUtils.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Flowframes.Data;
|
||||
using Flowframes.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Flowframes.UI
|
||||
{
|
||||
class UIUtils
|
||||
{
|
||||
public static void InitCombox(ComboBox box, int index)
|
||||
{
|
||||
if (box.Items.Count >= 1)
|
||||
{
|
||||
box.SelectedIndex = index;
|
||||
box.Text = box.Items[index].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AssignComboxIndexFromText (ComboBox box, string text) // Set index to corresponding text
|
||||
{
|
||||
int index = box.Items.IndexOf(text);
|
||||
|
||||
if (index == -1) // custom value, index not found
|
||||
return false;
|
||||
|
||||
box.SelectedIndex = index;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ComboBox FillAiModelsCombox (ComboBox combox, AI ai)
|
||||
{
|
||||
string pkgPath = PkgUtils.GetPkgFolder(ai.pkg);
|
||||
string modelsFile = Path.Combine(pkgPath, "models.txt");
|
||||
string[] modelsWithDec = IOUtils.ReadLines(modelsFile);
|
||||
combox.Items.Clear();
|
||||
|
||||
for (int i = 0; i < modelsWithDec.Length; i++)
|
||||
{
|
||||
string model = modelsWithDec[i];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(model))
|
||||
continue;
|
||||
|
||||
combox.Items.Add(model);
|
||||
|
||||
if (model.Contains("Recommended") || model.Contains("Default"))
|
||||
combox.SelectedIndex = i;
|
||||
}
|
||||
|
||||
if(combox.SelectedIndex < 0)
|
||||
combox.SelectedIndex = 0;
|
||||
|
||||
return combox;
|
||||
}
|
||||
}
|
||||
}
|
||||
112
Code5/UI/UtilsTab.cs
Normal file
112
Code5/UI/UtilsTab.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using Flowframes.IO;
|
||||
using Flowframes.Magick;
|
||||
using Flowframes.Main;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Flowframes.UI
|
||||
{
|
||||
class UtilsTab
|
||||
{
|
||||
|
||||
|
||||
public static async Task ExtractVideo(string videoPath, bool withAudio)
|
||||
{
|
||||
string outPath = Path.ChangeExtension(videoPath, null) + "-extracted";
|
||||
Program.mainForm.SetWorking(true);
|
||||
await FFmpegCommands.VideoToFrames(videoPath, Path.Combine(outPath, Paths.framesDir), false, Interpolate.current.inFps, false, false, false);
|
||||
File.WriteAllText(Path.Combine(outPath, "fps.ini"), Interpolate.current.inFps.ToString());
|
||||
if (withAudio)
|
||||
await FFmpegCommands.ExtractAudio(videoPath, Path.Combine(outPath, "audio"));
|
||||
Program.mainForm.SetWorking(false);
|
||||
Logger.Log("Done.");
|
||||
}
|
||||
|
||||
public static async Task LoopVideo (string inputFile, ComboBox loopTimes)
|
||||
{
|
||||
if (!InputIsValid(inputFile))
|
||||
return;
|
||||
int times = loopTimes.GetInt();
|
||||
Logger.Log("Lopping video " + times + "x...", true);
|
||||
await FFmpegCommands.LoopVideo(inputFile, times, false);
|
||||
Logger.Log("Done", true);
|
||||
}
|
||||
|
||||
public static async Task ChangeSpeed(string inputFile, ComboBox speed)
|
||||
{
|
||||
if (!InputIsValid(inputFile))
|
||||
return;
|
||||
float speedFloat = speed.GetFloat();
|
||||
Logger.Log("Creating video with " + speed + "% speed...", true);
|
||||
await FFmpegCommands.ChangeSpeed(inputFile, speedFloat, false);
|
||||
Logger.Log("Done", true);
|
||||
}
|
||||
|
||||
public static async Task Convert(string inputFile, ComboBox crfBox)
|
||||
{
|
||||
if (!InputIsValid(inputFile))
|
||||
return;
|
||||
int crf = crfBox.GetInt();
|
||||
Logger.Log("Creating MP4 with CRF " + crf + "...", true);
|
||||
if(Path.GetExtension(inputFile).ToUpper() != ".MP4")
|
||||
await FFmpegCommands.Encode(inputFile, "libx264", "aac", crf, 128);
|
||||
else
|
||||
await FFmpegCommands.Encode(inputFile, "libx264", "copy", crf); // Copy audio if input is MP4
|
||||
Logger.Log("Done", true);
|
||||
}
|
||||
|
||||
static bool InputIsValid (string inPath)
|
||||
{
|
||||
bool isFile = !IOUtils.IsPathDirectory(inPath);
|
||||
if ((isFile && !IOUtils.IsFileValid(inPath)) || (!isFile && !IOUtils.IsDirValid(inPath)))
|
||||
{
|
||||
MessageBox.Show("Input path is not valid!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async void Dedupe (string inPath, bool testRun)
|
||||
{
|
||||
bool isFile = !IOUtils.IsPathDirectory(inPath);
|
||||
if ((isFile && !IOUtils.IsFileValid(inPath)) || (!isFile && !IOUtils.IsDirValid(inPath)))
|
||||
{
|
||||
MessageBox.Show("Input path is not valid!");
|
||||
return;
|
||||
}
|
||||
|
||||
string framesPath;
|
||||
|
||||
if (isFile)
|
||||
{
|
||||
Logger.Log("Input is a file, not directory");
|
||||
if (!InterpolateUtils.IsVideoValid(inPath))
|
||||
{
|
||||
MessageBox.Show("Input file is not valid!", "Error");
|
||||
return;
|
||||
}
|
||||
Program.mainForm.SetWorking(true);
|
||||
await Task.Delay(10);
|
||||
framesPath = Path.ChangeExtension(inPath, null) + "-frames";
|
||||
Directory.CreateDirectory(framesPath);
|
||||
await Interpolate.ExtractFrames(inPath, framesPath, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
framesPath = inPath;
|
||||
}
|
||||
Program.mainForm.SetWorking(true);
|
||||
Logger.Log("Running frame de-duplication", true);
|
||||
await Task.Delay(10);
|
||||
await Magick.Dedupe.Run(framesPath, testRun);
|
||||
IOUtils.TryDeleteIfExists(framesPath);
|
||||
Program.mainForm.SetProgress(0);
|
||||
Program.mainForm.SetWorking(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user