mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-16 16:37:48 +01:00
Native alpha support with RIFE 3.5
This commit is contained in:
@@ -182,11 +182,11 @@ namespace Flowframes
|
||||
{
|
||||
try
|
||||
{
|
||||
bool alphaEnabled = Config.GetBool(Config.Key.enableAlpha, false);
|
||||
bool alphaModel = model.supportsAlpha;
|
||||
bool outputSupportsAlpha = (outMode == Interpolate.OutMode.ImgPng || outMode == Interpolate.OutMode.VidGif);
|
||||
string ext = inputIsFrames ? Path.GetExtension(IOUtils.GetFilesSorted(inPath).First()).ToLower() : Path.GetExtension(inPath).ToLower();
|
||||
alpha = (alphaEnabled && outputSupportsAlpha && (ext == ".gif" || ext == ".png" || ext == ".apng"));
|
||||
Logger.Log($"RefreshAlpha: alphaEnabled = {alphaEnabled} - outputSupportsAlpha = {outputSupportsAlpha} - " +
|
||||
alpha = (alphaModel && outputSupportsAlpha && (ext == ".gif" || ext == ".png" || ext == ".apng"));
|
||||
Logger.Log($"RefreshAlpha: model.supportsAlpha = {alphaModel} - outputSupportsAlpha = {outputSupportsAlpha} - " +
|
||||
$"input ext: {ext} => alpha = {alpha}", true);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Flowframes.IO;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
@@ -17,14 +16,16 @@ namespace Flowframes.Data
|
||||
public string name;
|
||||
public string desc;
|
||||
public string dir;
|
||||
public bool supportsAlpha;
|
||||
public bool isDefault;
|
||||
|
||||
public ModelInfo(AI ai, string name, string desc, string dir, bool isDefault)
|
||||
public ModelInfo(AI ai, string name, string desc, string dir, bool supportsAlpha, bool isDefault)
|
||||
{
|
||||
this.ai = ai;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.dir = dir;
|
||||
this.supportsAlpha = supportsAlpha;
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
@@ -49,9 +50,13 @@ namespace Flowframes.Data
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
bool alpha = false;
|
||||
bool.TryParse((string)item.supportsAlpha, out alpha);
|
||||
|
||||
bool def = false;
|
||||
bool.TryParse((string)item.isDefault, out def);
|
||||
models.Add(new ModelInfo(ai, (string)item.name, (string)item.desc, (string)item.dir, def));
|
||||
|
||||
models.Add(new ModelInfo(ai, (string)item.name, (string)item.desc, (string)item.dir, alpha, def));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,6 @@ namespace Flowframes.IO
|
||||
dedupThresh,
|
||||
delLogsOnStartup,
|
||||
dupeScanDebug,
|
||||
enableAlpha,
|
||||
enableLoop,
|
||||
exportNamePattern,
|
||||
exportNamePatternLoop,
|
||||
|
||||
@@ -157,17 +157,6 @@ namespace Flowframes
|
||||
File.Copy(frameFiles.First().FullName, loopFrameTargetPath, true);
|
||||
Logger.Log($"Copied loop frame to {loopFrameTargetPath}.", true);
|
||||
}
|
||||
|
||||
if (canceled) return;
|
||||
|
||||
if (current.alpha)
|
||||
{
|
||||
Program.mainForm.SetStatus("Extracting transparency...");
|
||||
Logger.Log("Extracting transparency... (1/2)");
|
||||
await FfmpegAlpha.ExtractAlphaDir(current.framesFolder, current.framesFolder + Paths.alphaSuffix);
|
||||
Logger.Log("Extracting transparency... (2/2)", false, true);
|
||||
await FfmpegAlpha.RemoveAlpha(current.framesFolder, current.framesFolder);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task RunAi(string outpath, AI ai, bool stepByStep = false)
|
||||
|
||||
@@ -265,12 +265,6 @@ namespace Flowframes.Main
|
||||
{
|
||||
AutoEncode.UpdateChunkAndBufferSizes();
|
||||
|
||||
if (current.alpha)
|
||||
{
|
||||
Logger.Log($"Not Using AutoEnc: Alpha mode is enabled.", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!current.outMode.ToString().ToLower().Contains("vid") || current.outMode.ToString().ToLower().Contains("gif"))
|
||||
{
|
||||
Logger.Log($"Not Using AutoEnc: Out Mode is not video ({current.outMode.ToString()})", true);
|
||||
|
||||
@@ -100,15 +100,6 @@ namespace Flowframes
|
||||
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
if (!Interpolate.canceled && Interpolate.current.alpha)
|
||||
{
|
||||
Logger.Log("Processing alpha...");
|
||||
string rgbInterpDir = Path.Combine(Interpolate.current.tempFolder, Paths.interpDir);
|
||||
string alphaInterpDir = Path.Combine(Interpolate.current.tempFolder, Paths.interpDir + Paths.alphaSuffix);
|
||||
if (!Directory.Exists(alphaInterpDir)) return;
|
||||
await FfmpegAlpha.MergeAlphaIntoRgb(rgbInterpDir, Padding.interpFrames, alphaInterpDir, Padding.interpFrames, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task RunRifeCuda(string framesPath, float interpFactor, string mdl)
|
||||
@@ -128,13 +119,6 @@ namespace Flowframes
|
||||
}
|
||||
|
||||
await RunRifeCudaProcess(framesPath, Paths.interpDir, script, interpFactor, mdl);
|
||||
|
||||
if (!Interpolate.canceled && Interpolate.current.alpha)
|
||||
{
|
||||
InterpolationProgress.progressPaused = true;
|
||||
Logger.Log("Interpolating alpha channel...");
|
||||
await RunRifeCudaProcess(framesPath + Paths.alphaSuffix, Paths.interpDir + Paths.alphaSuffix, script, interpFactor, mdl);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -197,13 +181,6 @@ namespace Flowframes
|
||||
}
|
||||
|
||||
await RunFlavrCudaProcess(framesPath, Paths.interpDir, script, interpFactor, mdl);
|
||||
|
||||
if (!Interpolate.canceled && Interpolate.current.alpha)
|
||||
{
|
||||
InterpolationProgress.progressPaused = true;
|
||||
Logger.Log("Interpolating alpha channel...");
|
||||
await RunFlavrCudaProcess(framesPath + Paths.alphaSuffix, Paths.interpDir + Paths.alphaSuffix, script, interpFactor, mdl);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -253,13 +230,6 @@ namespace Flowframes
|
||||
Logger.Log($"Running RIFE (NCNN){(await InterpolateUtils.UseUhd() ? " (UHD Mode)" : "")}...", false);
|
||||
|
||||
await RunRifeNcnnMulti(framesPath, outPath, factor, mdl);
|
||||
|
||||
if (!Interpolate.canceled && Interpolate.current.alpha)
|
||||
{
|
||||
InterpolationProgress.progressPaused = true;
|
||||
Logger.Log("Interpolating alpha channel...");
|
||||
await RunRifeNcnnMulti(framesPath + Paths.alphaSuffix, outPath + Paths.alphaSuffix, factor, mdl);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -340,13 +310,6 @@ namespace Flowframes
|
||||
try
|
||||
{
|
||||
await RunDainNcnnProcess(framesPath, outPath, factor, mdl, tilesize);
|
||||
|
||||
if (!Interpolate.canceled && Interpolate.current.alpha)
|
||||
{
|
||||
InterpolationProgress.progressPaused = true;
|
||||
Logger.Log("Interpolating alpha channel...");
|
||||
await RunDainNcnnProcess(framesPath + Paths.alphaSuffix, outPath + Paths.alphaSuffix, factor, mdl, tilesize);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user