mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-24 12:19:27 +01:00
Fix VS modulo padding
This commit is contained in:
@@ -35,8 +35,8 @@ namespace Flowframes
|
||||
|
||||
private Size _inputResolution;
|
||||
public Size InputResolution { get { RefreshInputRes(); return _inputResolution; } }
|
||||
private Size _scaledResolution;
|
||||
public Size ScaledResolution { get { RefreshOutputRes(); return _scaledResolution; } }
|
||||
public Size ScaledResolution { get { return InterpolateUtils.GetOutputResolution(InputResolution, false); } }
|
||||
public Size ScaledPaddedResolution { get { return InterpolateUtils.GetOutputResolution(InputResolution, true); } }
|
||||
|
||||
public bool alpha;
|
||||
public bool stepByStep;
|
||||
@@ -82,7 +82,6 @@ namespace Flowframes
|
||||
}
|
||||
|
||||
_inputResolution = new Size(0, 0);
|
||||
_scaledResolution = new Size(0, 0);
|
||||
|
||||
RefreshExtensions();
|
||||
}
|
||||
@@ -101,7 +100,6 @@ namespace Flowframes
|
||||
alpha = false;
|
||||
stepByStep = false;
|
||||
_inputResolution = new Size(0, 0);
|
||||
_scaledResolution = new Size(0, 0);
|
||||
framesExt = "";
|
||||
interpExt = "";
|
||||
|
||||
@@ -128,7 +126,6 @@ namespace Flowframes
|
||||
case "OUTMODE": outMode = (Interpolate.OutMode)Enum.Parse(typeof(Interpolate.OutMode), entry.Value); break;
|
||||
case "MODEL": model = AiModels.GetModelByName(ai, 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;
|
||||
case "FRAMESEXT": framesExt = entry.Value; break;
|
||||
@@ -171,12 +168,6 @@ namespace Flowframes
|
||||
_inputResolution = await GetMediaResolutionCached.GetSizeAsync(inPath);
|
||||
}
|
||||
|
||||
void RefreshOutputRes ()
|
||||
{
|
||||
if (_scaledResolution.IsEmpty)
|
||||
_scaledResolution = InterpolateUtils.GetOutputResolution(InputResolution, false, true);
|
||||
}
|
||||
|
||||
public void RefreshAlpha ()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -568,7 +568,7 @@ namespace Flowframes.IO
|
||||
if (curr.outMode == Interpolate.OutMode.VidGif && fps > 50f)
|
||||
fps = 50f;
|
||||
|
||||
Size outRes = await InterpolateUtils.GetOutputResolution(curr.inPath, false, false);
|
||||
Size outRes = await InterpolateUtils.GetOutputResolution(curr.inPath, true);
|
||||
string pattern = Config.Get(Config.Key.exportNamePattern);
|
||||
string inName = Interpolate.currentSettings.inputIsFrames ? Path.GetFileName(curr.inPath) : Path.GetFileNameWithoutExtension(curr.inPath);
|
||||
bool encodeBoth = Config.GetInt(Config.Key.maxFpsMode) == 0;
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using I = Flowframes.Interpolate;
|
||||
using Padding = Flowframes.Data.Padding;
|
||||
using static Flowframes.Magick.Dedupe;
|
||||
|
||||
namespace Flowframes.Main
|
||||
{
|
||||
@@ -138,7 +139,7 @@ namespace Flowframes.Main
|
||||
|
||||
return passes;
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log($"Failed to run InputIsValid: {e.Message}\n{e.StackTrace}", true);
|
||||
return false;
|
||||
@@ -186,7 +187,7 @@ namespace Flowframes.Main
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ShowWarnings (float factor, AI ai)
|
||||
public static void ShowWarnings(float factor, AI ai)
|
||||
{
|
||||
if (Config.GetInt(Config.Key.cmdDebugMode) > 0)
|
||||
Logger.Log($"Warning: The CMD window for interpolation is enabled. This will disable Auto-Encode and the progress bar!");
|
||||
@@ -221,7 +222,7 @@ namespace Flowframes.Main
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<bool> CheckEncoderValid (float interpFps)
|
||||
public static async Task<bool> CheckEncoderValid(float interpFps)
|
||||
{
|
||||
string enc = FfmpegUtils.GetEnc(FfmpegUtils.GetCodec(I.currentSettings.outMode));
|
||||
|
||||
@@ -253,33 +254,29 @@ namespace Flowframes.Main
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<Size> GetOutputResolution(string inputPath, bool print, bool returnZeroIfUnchanged = false)
|
||||
public static async Task<Size> GetOutputResolution(string inputPath, bool pad, bool print = false)
|
||||
{
|
||||
Size resolution = await GetMediaResolutionCached.GetSizeAsync(inputPath);
|
||||
return GetOutputResolution(resolution, print, returnZeroIfUnchanged);
|
||||
return GetOutputResolution(resolution, pad, print);
|
||||
}
|
||||
|
||||
public static Size GetOutputResolution(Size inputRes, bool print = false, bool returnZeroIfUnchanged = false)
|
||||
public static Size GetOutputResolution(Size inputRes, bool pad, bool print = false)
|
||||
{
|
||||
int maxHeightValue = Config.GetInt(Config.Key.maxVidHeight);
|
||||
int maxHeight = RoundDivisibleBy(maxHeightValue, FfmpegCommands.GetPadding());
|
||||
Size res = new Size(inputRes.Width, inputRes.Height);
|
||||
int maxHeight = Config.GetInt(Config.Key.maxVidHeight);
|
||||
int mod = pad ? FfmpegCommands.GetModulo() : 1;
|
||||
float factor = res.Height > maxHeight ? (float)maxHeight / res.Height : 1f; // Calculate downscale factor if bigger than max, otherwise just use 1x
|
||||
Logger.Log($"Un-rounded downscaled size: {(res.Width * factor).ToString("0.###")}x{(res.Height * factor).ToString("0.###")}", true);
|
||||
int width = RoundDivisibleBy((res.Width * factor).RoundToInt(), mod);
|
||||
int height = RoundDivisibleBy((res.Height * factor).RoundToInt(), mod);
|
||||
|
||||
if (inputRes.Height > maxHeight)
|
||||
{
|
||||
float factor = (float)maxHeight / inputRes.Height;
|
||||
Logger.Log($"Un-rounded downscaled size: {(inputRes.Width * factor).ToString("0.00")}x{maxHeightValue}", true);
|
||||
int width = RoundDivisibleBy((inputRes.Width * factor).RoundToInt(), FfmpegCommands.GetPadding());
|
||||
if (print)
|
||||
Logger.Log($"Video is bigger than the maximum - Downscaling to {width}x{maxHeight}.");
|
||||
return new Size(width, maxHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (returnZeroIfUnchanged)
|
||||
return new Size();
|
||||
else
|
||||
return inputRes;
|
||||
}
|
||||
if (print && factor < 1f)
|
||||
Logger.Log($"Video is bigger than the maximum - Downscaling to {width}x{height}.");
|
||||
|
||||
if (res != inputRes)
|
||||
Logger.Log($"Scaled {inputRes.Width}x{inputRes.Height} to {res.Width}x{res.Height}", true);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static int RoundDivisibleBy(int number, int divisibleBy) // Round to a number that's divisible by 2 (for h264 etc)
|
||||
@@ -305,7 +302,7 @@ namespace Flowframes.Main
|
||||
return false;
|
||||
}
|
||||
|
||||
if(current.outMode == I.OutMode.VidGif)
|
||||
if (current.outMode == I.OutMode.VidGif)
|
||||
{
|
||||
Logger.Log($"Not Using AutoEnc: Using GIF output", true);
|
||||
return false;
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Flowframes.Media
|
||||
public static async Task ExtractAlphaDir(string rgbDir, string alphaDir)
|
||||
{
|
||||
Directory.CreateDirectory(alphaDir);
|
||||
|
||||
foreach (FileInfo file in IoUtils.GetFileInfosSorted(rgbDir))
|
||||
{
|
||||
string args = $"-i {file.FullName.Wrap()} -vf \"format=yuva444p16le,alphaextract,format=yuv420p,{GetPadFilter()}\" {Path.Combine(alphaDir, file.Name).Wrap()}";
|
||||
|
||||
@@ -11,7 +11,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static Flowframes.AvProcess;
|
||||
using Utils = Flowframes.Media.FfmpegUtils;
|
||||
|
||||
namespace Flowframes
|
||||
{
|
||||
@@ -23,15 +22,15 @@ namespace Flowframes
|
||||
public static string mpDecDef = "\"mpdecimate\"";
|
||||
public static string mpDecAggr = "\"mpdecimate=hi=64*32:lo=64*32:frac=0.1\"";
|
||||
|
||||
public static int GetPadding ()
|
||||
public static int GetModulo ()
|
||||
{
|
||||
return (Interpolate.currentSettings.ai.NameInternal == Implementations.flavrCuda.NameInternal) ? 8 : 2; // FLAVR input needs to be divisible by 8
|
||||
}
|
||||
|
||||
public static string GetPadFilter ()
|
||||
{
|
||||
int padPixels = GetPadding();
|
||||
return $"pad=width=ceil(iw/{padPixels})*{padPixels}:height=ceil(ih/{padPixels})*{padPixels}:color=black@0";
|
||||
int mod = GetModulo();
|
||||
return $"pad=width=ceil(iw/{mod})*{mod}:height=ceil(ih/{mod})*{mod}:color=black@0";
|
||||
}
|
||||
|
||||
public static async Task ConcatVideos(string concatFile, string outPath, int looptimes = -1, bool showLog = true)
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace Flowframes.Media
|
||||
if(!isChunk && outMode == Interpolate.OutMode.VidMp4)
|
||||
extraArgs += $" -movflags +faststart";
|
||||
|
||||
filters.Add(GetPadFilter());
|
||||
return filters.Count > 0 ? $"-vf {string.Join(",", filters)}" : "" + $" {extraArgs}";
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace Flowframes.Media
|
||||
return false;
|
||||
}
|
||||
|
||||
int div = GetPadding();
|
||||
int div = GetModulo();
|
||||
bool allDivBy2 = randomSamples.All(i => (i.Width % div == 0) && (i.Height % div == 0));
|
||||
|
||||
if (!allDivBy2)
|
||||
|
||||
Reference in New Issue
Block a user