Alpha support for GIFs/PNGs (no ncnn support atm)

This commit is contained in:
N00MKRAD
2021-01-18 15:32:45 +01:00
parent d722481ba6
commit ec5f494be6
10 changed files with 243 additions and 155 deletions

View File

@@ -25,41 +25,40 @@ namespace Flowframes
public static async Task ExtractSceneChanges(string inputFile, string frameFolderPath, float rate) public static async Task ExtractSceneChanges(string inputFile, string frameFolderPath, float rate)
{ {
Logger.Log("Extracting scene changes..."); 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; bool hiddenLog = Interpolate.currentInputFrameCount <= 50;
int amount = IOUtils.GetAmountOfFiles(frameFolderPath, false); int amount = IOUtils.GetAmountOfFiles(frameFolderPath, false);
Logger.Log($"Detected {amount} scene {(amount == 1 ? "change" : "changes")}.".Replace(" 0 ", " no "), false, !hiddenLog); 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..."); if (!sceneDetect) Logger.Log("Extracting video frames from input video...");
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : ""; 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 timecodeStr = timecodes ? $"-copyts -r {FrameOrder.timebase} -frame_pts true" : "-copyts -frame_pts true";
string scnDetect = sceneDetect ? $"\"select='gt(scene,{Config.GetFloatString("scnDetectValue")})'\"" : ""; string scnDetect = sceneDetect ? $"\"select='gt(scene,{Config.GetFloatString("scnDetectValue")})'\"" : "";
string mpStr = deDupe ? ((Config.GetInt("mpdecimateMode") == 0) ? mpDecDef : mpDecAggr) : ""; string mpStr = deDupe ? ((Config.GetInt("mpdecimateMode") == 0) ? mpDecDef : mpDecAggr) : "";
string filters = FormatUtils.ConcatStrings(new string[] { scnDetect, mpStr } ); string filters = FormatUtils.ConcatStrings(new string[] { scnDetect, mpStr } );
string vf = filters.Length > 2 ? $"-vf {filters}" : ""; string vf = filters.Length > 2 ? $"-vf {filters}" : "";
string rateArg = (rate > 0) ? $" -r {rate.ToStringDot()}" : ""; string rateArg = (rate > 0) ? $" -r {rate.ToStringDot()}" : "";
bool enableAlpha = (Config.GetBool("enableAlpha", true) && (Path.GetExtension(inputFile).ToLower() == ".gif")); string pixFmt = alpha ? "-pix_fmt rgba" : "-pix_fmt rgb24"; // Use RGBA for GIF for alpha support
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} \"{framesDir}/%{Padding.inputFrames}d.png\"";
string args = $"{rateArg} -i {inputFile.Wrap()} {pngComprArg} -vsync 0 {pixFmt} {timecodeStr} {vf} {sizeStr} \"{frameFolderPath}/%{Padding.inputFrames}d.png\"";
AvProcess.LogMode logMode = Interpolate.currentInputFrameCount > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden; AvProcess.LogMode logMode = Interpolate.currentInputFrameCount > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden;
await AvProcess.RunFfmpeg(args, logMode, AvProcess.TaskType.ExtractFrames); 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); if (!sceneDetect) Logger.Log($"Extracted {amount} {(amount == 1 ? "frame" : "frames")} from input.", false, true);
await Task.Delay(1); await Task.Delay(1);
if (delSrc) if (delSrc)
DeleteSource(inputFile); 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..."); if (showLog) Logger.Log("Importing images...");
Logger.Log($"Importing images from {inpath} to {outpath}."); Logger.Log($"Importing images from {inpath} to {outpath}.");
@@ -72,8 +71,7 @@ namespace Flowframes
File.WriteAllText(concatFile, concatFileContent); File.WriteAllText(concatFile, concatFileContent);
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : ""; 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 = alpha ? "-pix_fmt rgba" : "-pix_fmt rgb24"; // Use RGBA for GIF for alpha support
string pixFmt = enableAlpha ? "-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\""; 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; AvProcess.LogMode logMode = IOUtils.GetAmountOfFiles(inpath, false) > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden;
await AvProcess.RunFfmpeg(args, logMode, AvProcess.TaskType.ExtractFrames); 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); 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) public static async Task LoopVideo(string inputFile, int times, bool delSrc = false)
{ {
string pathNoExt = Path.ChangeExtension(inputFile, null); string pathNoExt = Path.ChangeExtension(inputFile, null);
@@ -164,18 +169,6 @@ namespace Flowframes
DeleteSource(inputFile); 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) public static async Task ChangeSpeed(string inputFile, float newSpeedPercent, bool delSrc = false)
{ {
string pathNoExt = Path.ChangeExtension(inputFile, null); string pathNoExt = Path.ChangeExtension(inputFile, null);

View File

@@ -30,6 +30,8 @@ namespace Flowframes
public Size inputResolution; public Size inputResolution;
public Size scaledResolution; public Size scaledResolution;
public bool alpha;
public InterpSettings(string inPathArg, string outPathArg, AI aiArg, float inFpsArg, int interpFactorArg, Interpolate.OutMode outModeArg, string modelArg) public InterpSettings(string inPathArg, string outPathArg, AI aiArg, float inFpsArg, int interpFactorArg, Interpolate.OutMode outModeArg, string modelArg)
{ {
inPath = inPathArg; inPath = inPathArg;
@@ -41,6 +43,8 @@ namespace Flowframes
outMode = outModeArg; outMode = outModeArg;
model = modelArg; model = modelArg;
alpha = false;
try try
{ {
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath); tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);

View File

@@ -54,9 +54,10 @@
this.delLogsOnStartup = new System.Windows.Forms.CheckBox(); this.delLogsOnStartup = new System.Windows.Forms.CheckBox();
this.label11 = new System.Windows.Forms.Label(); this.label11 = new System.Windows.Forms.Label();
this.tabListPage2 = new Cyotek.Windows.Forms.TabListPage(); this.tabListPage2 = new Cyotek.Windows.Forms.TabListPage();
this.keepSubs = new System.Windows.Forms.CheckBox();
this.scnDetectValue = new System.Windows.Forms.NumericUpDown(); this.scnDetectValue = new System.Windows.Forms.NumericUpDown();
this.sbsAllowAutoEnc = new System.Windows.Forms.CheckBox(); 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.label53 = new System.Windows.Forms.Label();
this.autoEncMode = new System.Windows.Forms.ComboBox(); this.autoEncMode = new System.Windows.Forms.ComboBox();
this.label49 = new System.Windows.Forms.Label(); this.label49 = new System.Windows.Forms.Label();
@@ -78,6 +79,7 @@
this.keepAudio = new System.Windows.Forms.CheckBox(); this.keepAudio = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.aiOptsPage = new Cyotek.Windows.Forms.TabListPage(); this.aiOptsPage = new Cyotek.Windows.Forms.TabListPage();
this.ncnnThreads = new System.Windows.Forms.NumericUpDown();
this.label30 = new System.Windows.Forms.Label(); this.label30 = new System.Windows.Forms.Label();
this.panel6 = new System.Windows.Forms.Panel(); this.panel6 = new System.Windows.Forms.Panel();
this.uhdThresh = new System.Windows.Forms.ComboBox(); this.uhdThresh = new System.Windows.Forms.ComboBox();
@@ -93,6 +95,7 @@
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.label32 = new System.Windows.Forms.Label(); this.label32 = new System.Windows.Forms.Label();
this.vidExportTab = new Cyotek.Windows.Forms.TabListPage(); this.vidExportTab = new Cyotek.Windows.Forms.TabListPage();
this.minOutVidLength = new System.Windows.Forms.NumericUpDown();
this.aviColors = new System.Windows.Forms.ComboBox(); this.aviColors = new System.Windows.Forms.ComboBox();
this.aviCodec = new System.Windows.Forms.ComboBox(); this.aviCodec = new System.Windows.Forms.ComboBox();
this.label60 = new System.Windows.Forms.Label(); this.label60 = new System.Windows.Forms.Label();
@@ -150,9 +153,9 @@
this.cmdDebugMode = new System.Windows.Forms.ComboBox(); this.cmdDebugMode = new System.Windows.Forms.ComboBox();
this.titleLabel = new System.Windows.Forms.Label(); this.titleLabel = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.ncnnThreads = new System.Windows.Forms.NumericUpDown(); this.label25 = new System.Windows.Forms.Label();
this.minOutVidLength = new System.Windows.Forms.NumericUpDown(); this.enableAlpha = new System.Windows.Forms.CheckBox();
this.keepSubs = new System.Windows.Forms.CheckBox(); this.label4 = new System.Windows.Forms.Label();
this.settingsTabList.SuspendLayout(); this.settingsTabList.SuspendLayout();
this.generalTab.SuspendLayout(); this.generalTab.SuspendLayout();
this.tabListPage2.SuspendLayout(); this.tabListPage2.SuspendLayout();
@@ -161,10 +164,10 @@
this.magickDedupePanel.SuspendLayout(); this.magickDedupePanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dedupThresh)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dedupThresh)).BeginInit();
this.aiOptsPage.SuspendLayout(); this.aiOptsPage.SuspendLayout();
this.vidExportTab.SuspendLayout();
this.debugTab.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.ncnnThreads)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ncnnThreads)).BeginInit();
this.vidExportTab.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.minOutVidLength)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.minOutVidLength)).BeginInit();
this.debugTab.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// settingsTabList // settingsTabList
@@ -327,7 +330,7 @@
this.tempDirCustom.Location = new System.Drawing.Point(486, 67); this.tempDirCustom.Location = new System.Drawing.Point(486, 67);
this.tempDirCustom.MinimumSize = new System.Drawing.Size(4, 21); this.tempDirCustom.MinimumSize = new System.Drawing.Size(4, 21);
this.tempDirCustom.Name = "tempDirCustom"; 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; this.tempDirCustom.TabIndex = 69;
// //
// keepTempFolder // keepTempFolder
@@ -451,10 +454,13 @@
// tabListPage2 // tabListPage2
// //
this.tabListPage2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); 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.keepSubs);
this.tabListPage2.Controls.Add(this.scnDetectValue); this.tabListPage2.Controls.Add(this.scnDetectValue);
this.tabListPage2.Controls.Add(this.sbsAllowAutoEnc); 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.label53);
this.tabListPage2.Controls.Add(this.autoEncMode); this.tabListPage2.Controls.Add(this.autoEncMode);
this.tabListPage2.Controls.Add(this.label49); this.tabListPage2.Controls.Add(this.label49);
@@ -476,6 +482,16 @@
this.tabListPage2.Size = new System.Drawing.Size(762, 419); this.tabListPage2.Size = new System.Drawing.Size(762, 419);
this.tabListPage2.Text = "Interpolation"; 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 // scnDetectValue
// //
this.scnDetectValue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); this.scnDetectValue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
@@ -486,7 +502,7 @@
0, 0,
0, 0,
131072}); 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[] { this.scnDetectValue.Maximum = new decimal(new int[] {
5, 5,
0, 0,
@@ -509,26 +525,26 @@
// sbsAllowAutoEnc // sbsAllowAutoEnc
// //
this.sbsAllowAutoEnc.AutoSize = true; 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.Name = "sbsAllowAutoEnc";
this.sbsAllowAutoEnc.Size = new System.Drawing.Size(15, 14); this.sbsAllowAutoEnc.Size = new System.Drawing.Size(15, 14);
this.sbsAllowAutoEnc.TabIndex = 72; this.sbsAllowAutoEnc.TabIndex = 72;
this.sbsAllowAutoEnc.UseVisualStyleBackColor = true; this.sbsAllowAutoEnc.UseVisualStyleBackColor = true;
// //
// label4 // dedupeSensLabel
// //
this.label4.AutoSize = true; this.dedupeSensLabel.AutoSize = true;
this.label4.Location = new System.Drawing.Point(536, 71); this.dedupeSensLabel.Location = new System.Drawing.Point(536, 101);
this.label4.Margin = new System.Windows.Forms.Padding(3); this.dedupeSensLabel.Margin = new System.Windows.Forms.Padding(3);
this.label4.Name = "label4"; this.dedupeSensLabel.Name = "dedupeSensLabel";
this.label4.Size = new System.Drawing.Size(57, 13); this.dedupeSensLabel.Size = new System.Drawing.Size(57, 13);
this.label4.TabIndex = 29; this.dedupeSensLabel.TabIndex = 29;
this.label4.Text = "Sensitivity:"; this.dedupeSensLabel.Text = "Sensitivity:";
// //
// label53 // label53
// //
this.label53.AutoSize = true; 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.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label53.Name = "label53"; this.label53.Name = "label53";
this.label53.Size = new System.Drawing.Size(203, 13); this.label53.Size = new System.Drawing.Size(203, 13);
@@ -546,7 +562,7 @@
"Disabled", "Disabled",
"Enabled (Keep Interpolated Frames)", "Enabled (Keep Interpolated Frames)",
"Enabled (Delete Frames Once Encoded)"}); "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.Name = "autoEncMode";
this.autoEncMode.Size = new System.Drawing.Size(250, 21); this.autoEncMode.Size = new System.Drawing.Size(250, 21);
this.autoEncMode.TabIndex = 70; this.autoEncMode.TabIndex = 70;
@@ -554,7 +570,7 @@
// label49 // label49
// //
this.label49.AutoSize = true; 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.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label49.Name = "label49"; this.label49.Name = "label49";
this.label49.Size = new System.Drawing.Size(206, 13); 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.BackgroundImage = global::Flowframes.Properties.Resources.baseline_create_white_18dp_semiTransparent;
this.panel14.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "panel14";
this.panel14.Size = new System.Drawing.Size(21, 21); this.panel14.Size = new System.Drawing.Size(21, 21);
this.panel14.TabIndex = 68; this.panel14.TabIndex = 68;
@@ -575,7 +591,7 @@
// //
this.label52.AutoSize = true; this.label52.AutoSize = true;
this.label52.ForeColor = System.Drawing.Color.Silver; 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.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label52.Name = "label52"; this.label52.Name = "label52";
this.label52.Size = new System.Drawing.Size(225, 13); this.label52.Size = new System.Drawing.Size(225, 13);
@@ -585,7 +601,7 @@
// label51 // label51
// //
this.label51.AutoSize = true; 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.Margin = new System.Windows.Forms.Padding(3);
this.label51.Name = "label51"; this.label51.Name = "label51";
this.label51.Size = new System.Drawing.Size(57, 13); this.label51.Size = new System.Drawing.Size(57, 13);
@@ -595,7 +611,7 @@
// scnDetect // scnDetect
// //
this.scnDetect.AutoSize = true; 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.Name = "scnDetect";
this.scnDetect.Size = new System.Drawing.Size(15, 14); this.scnDetect.Size = new System.Drawing.Size(15, 14);
this.scnDetect.TabIndex = 64; this.scnDetect.TabIndex = 64;
@@ -604,7 +620,7 @@
// label50 // label50
// //
this.label50.AutoSize = true; 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.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label50.Name = "label50"; this.label50.Name = "label50";
this.label50.Size = new System.Drawing.Size(194, 13); this.label50.Size = new System.Drawing.Size(194, 13);
@@ -614,7 +630,7 @@
// mpDedupePanel // mpDedupePanel
// //
this.mpDedupePanel.Controls.Add(this.mpdecimateMode); 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.Margin = new System.Windows.Forms.Padding(0);
this.mpDedupePanel.Name = "mpDedupePanel"; this.mpDedupePanel.Name = "mpDedupePanel";
this.mpDedupePanel.Size = new System.Drawing.Size(135, 21); this.mpDedupePanel.Size = new System.Drawing.Size(135, 21);
@@ -640,7 +656,7 @@
// //
this.magickDedupePanel.Controls.Add(this.dedupThresh); this.magickDedupePanel.Controls.Add(this.dedupThresh);
this.magickDedupePanel.Controls.Add(this.panel3); 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.Margin = new System.Windows.Forms.Padding(0);
this.magickDedupePanel.Name = "magickDedupePanel"; this.magickDedupePanel.Name = "magickDedupePanel";
this.magickDedupePanel.Size = new System.Drawing.Size(135, 21); this.magickDedupePanel.Size = new System.Drawing.Size(135, 21);
@@ -701,7 +717,7 @@
// enableLoop // enableLoop
// //
this.enableLoop.AutoSize = true; 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.Name = "enableLoop";
this.enableLoop.Size = new System.Drawing.Size(15, 14); this.enableLoop.Size = new System.Drawing.Size(15, 14);
this.enableLoop.TabIndex = 31; this.enableLoop.TabIndex = 31;
@@ -710,7 +726,7 @@
// label15 // label15
// //
this.label15.AutoSize = true; 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.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label15.Name = "label15"; this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(217, 13); this.label15.Size = new System.Drawing.Size(217, 13);
@@ -728,7 +744,7 @@
"Disabled", "Disabled",
"1: After Extraction - Slow, Accurate", "1: After Extraction - Slow, Accurate",
"2: During Extraction - Fast, Less 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.Name = "dedupMode";
this.dedupMode.Size = new System.Drawing.Size(250, 21); this.dedupMode.Size = new System.Drawing.Size(250, 21);
this.dedupMode.TabIndex = 27; this.dedupMode.TabIndex = 27;
@@ -737,7 +753,7 @@
// label2 // label2
// //
this.label2.AutoSize = true; 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.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(139, 13); this.label2.Size = new System.Drawing.Size(139, 13);
@@ -786,6 +802,30 @@
this.aiOptsPage.Size = new System.Drawing.Size(762, 419); this.aiOptsPage.Size = new System.Drawing.Size(762, 419);
this.aiOptsPage.Text = "AI Specific Settings"; 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 // label30
// //
this.label30.AutoSize = true; this.label30.AutoSize = true;
@@ -991,6 +1031,25 @@
this.vidExportTab.Size = new System.Drawing.Size(762, 419); this.vidExportTab.Size = new System.Drawing.Size(762, 419);
this.vidExportTab.Text = "Video Export"; 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 // aviColors
// //
this.aviColors.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); 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.TabIndex = 1;
this.titleLabel.Text = "Settings"; this.titleLabel.Text = "Settings";
// //
// ncnnThreads // label25
// //
this.ncnnThreads.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); this.label25.AutoSize = true;
this.ncnnThreads.ForeColor = System.Drawing.Color.White; this.label25.Location = new System.Drawing.Point(10, 70);
this.ncnnThreads.Location = new System.Drawing.Point(280, 98); this.label25.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.ncnnThreads.Maximum = new decimal(new int[] { this.label25.Name = "label25";
4, this.label25.Size = new System.Drawing.Size(108, 13);
0, this.label25.TabIndex = 76;
0, this.label25.Text = "Enable Transparency";
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});
// //
// minOutVidLength // enableAlpha
// //
this.minOutVidLength.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); this.enableAlpha.AutoSize = true;
this.minOutVidLength.ForeColor = System.Drawing.Color.White; this.enableAlpha.Location = new System.Drawing.Point(280, 70);
this.minOutVidLength.Location = new System.Drawing.Point(280, 37); this.enableAlpha.Name = "enableAlpha";
this.minOutVidLength.Maximum = new decimal(new int[] { this.enableAlpha.Size = new System.Drawing.Size(15, 14);
60, this.enableAlpha.TabIndex = 77;
0, this.enableAlpha.UseVisualStyleBackColor = true;
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});
// //
// keepSubs // label4
// //
this.keepSubs.AutoSize = true; this.label4.AutoSize = true;
this.keepSubs.Location = new System.Drawing.Point(367, 39); this.label4.ForeColor = System.Drawing.Color.Silver;
this.keepSubs.Name = "keepSubs"; this.label4.Location = new System.Drawing.Point(308, 70);
this.keepSubs.Size = new System.Drawing.Size(94, 17); this.label4.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.keepSubs.TabIndex = 75; this.label4.Name = "label4";
this.keepSubs.Text = "Keep Subtitles"; this.label4.Size = new System.Drawing.Size(300, 13);
this.keepSubs.UseVisualStyleBackColor = true; this.label4.TabIndex = 78;
this.label4.Text = "Enables Transparency (Alpha) support for GIFs and PNG input";
// //
// SettingsForm // SettingsForm
// //
@@ -1762,12 +1798,12 @@
((System.ComponentModel.ISupportInitialize)(this.dedupThresh)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dedupThresh)).EndInit();
this.aiOptsPage.ResumeLayout(false); this.aiOptsPage.ResumeLayout(false);
this.aiOptsPage.PerformLayout(); this.aiOptsPage.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.ncnnThreads)).EndInit();
this.vidExportTab.ResumeLayout(false); this.vidExportTab.ResumeLayout(false);
this.vidExportTab.PerformLayout(); this.vidExportTab.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.minOutVidLength)).EndInit();
this.debugTab.ResumeLayout(false); this.debugTab.ResumeLayout(false);
this.debugTab.PerformLayout(); this.debugTab.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.ncnnThreads)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.minOutVidLength)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@@ -1788,7 +1824,7 @@
private System.Windows.Forms.ComboBox dedupMode; private System.Windows.Forms.ComboBox dedupMode;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox cmdDebugMode; 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.CheckBox enableLoop;
private System.Windows.Forms.Label label15; private System.Windows.Forms.Label label15;
private Cyotek.Windows.Forms.TabListPage vidExportTab; private Cyotek.Windows.Forms.TabListPage vidExportTab;
@@ -1898,5 +1934,8 @@
private System.Windows.Forms.NumericUpDown ncnnThreads; private System.Windows.Forms.NumericUpDown ncnnThreads;
private System.Windows.Forms.NumericUpDown minOutVidLength; private System.Windows.Forms.NumericUpDown minOutVidLength;
private System.Windows.Forms.CheckBox keepSubs; private System.Windows.Forms.CheckBox keepSubs;
private System.Windows.Forms.CheckBox enableAlpha;
private System.Windows.Forms.Label label25;
private System.Windows.Forms.Label label4;
} }
} }

View File

@@ -64,6 +64,7 @@ namespace Flowframes.Forms
// General // General
ConfigParser.SaveComboxIndex(processingMode); ConfigParser.SaveComboxIndex(processingMode);
ConfigParser.SaveGuiElement(maxVidHeight); ConfigParser.SaveGuiElement(maxVidHeight);
ConfigParser.SaveGuiElement(enableAlpha);
ConfigParser.SaveComboxIndex(tempFolderLoc); ConfigParser.SaveComboxIndex(tempFolderLoc);
ConfigParser.SaveGuiElement(keepTempFolder); ConfigParser.SaveGuiElement(keepTempFolder);
ConfigParser.SaveGuiElement(delLogsOnStartup); ConfigParser.SaveGuiElement(delLogsOnStartup);
@@ -112,6 +113,7 @@ namespace Flowframes.Forms
// General // General
ConfigParser.LoadComboxIndex(processingMode); ConfigParser.LoadComboxIndex(processingMode);
ConfigParser.LoadGuiElement(maxVidHeight); ConfigParser.LoadGuiElement(maxVidHeight);
ConfigParser.LoadGuiElement(enableAlpha);
ConfigParser.LoadComboxIndex(tempFolderLoc); ConfigParser.LoadGuiElement(tempDirCustom); ConfigParser.LoadComboxIndex(tempFolderLoc); ConfigParser.LoadGuiElement(tempDirCustom);
ConfigParser.LoadGuiElement(delLogsOnStartup); ConfigParser.LoadGuiElement(delLogsOnStartup);
ConfigParser.LoadGuiElement(keepTempFolder); ConfigParser.LoadGuiElement(keepTempFolder);
@@ -180,6 +182,7 @@ namespace Flowframes.Forms
private void dedupMode_SelectedIndexChanged(object sender, EventArgs e) private void dedupMode_SelectedIndexChanged(object sender, EventArgs e)
{ {
dedupeSensLabel.Visible = dedupMode.SelectedIndex != 0;
magickDedupePanel.Visible = dedupMode.SelectedIndex == 1; magickDedupePanel.Visible = dedupMode.SelectedIndex == 1;
mpDedupePanel.Visible = dedupMode.SelectedIndex == 2; mpDedupePanel.Visible = dedupMode.SelectedIndex == 2;
} }

View File

@@ -42,24 +42,20 @@ namespace Flowframes.Magick
{ {
var files = IOUtils.GetFilesSorted(inputDir); 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); Directory.CreateDirectory(outputDir);
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Restart(); sw.Restart();
int counter = 0; int counter = 0;
foreach (string file in files) foreach (string file in files)
{ {
if (print) Logger.Log($"Extracting alpha from {Path.GetFileName(file)}", false, true);
MagickImage img = new MagickImage(file); MagickImage img = new MagickImage(file);
img.Format = MagickFormat.Png32; img.Format = MagickFormat.Png32;
img.Quality = 10; img.Quality = 10;
// Fill the image with a transparent background img.FloodFill(MagickColors.None, 0, 0); // Fill the image with a transparent background
img.FloodFill(MagickColors.None, 0, 0); img.InverseOpaque(MagickColors.None, MagickColors.White); // Change all the pixels that are not transparent to white.
// Change all the pixels that are not transparent to white. img.ColorAlpha(MagickColors.Black); // Change the transparent pixels to black.
img.InverseOpaque(MagickColors.None, MagickColors.White);
// Change the transparent pixels to black.
//img.ColorAlpha(MagickColors.Black);
string outPath = Path.Combine(outputDir, Path.GetFileName(file)); string outPath = Path.Combine(outputDir, Path.GetFileName(file));
img.Write(outPath); img.Write(outPath);

View File

@@ -43,13 +43,7 @@ namespace Flowframes
currentInputFrameCount = await Utils.GetInputFrameCountAsync(current.inPath); currentInputFrameCount = await Utils.GetInputFrameCountAsync(current.inPath);
Program.mainForm.SetStatus("Starting..."); Program.mainForm.SetStatus("Starting...");
Program.mainForm.SetWorking(true); Program.mainForm.SetWorking(true);
await GetFrames();
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");
if (canceled) return; if (canceled) return;
sw.Restart(); sw.Restart();
await PostProcessFrames(); await PostProcessFrames();
@@ -67,7 +61,21 @@ namespace Flowframes
Program.mainForm.SetStatus("Done interpolating!"); 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")) if (Config.GetBool("scnDetect"))
{ {
@@ -78,7 +86,7 @@ namespace Flowframes
Program.mainForm.SetStatus("Extracting frames from video..."); Program.mainForm.SetStatus("Extracting frames from video...");
bool mpdecimate = Config.GetInt("dedupMode") == 2; 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) if (mpdecimate)
{ {
@@ -126,6 +134,7 @@ namespace Flowframes
if (canceled) return; 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); await FrameOrder.CreateTimecodeFiles(current.framesFolder, FrameOrder.Mode.CFR, Config.GetBool("enableLoop"), current.interpFactor, false);
if (canceled) return; if (canceled) return;
@@ -139,7 +148,7 @@ namespace Flowframes
await ModelDownloader.DownloadModelFiles(Path.GetFileNameWithoutExtension(ai.pkg.fileName), current.model); await ModelDownloader.DownloadModelFiles(Path.GetFileNameWithoutExtension(ai.pkg.fileName), current.model);
if (canceled) return; if (canceled) return;
currentlyUsingAutoEnc = Utils.UseAutoEnc(stepByStep, current); currentlyUsingAutoEnc = Utils.CanUseAutoEnc(stepByStep, current);
IOUtils.CreateDir(outpath); IOUtils.CreateDir(outpath);
@@ -149,7 +158,7 @@ namespace Flowframes
tasks.Add(AiProcess.RunRifeCuda(current.framesFolder, current.interpFactor, current.model)); tasks.Add(AiProcess.RunRifeCuda(current.framesFolder, current.interpFactor, current.model));
if (ai.aiName == Networks.rifeNcnn.aiName) 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) if (currentlyUsingAutoEnc)
{ {

View File

@@ -42,10 +42,7 @@ namespace Flowframes.Main
if (step.Contains("Extract Frames")) if (step.Contains("Extract Frames"))
{ {
if (!current.inputIsFrames) // Input is video - extract frames first await GetFrames();
await ExtractVideoFrames();
else
await FFmpegCommands.ImportImages(current.inPath, current.framesFolder, await InterpolateUtils.GetOutputResolution(current.inPath, true));
} }
if (step.Contains("Run Interpolation")) if (step.Contains("Run Interpolation"))

View File

@@ -59,21 +59,26 @@ namespace Flowframes.Main
} }
public static int targetFrames; public static int targetFrames;
public static string currentOutdir;
public static int currentFactor; public static int currentFactor;
public static bool progressPaused = false;
public static bool progCheckRunning = false;
public static async void GetProgressByFrameAmount(string outdir, int target) 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; bool firstProgUpd = true;
Program.mainForm.SetProgress(0); Program.mainForm.SetProgress(0);
targetFrames = target;
while (Program.busy) while (Program.busy)
{ {
if (AiProcess.processTime.IsRunning && Directory.Exists(outdir)) if (!progressPaused && AiProcess.processTime.IsRunning && Directory.Exists(currentOutdir))
{ {
if (firstProgUpd && Program.mainForm.IsInFocus()) if (firstProgUpd && Program.mainForm.IsInFocus())
Program.mainForm.SetTab("preview"); Program.mainForm.SetTab("preview");
firstProgUpd = false; firstProgUpd = false;
string[] frames = IOUtils.GetFilesSorted(outdir, $"*.{GetOutExt()}"); string[] frames = IOUtils.GetFilesSorted(currentOutdir, $"*.{GetOutExt()}");
if (frames.Length > 1) if (frames.Length > 1)
UpdateInterpProgress(frames.Length, targetFrames, frames[frames.Length - 1]); UpdateInterpProgress(frames.Length, targetFrames, frames[frames.Length - 1]);
if (frames.Length >= targetFrames) if (frames.Length >= targetFrames)
@@ -85,6 +90,7 @@ namespace Flowframes.Main
await Task.Delay(200); await Task.Delay(200);
} }
} }
progCheckRunning = false;
} }
public static void UpdateInterpProgress(int frames, int target, string latestFramePath = "") 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 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(); 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); Logger.Log($"Not Using AutoEnc: Out Mode is not video ({current.outMode.ToString()})", true);
return false; return false;

View File

@@ -28,18 +28,32 @@ namespace Flowframes
public static Dictionary<string, string> filenameMap = new Dictionary<string, string>(); // TODO: Store on disk instead for crashes? 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; lastStartupTimeMs = startupTimeMs;
processTime.Restart(); processTime.Restart();
currentAiProcess = proc; currentAiProcess = proc;
lastInPath = string.IsNullOrWhiteSpace(inPath) ? Interpolate.current.framesFolder : inPath; 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; 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) static async Task AiFinished (string aiName)
{ {
Program.mainForm.SetProgress(100); Program.mainForm.SetProgress(100);
@@ -70,12 +84,8 @@ namespace Flowframes
public static async Task RunRifeCuda(string framesPath, int interpFactor, string mdl) 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 rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName));
string script = "inference_video.py"; 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))) if (!File.Exists(Path.Combine(rifeDir, script)))
{ {
@@ -83,12 +93,38 @@ namespace Flowframes
return; 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()); 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()} & " + rifePy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeCuda).Wrap()} & " +
$"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Python.GetPyCmd()} {script} {args}"; $"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($"Running RIFE {(await InterpolateUtils.UseUHD() ? "(UHD Mode)" : "")} ({script})...".TrimWhitespaces(), false);
Logger.Log("cmd.exe " + rifePy.StartInfo.Arguments, true); Logger.Log("cmd.exe " + rifePy.StartInfo.Arguments, true);
if (!OSUtils.ShowHiddenCmd()) if (!OSUtils.ShowHiddenCmd())
{ {
rifePy.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "rife-cuda-log"); }; rifePy.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "rife-cuda-log"); };
@@ -100,11 +136,11 @@ namespace Flowframes
rifePy.BeginOutputReadLine(); rifePy.BeginOutputReadLine();
rifePy.BeginErrorReadLine(); rifePy.BeginErrorReadLine();
} }
while (!rifePy.HasExited) await Task.Delay(1); 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(); processTimeMulti.Restart();
Logger.Log($"Running RIFE{(await InterpolateUtils.UseUHD() ? " (UHD Mode)" : "")}...", false); Logger.Log($"Running RIFE{(await InterpolateUtils.UseUHD() ? " (UHD Mode)" : "")}...", false);
@@ -113,7 +149,7 @@ namespace Flowframes
if(factor > 2) if(factor > 2)
AutoEncode.paused = true; // Disable autoenc until the last iteration 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 if (factor == 4 || factor == 8) // #2
{ {
@@ -125,7 +161,7 @@ namespace Flowframes
Directory.CreateDirectory(outPath); Directory.CreateDirectory(outPath);
if (useAutoEnc && factor == 4) if (useAutoEnc && factor == 4)
AutoEncode.paused = false; AutoEncode.paused = false;
await RunRifePartial(run1ResultsPath, outPath, mdl); await RunRifeNcnnProcess(run1ResultsPath, outPath, mdl);
IOUtils.TryDeleteIfExists(run1ResultsPath); IOUtils.TryDeleteIfExists(run1ResultsPath);
} }
@@ -139,7 +175,7 @@ namespace Flowframes
Directory.CreateDirectory(outPath); Directory.CreateDirectory(outPath);
if (useAutoEnc && factor == 8) if (useAutoEnc && factor == 8)
AutoEncode.paused = false; AutoEncode.paused = false;
await RunRifePartial(run2ResultsPath, outPath, mdl); await RunRifeNcnnProcess(run2ResultsPath, outPath, mdl);
IOUtils.TryDeleteIfExists(run2ResultsPath); IOUtils.TryDeleteIfExists(run2ResultsPath);
} }
@@ -151,12 +187,11 @@ namespace Flowframes
AiFinished("RIFE"); 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()); Process rifeNcnn = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
AiStarted(rifeNcnn, 1500, 2, inPath); AiStarted(rifeNcnn, 1500, inPath);
SetProgressCheck(outPath, 2);
string uhdStr = await InterpolateUtils.UseUHD() ? "-u" : ""; string uhdStr = await InterpolateUtils.UseUHD() ? "-u" : "";

View File

@@ -19,7 +19,7 @@ namespace Flowframes.UI
{ {
string outPath = Path.ChangeExtension(videoPath, null) + "-extracted"; string outPath = Path.ChangeExtension(videoPath, null) + "-extracted";
Program.mainForm.SetWorking(true); 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()); File.WriteAllText(Path.Combine(outPath, "fps.ini"), Interpolate.current.inFps.ToString());
if (withAudio) if (withAudio)
await FFmpegCommands.ExtractAudio(videoPath, Path.Combine(outPath, "audio")); await FFmpegCommands.ExtractAudio(videoPath, Path.Combine(outPath, "audio"));