This commit is contained in:
N00MKRAD
2020-11-23 16:51:05 +01:00
parent 95b5df029e
commit 1bce73dea6
133 changed files with 25577 additions and 0 deletions

69
Code/UI/FormatUtils.cs Normal file
View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.UI
{
class FormatUtils
{
public static string Bytes(long sizeBytes)
{
int sizeKb = (int)Math.Round(sizeBytes / 1024f);
int sizeMb = (int)Math.Round(sizeKb / 1024f);
if (sizeBytes <= 8192)
{
return sizeBytes + " B";
}
if (sizeKb <= 8192)
{
return sizeKb + " KB";
}
return sizeMb + " MB"; ;
}
public static string Time(long milliseconds)
{
double secs = (milliseconds / 1000f);
if (milliseconds <= 1000)
{
return milliseconds + "ms";
}
return secs.ToString("0.00") + "s";
}
public static string Time (TimeSpan span)
{
if(span.TotalHours >= 1f)
return span.ToString(@"hh\:mm\:ss");
if (span.TotalMinutes >= 1f)
return span.ToString(@"mm\:ss");
if (span.TotalSeconds >= 1f)
return span.ToString(@"ss") + "s";
return span.Milliseconds.ToString() + "ms";
}
public static string TimeSw(Stopwatch sw)
{
long elapsedMs = sw.ElapsedMilliseconds;
return Time(elapsedMs);
}
public static string Ratio(long numFrom, long numTo)
{
float ratio = ((float)numTo / (float)numFrom) * 100f;
return ratio.ToString("0.00") + "%";
}
public static string RatioInt(long numFrom, long numTo)
{
double ratio = Math.Round(((float)numTo / (float)numFrom) * 100f);
return ratio + "%";
}
}
}

36
Code/UI/UIUtils.cs Normal file
View File

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

112
Code/UI/UtilsTab.cs Normal file
View 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";
bool rgb8 = Formats.preprocess.Contains(Path.GetExtension(videoPath).ToLower());
Program.mainForm.SetWorking(true);
await FFmpegCommands.VideoToFrames(videoPath, Path.Combine(outPath, "frames"), false, rgb8, false, false);
File.WriteAllText(Path.Combine(outPath, "fps.ini"), Interpolate.currentInFps.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(Formats.noEncodeSupport.Contains(Path.GetExtension(inputFile)))
await FFmpegCommands.Encode(inputFile, "libx264", "aac", crf, 112, false); // Use AAC if there is no audio enc for this format
else
await FFmpegCommands.Encode(inputFile, "libx264", "copy", crf, 0, false); // Copy audio if compatible
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";
await Interpolate.ExtractFrames(inPath, framesPath);
}
else
{
framesPath = inPath;
}
Program.mainForm.SetWorking(true);
Logger.Log("Running frame de-duplication", true);
await Task.Delay(10);
await FrameDedup.Run(framesPath, testRun);
IOUtils.TryDeleteIfExists(framesPath);
Program.mainForm.SetProgress(0);
Program.mainForm.SetWorking(false);
}
}
}