2020-12-23 16:13:04 +01:00
|
|
|
|
using Flowframes.AudioVideo;
|
|
|
|
|
|
using Flowframes.Data;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
using Flowframes.IO;
|
|
|
|
|
|
using Flowframes.Main;
|
2021-01-15 15:07:40 +01:00
|
|
|
|
using Flowframes.UI;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-12-22 23:45:07 +01:00
|
|
|
|
using System.Drawing;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
using System.IO;
|
2021-01-26 20:46:05 +01:00
|
|
|
|
using System.Linq;
|
2021-01-15 15:07:40 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
|
|
|
|
|
|
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;
|
2021-01-13 23:05:23 +01:00
|
|
|
|
public string model;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
|
|
|
|
|
|
public string tempFolder;
|
|
|
|
|
|
public string framesFolder;
|
|
|
|
|
|
public string interpFolder;
|
|
|
|
|
|
public bool inputIsFrames;
|
|
|
|
|
|
public string outFilename;
|
2020-12-22 23:45:07 +01:00
|
|
|
|
public Size inputResolution;
|
|
|
|
|
|
public Size scaledResolution;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
|
2021-01-18 15:32:45 +01:00
|
|
|
|
public bool alpha;
|
|
|
|
|
|
|
2021-01-13 23:05:23 +01:00
|
|
|
|
public InterpSettings(string inPathArg, string outPathArg, AI aiArg, float inFpsArg, int interpFactorArg, Interpolate.OutMode outModeArg, string modelArg)
|
2020-12-17 11:32:45 +01:00
|
|
|
|
{
|
|
|
|
|
|
inPath = inPathArg;
|
|
|
|
|
|
outPath = outPathArg;
|
|
|
|
|
|
ai = aiArg;
|
|
|
|
|
|
inFps = inFpsArg;
|
|
|
|
|
|
interpFactor = interpFactorArg;
|
|
|
|
|
|
outFps = inFpsArg * interpFactorArg;
|
|
|
|
|
|
outMode = outModeArg;
|
2021-01-13 23:05:23 +01:00
|
|
|
|
model = modelArg;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
|
2021-01-18 15:32:45 +01:00
|
|
|
|
alpha = false;
|
|
|
|
|
|
|
2020-12-18 00:19:08 +01:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
|
|
|
|
|
|
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
|
|
|
|
|
|
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
|
|
|
|
|
|
inputIsFrames = IOUtils.IsPathDirectory(inPath);
|
2021-01-14 00:19:21 +01:00
|
|
|
|
outFilename = Path.Combine(outPath, Path.GetFileNameWithoutExtension(inPath) + IOUtils.GetExportSuffix(interpFactor, ai, model) + FFmpegUtils.GetExt(outMode));
|
2020-12-18 00:19:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
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 = "";
|
|
|
|
|
|
}
|
2020-12-22 23:45:07 +01:00
|
|
|
|
|
|
|
|
|
|
inputResolution = new Size(0, 0);
|
|
|
|
|
|
scaledResolution = new Size(0, 0);
|
2020-12-18 00:19:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdatePaths (string inPathArg, string outPathArg)
|
|
|
|
|
|
{
|
|
|
|
|
|
inPath = inPathArg;
|
|
|
|
|
|
outPath = outPathArg;
|
2020-12-17 11:32:45 +01:00
|
|
|
|
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
|
|
|
|
|
|
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
|
|
|
|
|
|
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
|
|
|
|
|
|
inputIsFrames = IOUtils.IsPathDirectory(inPath);
|
2021-01-14 00:19:21 +01:00
|
|
|
|
outFilename = Path.Combine(outPath, Path.GetFileNameWithoutExtension(inPath) + IOUtils.GetExportSuffix(interpFactor, ai, model) + FFmpegUtils.GetExt(outMode));
|
2020-12-17 11:32:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-15 15:07:40 +01:00
|
|
|
|
public async Task<Size> GetInputRes()
|
2020-12-17 11:32:45 +01:00
|
|
|
|
{
|
2021-01-15 15:07:40 +01:00
|
|
|
|
await RefreshResolutions();
|
2020-12-22 23:45:07 +01:00
|
|
|
|
return inputResolution;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-15 15:07:40 +01:00
|
|
|
|
public async Task<Size> GetScaledRes()
|
2020-12-22 23:45:07 +01:00
|
|
|
|
{
|
2021-01-15 15:07:40 +01:00
|
|
|
|
await RefreshResolutions();
|
2020-12-22 23:45:07 +01:00
|
|
|
|
return scaledResolution;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-15 15:07:40 +01:00
|
|
|
|
async Task RefreshResolutions ()
|
2020-12-22 23:45:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (inputResolution.IsEmpty || scaledResolution.IsEmpty)
|
|
|
|
|
|
{
|
2021-01-15 15:07:40 +01:00
|
|
|
|
inputResolution = await IOUtils.GetVideoOrFramesRes(inPath);
|
2020-12-22 23:45:07 +01:00
|
|
|
|
scaledResolution = InterpolateUtils.GetOutputResolution(inputResolution, false);
|
|
|
|
|
|
}
|
2020-12-17 11:32:45 +01:00
|
|
|
|
}
|
2021-01-13 22:50:34 +01:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2021-01-26 20:46:05 +01:00
|
|
|
|
|
|
|
|
|
|
public void RefreshAlpha ()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-01-27 20:59:29 +01:00
|
|
|
|
bool alphaEnabled = Config.GetBool("enableAlpha", false);
|
|
|
|
|
|
bool outputSupportsAlpha = (outMode == Interpolate.OutMode.ImgPng || outMode == Interpolate.OutMode.VidGif);
|
|
|
|
|
|
|
2021-01-26 20:46:05 +01:00
|
|
|
|
if (!inputIsFrames)
|
2021-01-27 20:59:29 +01:00
|
|
|
|
alpha = (alphaEnabled && outputSupportsAlpha && (Path.GetExtension(inPath).ToLower() == ".gif"));
|
2021-01-26 20:46:05 +01:00
|
|
|
|
else
|
2021-01-27 20:59:29 +01:00
|
|
|
|
alpha = (alphaEnabled && outputSupportsAlpha && Path.GetExtension(IOUtils.GetFilesSorted(inPath).First()).ToLower() == ".gif");
|
2021-01-26 20:46:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger.Log("RefreshAlpha Error: " + e.Message, true);
|
|
|
|
|
|
alpha = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-12-17 11:32:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|