public static async Task InitInput(TextBox outputTbox, TextBox inputTbox, TextBox fpsInTbox)
        {
            Program.mainForm.SetTab("interpolate");
            Program.mainForm.ResetInputInfo();
            string path = inputTbox.Text.Trim();

            InterpolateUtils.PathAsciiCheck(path, "input path");

            if (Config.GetBool("clearLogOnInput"))
            {
                Logger.ClearLogBox();
            }

            outputTbox.Text            = inputTbox.Text.Trim().GetParentDir();
            Program.lastInputPath      = path;
            Program.lastInputPathIsSsd = OSUtils.DriveIsSSD(path);

            if (!Program.lastInputPathIsSsd)
            {
                Logger.Log("Your file seems to be on an HDD or USB device. It is recommended to interpolate videos on an SSD drive for best performance.");
            }

            Logger.Log("Loading metadata...");
            Program.mainForm.currInDuration    = FfmpegCommands.GetDuration(path);
            Program.mainForm.currInDurationCut = Program.mainForm.currInDuration;
            int frameCount = await InterpolateUtils.GetInputFrameCountAsync(path);

            string fpsStr = "Not Found";
            float  fps    = await IOUtils.GetFpsFolderOrVideo(path);

            fpsInTbox.Text = fps.ToString();

            if (fps > 0)
            {
                fpsStr = fps.ToString();
            }

            Logger.Log($"Video FPS: {fpsStr} - Total Number Of Frames: {frameCount}", false, true);
            Program.mainForm.GetInputFpsTextbox().ReadOnly = fps > 0;
            Program.mainForm.currInFps    = fps;
            Program.mainForm.currInFrames = frameCount;
            Program.mainForm.UpdateInputInfo();
            CheckExistingFolder(path, outputTbox.Text.Trim());
            await Task.Delay(10);

            await PrintResolution(path);

            Dedupe.ClearCache();
            await Task.Delay(10);

            InterpolateUtils.SetPreviewImg(await GetThumbnail(path));
        }
Beispiel #2
0
        public static async Task PostProcessFrames(bool stepByStep)
        {
            if (canceled)
            {
                return;
            }

            Program.mainForm.SetStatus("Processing frames...");

            int extractedFrames = IoUtils.GetAmountOfFiles(current.framesFolder, false, "*" + current.framesExt);

            if (!Directory.Exists(current.framesFolder) || currentInputFrameCount <= 0 || extractedFrames < 2)
            {
                if (extractedFrames == 1)
                {
                    Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?");
                }
                else
                {
                    Cancel($"Frame extraction failed!\nExtracted {extractedFrames} frames - current.framesFolder exists: {Directory.Exists(current.framesFolder)} - currentInputFrameCount = {currentInputFrameCount} - extractedFrames = {extractedFrames}.\n\nYour input file might be incompatible.");
                }
            }

            if (Config.GetInt(Config.Key.dedupMode) == 1)
            {
                await Dedupe.Run(current.framesFolder);
            }
            else
            {
                Dedupe.ClearCache();
            }

            if (!Config.GetBool(Config.Key.enableLoop))
            {
                await Utils.CopyLastFrame(currentInputFrameCount);
            }
            else
            {
                FileInfo[] frameFiles          = IoUtils.GetFileInfosSorted(current.framesFolder);
                string     ext                 = frameFiles.First().Extension;
                int        lastNum             = frameFiles.Last().Name.GetInt() + 1;
                string     loopFrameTargetPath = Path.Combine(current.framesFolder, lastNum.ToString().PadLeft(Padding.inputFrames, '0') + ext);
                File.Copy(frameFiles.First().FullName, loopFrameTargetPath, true);
                Logger.Log($"Copied loop frame to {loopFrameTargetPath}.", true);
            }
        }
Beispiel #3
0
        public static async Task RunAi(string outpath, AI ai, bool stepByStep = false)
        {
            if (canceled)
            {
                return;
            }

            await Task.Run(async() => { await Dedupe.CreateDupesFile(current.framesFolder, currentInputFrameCount, current.framesExt); });

            await Task.Run(async() => { await FrameRename.Rename(); });

            await Task.Run(async() => { await FrameOrder.CreateFrameOrderFile(current.framesFolder, Config.GetBool(Config.Key.enableLoop), current.interpFactor); });

            Program.mainForm.SetStatus("Downloading models...");
            await ModelDownloader.DownloadModelFiles(ai, current.model.dir);

            if (canceled)
            {
                return;
            }

            currentlyUsingAutoEnc = Utils.CanUseAutoEnc(stepByStep, current);

            IoUtils.CreateDir(outpath);

            List <Task> tasks = new List <Task>();

            if (ai.aiName == Implementations.rifeCuda.aiName)
            {
                tasks.Add(AiProcess.RunRifeCuda(current.framesFolder, current.interpFactor, current.model.dir));
            }

            if (ai.aiName == Implementations.rifeNcnn.aiName)
            {
                tasks.Add(AiProcess.RunRifeNcnn(current.framesFolder, outpath, current.interpFactor, current.model.dir));
            }

            if (ai.aiName == Implementations.flavrCuda.aiName)
            {
                tasks.Add(AiProcess.RunFlavrCuda(current.framesFolder, current.interpFactor, current.model.dir));
            }

            if (ai.aiName == Implementations.dainNcnn.aiName)
            {
                tasks.Add(AiProcess.RunDainNcnn(current.framesFolder, outpath, current.interpFactor, current.model.dir, Config.GetInt(Config.Key.dainNcnnTilesize, 512)));
            }

            if (ai.aiName == Implementations.xvfiCuda.aiName)
            {
                tasks.Add(AiProcess.RunXvfiCuda(current.framesFolder, current.interpFactor, current.model.dir));
            }

            if (currentlyUsingAutoEnc)
            {
                Logger.Log($"{Logger.GetLastLine()} (Using Auto-Encode)", true);
                tasks.Add(AutoEncode.MainLoop(outpath));
            }

            Program.mainForm.SetStatus("Running AI...");
            await Task.WhenAll(tasks);
        }
Beispiel #4
0
        public static async Task PostProcessFrames(bool stepByStep)
        {
            if (canceled)
            {
                return;
            }

            int extractedFrames = IOUtils.GetAmountOfFiles(current.framesFolder, false, "*.png");

            if (!Directory.Exists(current.framesFolder) || currentInputFrameCount <= 0 || extractedFrames < 2)
            {
                if (extractedFrames == 1)
                {
                    Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?");
                }
                else
                {
                    Cancel("Frame extraction failed!\n\nYour input file might be incompatible.");
                }
            }

            if (Config.GetInt("dedupMode") == 1)
            {
                await Dedupe.Run(current.framesFolder);
            }
            else
            {
                Dedupe.ClearCache();
            }

            if (!Config.GetBool("enableLoop"))
            {
                await Utils.CopyLastFrame(currentInputFrameCount);
            }

            if (Config.GetInt("dedupMode") > 0)
            {
                await Dedupe.CreateDupesFile(current.framesFolder, currentInputFrameCount);
            }

            if (canceled)
            {
                return;
            }

            await FrameOrder.CreateFrameOrderFile(current.framesFolder, Config.GetBool("enableLoop"), current.interpFactor);

            if (canceled)
            {
                return;
            }

            try
            {
                Dictionary <string, string> renamedFilesDict = await IOUtils.RenameCounterDirReversibleAsync(current.framesFolder, "png", 1, Padding.inputFramesRenamed);

                if (stepByStep)
                {
                    AiProcess.filenameMap = renamedFilesDict.ToDictionary(x => Path.GetFileName(x.Key), x => Path.GetFileName(x.Value));    // Save rel paths
                }
            }
            catch (Exception e)
            {
                Logger.Log($"Error renaming frame files: {e.Message}");
                Cancel("Error renaming frame files. Check the log for details.");
            }

            if (current.alpha)
            {
                Program.mainForm.SetStatus("Extracting transparency...");
                Logger.Log("Extracting transparency... (1/2)");
                await FfmpegAlpha.ExtractAlphaDir(current.framesFolder, current.framesFolder + Paths.alphaSuffix);

                Logger.Log("Extracting transparency... (2/2)", false, true);
                await FfmpegAlpha.RemoveAlpha(current.framesFolder, current.framesFolder);
            }
        }
Beispiel #5
0
        public static async Task InitInput(TextBox outputTbox, TextBox inputTbox, TextBox fpsInTbox, bool start = false)
        {
            Program.mainForm.SetTab("interpolate");
            Program.mainForm.ResetInputInfo();
            string path = inputTbox.Text.Trim();

            GetFrameCountCached.Clear();
            GetMediaResolutionCached.Clear();

            if (Config.GetBool(Config.Key.clearLogOnInput))
            {
                Logger.ClearLogBox();
            }

            SetOutPath(outputTbox, inputTbox.Text.Trim().GetParentDir());

            Program.lastInputPath      = path;
            Program.lastInputPathIsSsd = OsUtils.DriveIsSSD(path);

            if (!Program.lastInputPathIsSsd)
            {
                Logger.Log("Your file seems to be on an HDD or USB device. It is recommended to interpolate videos on an SSD drive for best performance.");
            }

            Logger.Log("Loading metadata...");
            Program.mainForm.currInDuration    = FfmpegCommands.GetDuration(path);
            Program.mainForm.currInDurationCut = Program.mainForm.currInDuration;
            int frameCount = await GetFrameCountCached.GetFrameCountAsync(path);

            string   fpsStr = "Not Found";
            Fraction fps    = (await IoUtils.GetFpsFolderOrVideo(path));

            Program.mainForm.currInFpsDetected = fps;
            fpsInTbox.Text = fps.GetString();

            if (fps.GetFloat() > 0)
            {
                fpsStr = $"{fps} (~{fps.GetFloat()})";
            }

            Logger.Log($"Video FPS: {fpsStr} - Total Number Of Frames: {frameCount}", false, true);
            Program.mainForm.GetInputFpsTextbox().ReadOnly = (fps.GetFloat() > 0 && !Config.GetBool("allowCustomInputRate", false));
            Program.mainForm.currInFps    = fps;
            Program.mainForm.currInFrames = frameCount;
            Program.mainForm.UpdateInputInfo();
            CheckExistingFolder(path, outputTbox.Text.Trim());
            await Task.Delay(10);

            await PrintResolution(path);

            Dedupe.ClearCache();
            await Task.Delay(10);

            InterpolationProgress.SetPreviewImg(await GetThumbnail(path));

            if (AutoEncodeResume.resumeNextRun)
            {
                Logger.Log($"Incomplete interpolation detected. Flowframes will resume the interpolation.");
            }

            if (start)
            {
                Program.mainForm.runBtn_Click(null, null);
            }
        }