mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-23 03:39:26 +01:00
Alpha support for GIFs/PNGs (no ncnn support atm)
This commit is contained in:
@@ -25,41 +25,40 @@ namespace Flowframes
|
||||
public static async Task ExtractSceneChanges(string inputFile, string frameFolderPath, float rate)
|
||||
{
|
||||
Logger.Log("Extracting scene changes...");
|
||||
await VideoToFrames(inputFile, frameFolderPath, rate, false, false, new Size(320, 180), false, true);
|
||||
await VideoToFrames(inputFile, frameFolderPath, false, rate, false, false, new Size(320, 180), false, true);
|
||||
bool hiddenLog = Interpolate.currentInputFrameCount <= 50;
|
||||
int amount = IOUtils.GetAmountOfFiles(frameFolderPath, false);
|
||||
Logger.Log($"Detected {amount} scene {(amount == 1 ? "change" : "changes")}.".Replace(" 0 ", " no "), false, !hiddenLog);
|
||||
}
|
||||
|
||||
public static async Task VideoToFrames(string inputFile, string frameFolderPath, float rate, bool deDupe, bool delSrc, bool timecodes = true)
|
||||
public static async Task VideoToFrames(string inputFile, string framesDir, bool alpha, float rate, bool deDupe, bool delSrc, bool timecodes = true)
|
||||
{
|
||||
await VideoToFrames(inputFile, frameFolderPath, rate, deDupe, delSrc, new Size(), timecodes);
|
||||
await VideoToFrames(inputFile, framesDir, alpha, rate, deDupe, delSrc, new Size(), timecodes);
|
||||
}
|
||||
|
||||
public static async Task VideoToFrames(string inputFile, string frameFolderPath, float rate, bool deDupe, bool delSrc, Size size, bool timecodes, bool sceneDetect = false)
|
||||
public static async Task VideoToFrames(string inputFile, string framesDir, bool alpha, float rate, bool deDupe, bool delSrc, Size size, bool timecodes, bool sceneDetect = false)
|
||||
{
|
||||
if (!sceneDetect) Logger.Log("Extracting video frames from input video...");
|
||||
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";
|
||||
IOUtils.CreateDir(frameFolderPath);
|
||||
IOUtils.CreateDir(framesDir);
|
||||
string timecodeStr = timecodes ? $"-copyts -r {FrameOrder.timebase} -frame_pts true" : "-copyts -frame_pts true";
|
||||
string scnDetect = sceneDetect ? $"\"select='gt(scene,{Config.GetFloatString("scnDetectValue")})'\"" : "";
|
||||
string mpStr = deDupe ? ((Config.GetInt("mpdecimateMode") == 0) ? mpDecDef : mpDecAggr) : "";
|
||||
string filters = FormatUtils.ConcatStrings(new string[] { scnDetect, mpStr } );
|
||||
string vf = filters.Length > 2 ? $"-vf {filters}" : "";
|
||||
string rateArg = (rate > 0) ? $" -r {rate.ToStringDot()}" : "";
|
||||
bool enableAlpha = (Config.GetBool("enableAlpha", true) && (Path.GetExtension(inputFile).ToLower() == ".gif"));
|
||||
string pixFmt = enableAlpha ? "-pix_fmt rgba" : "-pix_fmt rgb24"; // Use RGBA for GIF for alpha support
|
||||
string args = $"{rateArg} -i {inputFile.Wrap()} {pngComprArg} -vsync 0 {pixFmt} {timecodeStr} {vf} {sizeStr} \"{frameFolderPath}/%{Padding.inputFrames}d.png\"";
|
||||
string pixFmt = alpha ? "-pix_fmt rgba" : "-pix_fmt rgb24"; // Use RGBA for GIF for alpha support
|
||||
string args = $"{rateArg} -i {inputFile.Wrap()} {pngComprArg} -vsync 0 {pixFmt} {timecodeStr} {vf} {sizeStr} \"{framesDir}/%{Padding.inputFrames}d.png\"";
|
||||
AvProcess.LogMode logMode = Interpolate.currentInputFrameCount > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden;
|
||||
await AvProcess.RunFfmpeg(args, logMode, AvProcess.TaskType.ExtractFrames);
|
||||
int amount = IOUtils.GetAmountOfFiles(frameFolderPath, false, "*.png");
|
||||
int amount = IOUtils.GetAmountOfFiles(framesDir, false, "*.png");
|
||||
if (!sceneDetect) Logger.Log($"Extracted {amount} {(amount == 1 ? "frame" : "frames")} from input.", false, true);
|
||||
await Task.Delay(1);
|
||||
if (delSrc)
|
||||
DeleteSource(inputFile);
|
||||
}
|
||||
|
||||
public static async Task ImportImages(string inpath, string outpath, Size size, bool delSrc = false, bool showLog = true)
|
||||
public static async Task ImportImages(string inpath, string outpath, bool alpha, Size size, bool delSrc = false, bool showLog = true)
|
||||
{
|
||||
if (showLog) Logger.Log("Importing images...");
|
||||
Logger.Log($"Importing images from {inpath} to {outpath}.");
|
||||
@@ -72,8 +71,7 @@ namespace Flowframes
|
||||
File.WriteAllText(concatFile, concatFileContent);
|
||||
|
||||
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";
|
||||
bool enableAlpha = (Config.GetBool("enableAlpha", true) && Path.GetExtension(files.First()).ToLower() == ".gif");
|
||||
string pixFmt = enableAlpha ? "-pix_fmt rgba" : "-pix_fmt rgb24"; // Use RGBA for GIF for alpha support
|
||||
string pixFmt = alpha ? "-pix_fmt rgba" : "-pix_fmt rgb24"; // Use RGBA for GIF for alpha support
|
||||
string args = $" -loglevel panic -f concat -safe 0 -i {concatFile.Wrap()} {pngComprArg} {sizeStr} {pixFmt} -vsync 0 -vf {divisionFilter} \"{outpath}/%{Padding.inputFrames}d.png\"";
|
||||
AvProcess.LogMode logMode = IOUtils.GetAmountOfFiles(inpath, false) > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden;
|
||||
await AvProcess.RunFfmpeg(args, logMode, AvProcess.TaskType.ExtractFrames);
|
||||
@@ -154,6 +152,13 @@ namespace Flowframes
|
||||
await AvProcess.RunFfmpeg(args, framesFile.GetParentDir(), AvProcess.LogMode.OnlyLastLine, AvProcess.TaskType.Encode);
|
||||
}
|
||||
|
||||
public static async Task MergeAlphaIntoRgb (string rgbDir, int rgbPad, string alphaDir, int aPad)
|
||||
{
|
||||
string filter = "-filter_complex [0:v:0][1:v:0]alphamerge[out] -map [out]";
|
||||
string args = $"-i \"{rgbDir}/%{rgbPad}d.png\" -i \"{alphaDir}/%{aPad}d.png\" {filter} \"{rgbDir}/%{rgbPad}d.png\"";
|
||||
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden);
|
||||
}
|
||||
|
||||
public static async Task LoopVideo(string inputFile, int times, bool delSrc = false)
|
||||
{
|
||||
string pathNoExt = Path.ChangeExtension(inputFile, null);
|
||||
@@ -164,18 +169,6 @@ namespace Flowframes
|
||||
DeleteSource(inputFile);
|
||||
}
|
||||
|
||||
public static async Task LoopVideoEnc(string inputFile, int times, bool useH265, int crf, bool delSrc = false)
|
||||
{
|
||||
string pathNoExt = Path.ChangeExtension(inputFile, null);
|
||||
string ext = Path.GetExtension(inputFile);
|
||||
string enc = "libx264";
|
||||
if (useH265) enc = "libx265";
|
||||
string args = " -stream_loop " + times + " -i \"" + inputFile + "\" -c:v " + enc + " -crf " + crf + " -c:a copy \"" + pathNoExt + "-" + times + "xLoop" + ext + "\"";
|
||||
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine);
|
||||
if (delSrc)
|
||||
DeleteSource(inputFile);
|
||||
}
|
||||
|
||||
public static async Task ChangeSpeed(string inputFile, float newSpeedPercent, bool delSrc = false)
|
||||
{
|
||||
string pathNoExt = Path.ChangeExtension(inputFile, null);
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace Flowframes
|
||||
public Size inputResolution;
|
||||
public Size scaledResolution;
|
||||
|
||||
public bool alpha;
|
||||
|
||||
public InterpSettings(string inPathArg, string outPathArg, AI aiArg, float inFpsArg, int interpFactorArg, Interpolate.OutMode outModeArg, string modelArg)
|
||||
{
|
||||
inPath = inPathArg;
|
||||
@@ -41,6 +43,8 @@ namespace Flowframes
|
||||
outMode = outModeArg;
|
||||
model = modelArg;
|
||||
|
||||
alpha = false;
|
||||
|
||||
try
|
||||
{
|
||||
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
|
||||
|
||||
203
Code/Forms/SettingsForm.Designer.cs
generated
203
Code/Forms/SettingsForm.Designer.cs
generated
@@ -54,9 +54,10 @@
|
||||
this.delLogsOnStartup = new System.Windows.Forms.CheckBox();
|
||||
this.label11 = new System.Windows.Forms.Label();
|
||||
this.tabListPage2 = new Cyotek.Windows.Forms.TabListPage();
|
||||
this.keepSubs = new System.Windows.Forms.CheckBox();
|
||||
this.scnDetectValue = new System.Windows.Forms.NumericUpDown();
|
||||
this.sbsAllowAutoEnc = new System.Windows.Forms.CheckBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.dedupeSensLabel = new System.Windows.Forms.Label();
|
||||
this.label53 = new System.Windows.Forms.Label();
|
||||
this.autoEncMode = new System.Windows.Forms.ComboBox();
|
||||
this.label49 = new System.Windows.Forms.Label();
|
||||
@@ -78,6 +79,7 @@
|
||||
this.keepAudio = new System.Windows.Forms.CheckBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.aiOptsPage = new Cyotek.Windows.Forms.TabListPage();
|
||||
this.ncnnThreads = new System.Windows.Forms.NumericUpDown();
|
||||
this.label30 = new System.Windows.Forms.Label();
|
||||
this.panel6 = new System.Windows.Forms.Panel();
|
||||
this.uhdThresh = new System.Windows.Forms.ComboBox();
|
||||
@@ -93,6 +95,7 @@
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.label32 = new System.Windows.Forms.Label();
|
||||
this.vidExportTab = new Cyotek.Windows.Forms.TabListPage();
|
||||
this.minOutVidLength = new System.Windows.Forms.NumericUpDown();
|
||||
this.aviColors = new System.Windows.Forms.ComboBox();
|
||||
this.aviCodec = new System.Windows.Forms.ComboBox();
|
||||
this.label60 = new System.Windows.Forms.Label();
|
||||
@@ -150,9 +153,9 @@
|
||||
this.cmdDebugMode = new System.Windows.Forms.ComboBox();
|
||||
this.titleLabel = new System.Windows.Forms.Label();
|
||||
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
||||
this.ncnnThreads = new System.Windows.Forms.NumericUpDown();
|
||||
this.minOutVidLength = new System.Windows.Forms.NumericUpDown();
|
||||
this.keepSubs = new System.Windows.Forms.CheckBox();
|
||||
this.label25 = new System.Windows.Forms.Label();
|
||||
this.enableAlpha = new System.Windows.Forms.CheckBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.settingsTabList.SuspendLayout();
|
||||
this.generalTab.SuspendLayout();
|
||||
this.tabListPage2.SuspendLayout();
|
||||
@@ -161,10 +164,10 @@
|
||||
this.magickDedupePanel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dedupThresh)).BeginInit();
|
||||
this.aiOptsPage.SuspendLayout();
|
||||
this.vidExportTab.SuspendLayout();
|
||||
this.debugTab.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ncnnThreads)).BeginInit();
|
||||
this.vidExportTab.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.minOutVidLength)).BeginInit();
|
||||
this.debugTab.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// settingsTabList
|
||||
@@ -327,7 +330,7 @@
|
||||
this.tempDirCustom.Location = new System.Drawing.Point(486, 67);
|
||||
this.tempDirCustom.MinimumSize = new System.Drawing.Size(4, 21);
|
||||
this.tempDirCustom.Name = "tempDirCustom";
|
||||
this.tempDirCustom.Size = new System.Drawing.Size(212, 20);
|
||||
this.tempDirCustom.Size = new System.Drawing.Size(212, 21);
|
||||
this.tempDirCustom.TabIndex = 69;
|
||||
//
|
||||
// keepTempFolder
|
||||
@@ -451,10 +454,13 @@
|
||||
// tabListPage2
|
||||
//
|
||||
this.tabListPage2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
|
||||
this.tabListPage2.Controls.Add(this.label4);
|
||||
this.tabListPage2.Controls.Add(this.enableAlpha);
|
||||
this.tabListPage2.Controls.Add(this.label25);
|
||||
this.tabListPage2.Controls.Add(this.keepSubs);
|
||||
this.tabListPage2.Controls.Add(this.scnDetectValue);
|
||||
this.tabListPage2.Controls.Add(this.sbsAllowAutoEnc);
|
||||
this.tabListPage2.Controls.Add(this.label4);
|
||||
this.tabListPage2.Controls.Add(this.dedupeSensLabel);
|
||||
this.tabListPage2.Controls.Add(this.label53);
|
||||
this.tabListPage2.Controls.Add(this.autoEncMode);
|
||||
this.tabListPage2.Controls.Add(this.label49);
|
||||
@@ -476,6 +482,16 @@
|
||||
this.tabListPage2.Size = new System.Drawing.Size(762, 419);
|
||||
this.tabListPage2.Text = "Interpolation";
|
||||
//
|
||||
// keepSubs
|
||||
//
|
||||
this.keepSubs.AutoSize = true;
|
||||
this.keepSubs.Location = new System.Drawing.Point(367, 39);
|
||||
this.keepSubs.Name = "keepSubs";
|
||||
this.keepSubs.Size = new System.Drawing.Size(94, 17);
|
||||
this.keepSubs.TabIndex = 75;
|
||||
this.keepSubs.Text = "Keep Subtitles";
|
||||
this.keepSubs.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// scnDetectValue
|
||||
//
|
||||
this.scnDetectValue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
@@ -486,7 +502,7 @@
|
||||
0,
|
||||
0,
|
||||
131072});
|
||||
this.scnDetectValue.Location = new System.Drawing.Point(364, 128);
|
||||
this.scnDetectValue.Location = new System.Drawing.Point(364, 158);
|
||||
this.scnDetectValue.Maximum = new decimal(new int[] {
|
||||
5,
|
||||
0,
|
||||
@@ -509,26 +525,26 @@
|
||||
// sbsAllowAutoEnc
|
||||
//
|
||||
this.sbsAllowAutoEnc.AutoSize = true;
|
||||
this.sbsAllowAutoEnc.Location = new System.Drawing.Point(280, 190);
|
||||
this.sbsAllowAutoEnc.Location = new System.Drawing.Point(280, 220);
|
||||
this.sbsAllowAutoEnc.Name = "sbsAllowAutoEnc";
|
||||
this.sbsAllowAutoEnc.Size = new System.Drawing.Size(15, 14);
|
||||
this.sbsAllowAutoEnc.TabIndex = 72;
|
||||
this.sbsAllowAutoEnc.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label4
|
||||
// dedupeSensLabel
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(536, 71);
|
||||
this.label4.Margin = new System.Windows.Forms.Padding(3);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(57, 13);
|
||||
this.label4.TabIndex = 29;
|
||||
this.label4.Text = "Sensitivity:";
|
||||
this.dedupeSensLabel.AutoSize = true;
|
||||
this.dedupeSensLabel.Location = new System.Drawing.Point(536, 101);
|
||||
this.dedupeSensLabel.Margin = new System.Windows.Forms.Padding(3);
|
||||
this.dedupeSensLabel.Name = "dedupeSensLabel";
|
||||
this.dedupeSensLabel.Size = new System.Drawing.Size(57, 13);
|
||||
this.dedupeSensLabel.TabIndex = 29;
|
||||
this.dedupeSensLabel.Text = "Sensitivity:";
|
||||
//
|
||||
// label53
|
||||
//
|
||||
this.label53.AutoSize = true;
|
||||
this.label53.Location = new System.Drawing.Point(10, 190);
|
||||
this.label53.Location = new System.Drawing.Point(10, 220);
|
||||
this.label53.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label53.Name = "label53";
|
||||
this.label53.Size = new System.Drawing.Size(203, 13);
|
||||
@@ -546,7 +562,7 @@
|
||||
"Disabled",
|
||||
"Enabled (Keep Interpolated Frames)",
|
||||
"Enabled (Delete Frames Once Encoded)"});
|
||||
this.autoEncMode.Location = new System.Drawing.Point(280, 157);
|
||||
this.autoEncMode.Location = new System.Drawing.Point(280, 187);
|
||||
this.autoEncMode.Name = "autoEncMode";
|
||||
this.autoEncMode.Size = new System.Drawing.Size(250, 21);
|
||||
this.autoEncMode.TabIndex = 70;
|
||||
@@ -554,7 +570,7 @@
|
||||
// label49
|
||||
//
|
||||
this.label49.AutoSize = true;
|
||||
this.label49.Location = new System.Drawing.Point(10, 160);
|
||||
this.label49.Location = new System.Drawing.Point(10, 190);
|
||||
this.label49.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label49.Name = "label49";
|
||||
this.label49.Size = new System.Drawing.Size(206, 13);
|
||||
@@ -565,7 +581,7 @@
|
||||
//
|
||||
this.panel14.BackgroundImage = global::Flowframes.Properties.Resources.baseline_create_white_18dp_semiTransparent;
|
||||
this.panel14.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.panel14.Location = new System.Drawing.Point(475, 127);
|
||||
this.panel14.Location = new System.Drawing.Point(475, 157);
|
||||
this.panel14.Name = "panel14";
|
||||
this.panel14.Size = new System.Drawing.Size(21, 21);
|
||||
this.panel14.TabIndex = 68;
|
||||
@@ -575,7 +591,7 @@
|
||||
//
|
||||
this.label52.AutoSize = true;
|
||||
this.label52.ForeColor = System.Drawing.Color.Silver;
|
||||
this.label52.Location = new System.Drawing.Point(509, 132);
|
||||
this.label52.Location = new System.Drawing.Point(509, 162);
|
||||
this.label52.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label52.Name = "label52";
|
||||
this.label52.Size = new System.Drawing.Size(225, 13);
|
||||
@@ -585,7 +601,7 @@
|
||||
// label51
|
||||
//
|
||||
this.label51.AutoSize = true;
|
||||
this.label51.Location = new System.Drawing.Point(301, 131);
|
||||
this.label51.Location = new System.Drawing.Point(301, 161);
|
||||
this.label51.Margin = new System.Windows.Forms.Padding(3);
|
||||
this.label51.Name = "label51";
|
||||
this.label51.Size = new System.Drawing.Size(57, 13);
|
||||
@@ -595,7 +611,7 @@
|
||||
// scnDetect
|
||||
//
|
||||
this.scnDetect.AutoSize = true;
|
||||
this.scnDetect.Location = new System.Drawing.Point(280, 130);
|
||||
this.scnDetect.Location = new System.Drawing.Point(280, 160);
|
||||
this.scnDetect.Name = "scnDetect";
|
||||
this.scnDetect.Size = new System.Drawing.Size(15, 14);
|
||||
this.scnDetect.TabIndex = 64;
|
||||
@@ -604,7 +620,7 @@
|
||||
// label50
|
||||
//
|
||||
this.label50.AutoSize = true;
|
||||
this.label50.Location = new System.Drawing.Point(10, 130);
|
||||
this.label50.Location = new System.Drawing.Point(10, 160);
|
||||
this.label50.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label50.Name = "label50";
|
||||
this.label50.Size = new System.Drawing.Size(194, 13);
|
||||
@@ -614,7 +630,7 @@
|
||||
// mpDedupePanel
|
||||
//
|
||||
this.mpDedupePanel.Controls.Add(this.mpdecimateMode);
|
||||
this.mpDedupePanel.Location = new System.Drawing.Point(599, 67);
|
||||
this.mpDedupePanel.Location = new System.Drawing.Point(599, 97);
|
||||
this.mpDedupePanel.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.mpDedupePanel.Name = "mpDedupePanel";
|
||||
this.mpDedupePanel.Size = new System.Drawing.Size(135, 21);
|
||||
@@ -640,7 +656,7 @@
|
||||
//
|
||||
this.magickDedupePanel.Controls.Add(this.dedupThresh);
|
||||
this.magickDedupePanel.Controls.Add(this.panel3);
|
||||
this.magickDedupePanel.Location = new System.Drawing.Point(599, 67);
|
||||
this.magickDedupePanel.Location = new System.Drawing.Point(599, 97);
|
||||
this.magickDedupePanel.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.magickDedupePanel.Name = "magickDedupePanel";
|
||||
this.magickDedupePanel.Size = new System.Drawing.Size(135, 21);
|
||||
@@ -701,7 +717,7 @@
|
||||
// enableLoop
|
||||
//
|
||||
this.enableLoop.AutoSize = true;
|
||||
this.enableLoop.Location = new System.Drawing.Point(280, 100);
|
||||
this.enableLoop.Location = new System.Drawing.Point(280, 130);
|
||||
this.enableLoop.Name = "enableLoop";
|
||||
this.enableLoop.Size = new System.Drawing.Size(15, 14);
|
||||
this.enableLoop.TabIndex = 31;
|
||||
@@ -710,7 +726,7 @@
|
||||
// label15
|
||||
//
|
||||
this.label15.AutoSize = true;
|
||||
this.label15.Location = new System.Drawing.Point(10, 100);
|
||||
this.label15.Location = new System.Drawing.Point(10, 130);
|
||||
this.label15.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label15.Name = "label15";
|
||||
this.label15.Size = new System.Drawing.Size(217, 13);
|
||||
@@ -728,7 +744,7 @@
|
||||
"Disabled",
|
||||
"1: After Extraction - Slow, Accurate",
|
||||
"2: During Extraction - Fast, Less Accurate"});
|
||||
this.dedupMode.Location = new System.Drawing.Point(280, 67);
|
||||
this.dedupMode.Location = new System.Drawing.Point(280, 97);
|
||||
this.dedupMode.Name = "dedupMode";
|
||||
this.dedupMode.Size = new System.Drawing.Size(250, 21);
|
||||
this.dedupMode.TabIndex = 27;
|
||||
@@ -737,7 +753,7 @@
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(10, 70);
|
||||
this.label2.Location = new System.Drawing.Point(10, 100);
|
||||
this.label2.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(139, 13);
|
||||
@@ -786,6 +802,30 @@
|
||||
this.aiOptsPage.Size = new System.Drawing.Size(762, 419);
|
||||
this.aiOptsPage.Text = "AI Specific Settings";
|
||||
//
|
||||
// ncnnThreads
|
||||
//
|
||||
this.ncnnThreads.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.ncnnThreads.ForeColor = System.Drawing.Color.White;
|
||||
this.ncnnThreads.Location = new System.Drawing.Point(280, 98);
|
||||
this.ncnnThreads.Maximum = new decimal(new int[] {
|
||||
4,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.ncnnThreads.Minimum = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.ncnnThreads.Name = "ncnnThreads";
|
||||
this.ncnnThreads.Size = new System.Drawing.Size(77, 20);
|
||||
this.ncnnThreads.TabIndex = 75;
|
||||
this.ncnnThreads.Value = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// label30
|
||||
//
|
||||
this.label30.AutoSize = true;
|
||||
@@ -991,6 +1031,25 @@
|
||||
this.vidExportTab.Size = new System.Drawing.Size(762, 419);
|
||||
this.vidExportTab.Text = "Video Export";
|
||||
//
|
||||
// minOutVidLength
|
||||
//
|
||||
this.minOutVidLength.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.minOutVidLength.ForeColor = System.Drawing.Color.White;
|
||||
this.minOutVidLength.Location = new System.Drawing.Point(280, 37);
|
||||
this.minOutVidLength.Maximum = new decimal(new int[] {
|
||||
60,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.minOutVidLength.Name = "minOutVidLength";
|
||||
this.minOutVidLength.Size = new System.Drawing.Size(100, 20);
|
||||
this.minOutVidLength.TabIndex = 75;
|
||||
this.minOutVidLength.Value = new decimal(new int[] {
|
||||
5,
|
||||
0,
|
||||
0,
|
||||
131072});
|
||||
//
|
||||
// aviColors
|
||||
//
|
||||
this.aviColors.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
@@ -1682,58 +1741,35 @@
|
||||
this.titleLabel.TabIndex = 1;
|
||||
this.titleLabel.Text = "Settings";
|
||||
//
|
||||
// ncnnThreads
|
||||
// label25
|
||||
//
|
||||
this.ncnnThreads.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.ncnnThreads.ForeColor = System.Drawing.Color.White;
|
||||
this.ncnnThreads.Location = new System.Drawing.Point(280, 98);
|
||||
this.ncnnThreads.Maximum = new decimal(new int[] {
|
||||
4,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.ncnnThreads.Minimum = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.ncnnThreads.Name = "ncnnThreads";
|
||||
this.ncnnThreads.Size = new System.Drawing.Size(77, 20);
|
||||
this.ncnnThreads.TabIndex = 75;
|
||||
this.ncnnThreads.Value = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.label25.AutoSize = true;
|
||||
this.label25.Location = new System.Drawing.Point(10, 70);
|
||||
this.label25.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label25.Name = "label25";
|
||||
this.label25.Size = new System.Drawing.Size(108, 13);
|
||||
this.label25.TabIndex = 76;
|
||||
this.label25.Text = "Enable Transparency";
|
||||
//
|
||||
// minOutVidLength
|
||||
// enableAlpha
|
||||
//
|
||||
this.minOutVidLength.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.minOutVidLength.ForeColor = System.Drawing.Color.White;
|
||||
this.minOutVidLength.Location = new System.Drawing.Point(280, 37);
|
||||
this.minOutVidLength.Maximum = new decimal(new int[] {
|
||||
60,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.minOutVidLength.Name = "minOutVidLength";
|
||||
this.minOutVidLength.Size = new System.Drawing.Size(100, 20);
|
||||
this.minOutVidLength.TabIndex = 75;
|
||||
this.minOutVidLength.Value = new decimal(new int[] {
|
||||
5,
|
||||
0,
|
||||
0,
|
||||
131072});
|
||||
this.enableAlpha.AutoSize = true;
|
||||
this.enableAlpha.Location = new System.Drawing.Point(280, 70);
|
||||
this.enableAlpha.Name = "enableAlpha";
|
||||
this.enableAlpha.Size = new System.Drawing.Size(15, 14);
|
||||
this.enableAlpha.TabIndex = 77;
|
||||
this.enableAlpha.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// keepSubs
|
||||
// label4
|
||||
//
|
||||
this.keepSubs.AutoSize = true;
|
||||
this.keepSubs.Location = new System.Drawing.Point(367, 39);
|
||||
this.keepSubs.Name = "keepSubs";
|
||||
this.keepSubs.Size = new System.Drawing.Size(94, 17);
|
||||
this.keepSubs.TabIndex = 75;
|
||||
this.keepSubs.Text = "Keep Subtitles";
|
||||
this.keepSubs.UseVisualStyleBackColor = true;
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.ForeColor = System.Drawing.Color.Silver;
|
||||
this.label4.Location = new System.Drawing.Point(308, 70);
|
||||
this.label4.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(300, 13);
|
||||
this.label4.TabIndex = 78;
|
||||
this.label4.Text = "Enables Transparency (Alpha) support for GIFs and PNG input";
|
||||
//
|
||||
// SettingsForm
|
||||
//
|
||||
@@ -1762,12 +1798,12 @@
|
||||
((System.ComponentModel.ISupportInitialize)(this.dedupThresh)).EndInit();
|
||||
this.aiOptsPage.ResumeLayout(false);
|
||||
this.aiOptsPage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ncnnThreads)).EndInit();
|
||||
this.vidExportTab.ResumeLayout(false);
|
||||
this.vidExportTab.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.minOutVidLength)).EndInit();
|
||||
this.debugTab.ResumeLayout(false);
|
||||
this.debugTab.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ncnnThreads)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.minOutVidLength)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@@ -1788,7 +1824,7 @@
|
||||
private System.Windows.Forms.ComboBox dedupMode;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.ComboBox cmdDebugMode;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.Label dedupeSensLabel;
|
||||
private System.Windows.Forms.CheckBox enableLoop;
|
||||
private System.Windows.Forms.Label label15;
|
||||
private Cyotek.Windows.Forms.TabListPage vidExportTab;
|
||||
@@ -1898,5 +1934,8 @@
|
||||
private System.Windows.Forms.NumericUpDown ncnnThreads;
|
||||
private System.Windows.Forms.NumericUpDown minOutVidLength;
|
||||
private System.Windows.Forms.CheckBox keepSubs;
|
||||
private System.Windows.Forms.CheckBox enableAlpha;
|
||||
private System.Windows.Forms.Label label25;
|
||||
private System.Windows.Forms.Label label4;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ namespace Flowframes.Forms
|
||||
// General
|
||||
ConfigParser.SaveComboxIndex(processingMode);
|
||||
ConfigParser.SaveGuiElement(maxVidHeight);
|
||||
ConfigParser.SaveGuiElement(enableAlpha);
|
||||
ConfigParser.SaveComboxIndex(tempFolderLoc);
|
||||
ConfigParser.SaveGuiElement(keepTempFolder);
|
||||
ConfigParser.SaveGuiElement(delLogsOnStartup);
|
||||
@@ -112,6 +113,7 @@ namespace Flowframes.Forms
|
||||
// General
|
||||
ConfigParser.LoadComboxIndex(processingMode);
|
||||
ConfigParser.LoadGuiElement(maxVidHeight);
|
||||
ConfigParser.LoadGuiElement(enableAlpha);
|
||||
ConfigParser.LoadComboxIndex(tempFolderLoc); ConfigParser.LoadGuiElement(tempDirCustom);
|
||||
ConfigParser.LoadGuiElement(delLogsOnStartup);
|
||||
ConfigParser.LoadGuiElement(keepTempFolder);
|
||||
@@ -180,6 +182,7 @@ namespace Flowframes.Forms
|
||||
|
||||
private void dedupMode_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
dedupeSensLabel.Visible = dedupMode.SelectedIndex != 0;
|
||||
magickDedupePanel.Visible = dedupMode.SelectedIndex == 1;
|
||||
mpDedupePanel.Visible = dedupMode.SelectedIndex == 2;
|
||||
}
|
||||
|
||||
@@ -42,24 +42,20 @@ namespace Flowframes.Magick
|
||||
{
|
||||
|
||||
var files = IOUtils.GetFilesSorted(inputDir);
|
||||
if (print) Logger.Log($"Extracting alpha channel from {files.Length} files in {inputDir}");
|
||||
if (print) Logger.Log($"Extracting alpha channel from images...");
|
||||
Directory.CreateDirectory(outputDir);
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Restart();
|
||||
int counter = 0;
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (print) Logger.Log($"Extracting alpha from {Path.GetFileName(file)}", false, true);
|
||||
MagickImage img = new MagickImage(file);
|
||||
img.Format = MagickFormat.Png32;
|
||||
img.Quality = 10;
|
||||
|
||||
// Fill the image with a transparent background
|
||||
img.FloodFill(MagickColors.None, 0, 0);
|
||||
// Change all the pixels that are not transparent to white.
|
||||
img.InverseOpaque(MagickColors.None, MagickColors.White);
|
||||
// Change the transparent pixels to black.
|
||||
//img.ColorAlpha(MagickColors.Black);
|
||||
img.FloodFill(MagickColors.None, 0, 0); // Fill the image with a transparent background
|
||||
img.InverseOpaque(MagickColors.None, MagickColors.White); // Change all the pixels that are not transparent to white.
|
||||
img.ColorAlpha(MagickColors.Black); // Change the transparent pixels to black.
|
||||
|
||||
string outPath = Path.Combine(outputDir, Path.GetFileName(file));
|
||||
img.Write(outPath);
|
||||
|
||||
@@ -43,13 +43,7 @@ namespace Flowframes
|
||||
currentInputFrameCount = await Utils.GetInputFrameCountAsync(current.inPath);
|
||||
Program.mainForm.SetStatus("Starting...");
|
||||
Program.mainForm.SetWorking(true);
|
||||
|
||||
if (!current.inputIsFrames) // Input is video - extract frames first
|
||||
await ExtractFrames(current.inPath, current.framesFolder);
|
||||
else
|
||||
await FFmpegCommands.ImportImages(current.inPath, current.framesFolder, await Utils.GetOutputResolution(current.inPath, true));
|
||||
|
||||
await Converter.ExtractAlpha(current.framesFolder, current.framesFolder + "-a");
|
||||
await GetFrames();
|
||||
if (canceled) return;
|
||||
sw.Restart();
|
||||
await PostProcessFrames();
|
||||
@@ -67,7 +61,21 @@ namespace Flowframes
|
||||
Program.mainForm.SetStatus("Done interpolating!");
|
||||
}
|
||||
|
||||
public static async Task ExtractFrames(string inPath, string outPath, bool allowSceneDetect = true, bool extractAudio = true)
|
||||
public static async Task GetFrames ()
|
||||
{
|
||||
if (!current.inputIsFrames) // Input is video - extract frames first
|
||||
{
|
||||
current.alpha = (Config.GetBool("enableAlpha", true) && (Path.GetExtension(current.inPath).ToLower() == ".gif"));
|
||||
await ExtractFrames(current.inPath, current.framesFolder, current.alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
current.alpha = (Config.GetBool("enableAlpha", true) && Path.GetExtension(IOUtils.GetFilesSorted(current.inPath).First()).ToLower() == ".gif");
|
||||
await FFmpegCommands.ImportImages(current.inPath, current.framesFolder, current.alpha, await Utils.GetOutputResolution(current.inPath, true));
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ExtractFrames(string inPath, string outPath, bool alpha, bool allowSceneDetect = true, bool extractAudio = true)
|
||||
{
|
||||
if (Config.GetBool("scnDetect"))
|
||||
{
|
||||
@@ -78,7 +86,7 @@ namespace Flowframes
|
||||
|
||||
Program.mainForm.SetStatus("Extracting frames from video...");
|
||||
bool mpdecimate = Config.GetInt("dedupMode") == 2;
|
||||
await FFmpegCommands.VideoToFrames(inPath, outPath, current.inFps, mpdecimate, false, await Utils.GetOutputResolution(inPath, true), false);
|
||||
await FFmpegCommands.VideoToFrames(inPath, outPath, alpha, current.inFps, mpdecimate, false, await Utils.GetOutputResolution(inPath, true), false);
|
||||
|
||||
if (mpdecimate)
|
||||
{
|
||||
@@ -126,6 +134,7 @@ namespace Flowframes
|
||||
|
||||
if (canceled) return;
|
||||
|
||||
await Converter.ExtractAlpha(current.framesFolder, current.framesFolder + "-a");
|
||||
await FrameOrder.CreateTimecodeFiles(current.framesFolder, FrameOrder.Mode.CFR, Config.GetBool("enableLoop"), current.interpFactor, false);
|
||||
|
||||
if (canceled) return;
|
||||
@@ -139,7 +148,7 @@ namespace Flowframes
|
||||
await ModelDownloader.DownloadModelFiles(Path.GetFileNameWithoutExtension(ai.pkg.fileName), current.model);
|
||||
if (canceled) return;
|
||||
|
||||
currentlyUsingAutoEnc = Utils.UseAutoEnc(stepByStep, current);
|
||||
currentlyUsingAutoEnc = Utils.CanUseAutoEnc(stepByStep, current);
|
||||
|
||||
IOUtils.CreateDir(outpath);
|
||||
|
||||
@@ -149,7 +158,7 @@ namespace Flowframes
|
||||
tasks.Add(AiProcess.RunRifeCuda(current.framesFolder, current.interpFactor, current.model));
|
||||
|
||||
if (ai.aiName == Networks.rifeNcnn.aiName)
|
||||
tasks.Add(AiProcess.RunRifeNcnnMulti(current.framesFolder, outpath, current.interpFactor, current.model));
|
||||
tasks.Add(AiProcess.RunRifeNcnn(current.framesFolder, outpath, current.interpFactor, current.model));
|
||||
|
||||
if (currentlyUsingAutoEnc)
|
||||
{
|
||||
|
||||
@@ -42,10 +42,7 @@ namespace Flowframes.Main
|
||||
|
||||
if (step.Contains("Extract Frames"))
|
||||
{
|
||||
if (!current.inputIsFrames) // Input is video - extract frames first
|
||||
await ExtractVideoFrames();
|
||||
else
|
||||
await FFmpegCommands.ImportImages(current.inPath, current.framesFolder, await InterpolateUtils.GetOutputResolution(current.inPath, true));
|
||||
await GetFrames();
|
||||
}
|
||||
|
||||
if (step.Contains("Run Interpolation"))
|
||||
|
||||
@@ -59,21 +59,26 @@ namespace Flowframes.Main
|
||||
}
|
||||
|
||||
public static int targetFrames;
|
||||
public static string currentOutdir;
|
||||
public static int currentFactor;
|
||||
public static bool progressPaused = false;
|
||||
public static bool progCheckRunning = false;
|
||||
public static async void GetProgressByFrameAmount(string outdir, int target)
|
||||
{
|
||||
Logger.Log($"Starting GetProgressByFrameAmount() loop for outdir '{outdir}', target is {target} frames", true);
|
||||
progCheckRunning = true;
|
||||
targetFrames = target;
|
||||
currentOutdir = outdir;
|
||||
Logger.Log($"Starting GetProgressByFrameAmount() loop for outdir '{currentOutdir}', target is {target} frames", true);
|
||||
bool firstProgUpd = true;
|
||||
Program.mainForm.SetProgress(0);
|
||||
targetFrames = target;
|
||||
while (Program.busy)
|
||||
{
|
||||
if (AiProcess.processTime.IsRunning && Directory.Exists(outdir))
|
||||
if (!progressPaused && AiProcess.processTime.IsRunning && Directory.Exists(currentOutdir))
|
||||
{
|
||||
if (firstProgUpd && Program.mainForm.IsInFocus())
|
||||
Program.mainForm.SetTab("preview");
|
||||
firstProgUpd = false;
|
||||
string[] frames = IOUtils.GetFilesSorted(outdir, $"*.{GetOutExt()}");
|
||||
string[] frames = IOUtils.GetFilesSorted(currentOutdir, $"*.{GetOutExt()}");
|
||||
if (frames.Length > 1)
|
||||
UpdateInterpProgress(frames.Length, targetFrames, frames[frames.Length - 1]);
|
||||
if (frames.Length >= targetFrames)
|
||||
@@ -85,6 +90,7 @@ namespace Flowframes.Main
|
||||
await Task.Delay(200);
|
||||
}
|
||||
}
|
||||
progCheckRunning = false;
|
||||
}
|
||||
|
||||
public static void UpdateInterpProgress(int frames, int target, string latestFramePath = "")
|
||||
@@ -361,11 +367,17 @@ namespace Flowframes.Main
|
||||
return (n - a > b - n) ? b : a; // Return of closest of two
|
||||
}
|
||||
|
||||
public static bool UseAutoEnc (bool stepByStep, InterpSettings current)
|
||||
public static bool CanUseAutoEnc (bool stepByStep, InterpSettings current)
|
||||
{
|
||||
AutoEncode.UpdateChunkAndBufferSizes();
|
||||
|
||||
if (!current.outMode.ToString().ToLower().Contains("vid"))
|
||||
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);
|
||||
return false;
|
||||
|
||||
@@ -28,18 +28,32 @@ namespace Flowframes
|
||||
|
||||
public static Dictionary<string, string> filenameMap = new Dictionary<string, string>(); // TODO: Store on disk instead for crashes?
|
||||
|
||||
static void AiStarted (Process proc, int startupTimeMs, int factor, string inPath = "")
|
||||
static void AiStarted (Process proc, int startupTimeMs, string inPath = "")
|
||||
{
|
||||
lastStartupTimeMs = startupTimeMs;
|
||||
processTime.Restart();
|
||||
currentAiProcess = proc;
|
||||
lastInPath = string.IsNullOrWhiteSpace(inPath) ? Interpolate.current.framesFolder : inPath;
|
||||
int frames = IOUtils.GetAmountOfFiles(lastInPath, false, "*.png");
|
||||
InterpolateUtils.currentFactor = factor;
|
||||
InterpolateUtils.targetFrames = (frames * factor) - (factor - 1);
|
||||
hasShownError = false;
|
||||
}
|
||||
|
||||
static void SetProgressCheck(string interpPath, int factor)
|
||||
{
|
||||
int frames = IOUtils.GetAmountOfFiles(lastInPath, false, "*.png");
|
||||
int target = (frames * factor) - (factor - 1);
|
||||
InterpolateUtils.progressPaused = false;
|
||||
|
||||
if (InterpolateUtils.progCheckRunning)
|
||||
{
|
||||
InterpolateUtils.currentFactor = factor;
|
||||
InterpolateUtils.targetFrames = target;
|
||||
}
|
||||
else
|
||||
{
|
||||
InterpolateUtils.GetProgressByFrameAmount(interpPath, target);
|
||||
}
|
||||
}
|
||||
|
||||
static async Task AiFinished (string aiName)
|
||||
{
|
||||
Program.mainForm.SetProgress(100);
|
||||
@@ -70,12 +84,8 @@ namespace Flowframes
|
||||
|
||||
public static async Task RunRifeCuda(string framesPath, int interpFactor, string mdl)
|
||||
{
|
||||
InterpolateUtils.GetProgressByFrameAmount(Interpolate.current.interpFolder, Interpolate.current.GetTargetFrameCount(framesPath, interpFactor));
|
||||
|
||||
string rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName));
|
||||
string script = "inference_video.py";
|
||||
string uhdStr = await InterpolateUtils.UseUHD() ? "--UHD" : "";
|
||||
string args = $" --input {framesPath.Wrap()} --model {mdl} --exp {(int)Math.Log(interpFactor, 2)} {uhdStr} --imgformat {InterpolateUtils.GetOutExt()} --output {Paths.interpDir}";
|
||||
|
||||
if (!File.Exists(Path.Combine(rifeDir, script)))
|
||||
{
|
||||
@@ -83,12 +93,38 @@ namespace Flowframes
|
||||
return;
|
||||
}
|
||||
|
||||
await RunRifeCudaProcess(framesPath, Paths.interpDir, script, interpFactor, mdl);
|
||||
|
||||
if (!Interpolate.canceled && Interpolate.current.alpha)
|
||||
{
|
||||
InterpolateUtils.progressPaused = true;
|
||||
Logger.Log("Interpolating alpha channel...");
|
||||
await RunRifeCudaProcess(framesPath + "-a", Paths.interpDir + "-a", script, interpFactor, mdl);
|
||||
}
|
||||
|
||||
await AiFinished("RIFE");
|
||||
|
||||
if (!Interpolate.canceled && Interpolate.current.alpha)
|
||||
{
|
||||
Logger.Log("Processing alpha...");
|
||||
string rgbInterpDir = Path.Combine(Interpolate.current.tempFolder, Paths.interpDir);
|
||||
await FFmpegCommands.MergeAlphaIntoRgb(rgbInterpDir, Padding.interpFrames, rgbInterpDir + "-a", Padding.interpFrames);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task RunRifeCudaProcess (string inPath, string outDir, string script, int interpFactor, string mdl)
|
||||
{
|
||||
string uhdStr = await InterpolateUtils.UseUHD() ? "--UHD" : "";
|
||||
string args = $" --input {inPath.Wrap()} --model {mdl} --exp {(int)Math.Log(interpFactor, 2)} {uhdStr} --imgformat {InterpolateUtils.GetOutExt()} --output {outDir}";
|
||||
|
||||
Process rifePy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
|
||||
AiStarted(rifePy, 3500, Interpolate.current.interpFactor);
|
||||
AiStarted(rifePy, 3500);
|
||||
SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor);
|
||||
rifePy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeCuda).Wrap()} & " +
|
||||
$"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Python.GetPyCmd()} {script} {args}";
|
||||
Logger.Log($"Running RIFE {(await InterpolateUtils.UseUHD() ? "(UHD Mode)" : "")} ({script})...".TrimWhitespaces(), false);
|
||||
Logger.Log("cmd.exe " + rifePy.StartInfo.Arguments, true);
|
||||
|
||||
if (!OSUtils.ShowHiddenCmd())
|
||||
{
|
||||
rifePy.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "rife-cuda-log"); };
|
||||
@@ -100,11 +136,11 @@ namespace Flowframes
|
||||
rifePy.BeginOutputReadLine();
|
||||
rifePy.BeginErrorReadLine();
|
||||
}
|
||||
|
||||
while (!rifePy.HasExited) await Task.Delay(1);
|
||||
AiFinished("RIFE");
|
||||
}
|
||||
|
||||
public static async Task RunRifeNcnnMulti(string framesPath, string outPath, int factor, string mdl)
|
||||
public static async Task RunRifeNcnn (string framesPath, string outPath, int factor, string mdl)
|
||||
{
|
||||
processTimeMulti.Restart();
|
||||
Logger.Log($"Running RIFE{(await InterpolateUtils.UseUHD() ? " (UHD Mode)" : "")}...", false);
|
||||
@@ -113,7 +149,7 @@ namespace Flowframes
|
||||
if(factor > 2)
|
||||
AutoEncode.paused = true; // Disable autoenc until the last iteration
|
||||
|
||||
await RunRifePartial(framesPath, outPath, mdl);
|
||||
await RunRifeNcnnProcess(framesPath, outPath, mdl);
|
||||
|
||||
if (factor == 4 || factor == 8) // #2
|
||||
{
|
||||
@@ -125,7 +161,7 @@ namespace Flowframes
|
||||
Directory.CreateDirectory(outPath);
|
||||
if (useAutoEnc && factor == 4)
|
||||
AutoEncode.paused = false;
|
||||
await RunRifePartial(run1ResultsPath, outPath, mdl);
|
||||
await RunRifeNcnnProcess(run1ResultsPath, outPath, mdl);
|
||||
IOUtils.TryDeleteIfExists(run1ResultsPath);
|
||||
}
|
||||
|
||||
@@ -139,7 +175,7 @@ namespace Flowframes
|
||||
Directory.CreateDirectory(outPath);
|
||||
if (useAutoEnc && factor == 8)
|
||||
AutoEncode.paused = false;
|
||||
await RunRifePartial(run2ResultsPath, outPath, mdl);
|
||||
await RunRifeNcnnProcess(run2ResultsPath, outPath, mdl);
|
||||
IOUtils.TryDeleteIfExists(run2ResultsPath);
|
||||
}
|
||||
|
||||
@@ -151,12 +187,11 @@ namespace Flowframes
|
||||
AiFinished("RIFE");
|
||||
}
|
||||
|
||||
static async Task RunRifePartial(string inPath, string outPath, string mdl)
|
||||
static async Task RunRifeNcnnProcess(string inPath, string outPath, string mdl)
|
||||
{
|
||||
InterpolateUtils.GetProgressByFrameAmount(Interpolate.current.interpFolder, Interpolate.current.GetTargetFrameCount(inPath, 2));
|
||||
|
||||
Process rifeNcnn = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
|
||||
AiStarted(rifeNcnn, 1500, 2, inPath);
|
||||
AiStarted(rifeNcnn, 1500, inPath);
|
||||
SetProgressCheck(outPath, 2);
|
||||
|
||||
string uhdStr = await InterpolateUtils.UseUHD() ? "-u" : "";
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Flowframes.UI
|
||||
{
|
||||
string outPath = Path.ChangeExtension(videoPath, null) + "-extracted";
|
||||
Program.mainForm.SetWorking(true);
|
||||
await FFmpegCommands.VideoToFrames(videoPath, Path.Combine(outPath, Paths.framesDir), Interpolate.current.inFps, false, false, false);
|
||||
await FFmpegCommands.VideoToFrames(videoPath, Path.Combine(outPath, Paths.framesDir), false, Interpolate.current.inFps, false, false, false);
|
||||
File.WriteAllText(Path.Combine(outPath, "fps.ini"), Interpolate.current.inFps.ToString());
|
||||
if (withAudio)
|
||||
await FFmpegCommands.ExtractAudio(videoPath, Path.Combine(outPath, "audio"));
|
||||
|
||||
Reference in New Issue
Block a user