Files
flowframes/Code/Data/InterpSettings.cs

135 lines
4.8 KiB
C#
Raw Normal View History

using Flowframes.AudioVideo;
using Flowframes.Data;
2020-12-17 11:32:45 +01:00
using Flowframes.IO;
using Flowframes.Main;
using Flowframes.UI;
2020-12-17 11:32:45 +01:00
using System;
using System.Collections.Generic;
using System.Drawing;
2020-12-17 11:32:45 +01:00
using System.IO;
using System.Linq;
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;
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;
public Size inputResolution;
public Size scaledResolution;
2020-12-17 11:32:45 +01:00
public bool alpha;
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;
model = modelArg;
2020-12-17 11:32:45 +01:00
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;
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);
outFilename = Path.Combine(outPath, Path.GetFileNameWithoutExtension(inPath) + IOUtils.GetExportSuffix(interpFactor, ai, model) + FFmpegUtils.GetExt(outMode));
2020-12-17 11:32:45 +01:00
}
public async Task<Size> GetInputRes()
2020-12-17 11:32:45 +01:00
{
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);
}
2020-12-17 11:32:45 +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;
}
public void RefreshAlpha ()
{
try
{
bool alphaEnabled = Config.GetBool("enableAlpha", false);
bool outputSupportsAlpha = (outMode == Interpolate.OutMode.ImgPng || outMode == Interpolate.OutMode.VidGif);
if (!inputIsFrames)
alpha = (alphaEnabled && outputSupportsAlpha && (Path.GetExtension(inPath).ToLower() == ".gif"));
else
alpha = (alphaEnabled && outputSupportsAlpha && Path.GetExtension(IOUtils.GetFilesSorted(inPath).First()).ToLower() == ".gif");
}
catch (Exception e)
{
Logger.Log("RefreshAlpha Error: " + e.Message, true);
alpha = false;
}
}
2020-12-17 11:32:45 +01:00
}
}