Exemple #1
0
        public static async Task RunFlavrCuda(string framesPath, float interpFactor, string mdl)
        {
            if (Interpolate.currentlyUsingAutoEnc)      // Ensure AutoEnc is not paused
            {
                AutoEncode.paused = false;
            }

            try
            {
                string flavDir = Path.Combine(Paths.GetPkgPath(), Networks.flavrCuda.pkgDir);
                string script  = "flavr.py";

                if (!File.Exists(Path.Combine(flavDir, script)))
                {
                    Interpolate.Cancel("FLAVR script not found! Make sure you didn't modify any files.");
                    return;
                }

                await RunFlavrCudaProcess(framesPath, Paths.interpDir, script, interpFactor, mdl);

                if (!Interpolate.canceled && Interpolate.current.alpha)
                {
                    InterpolateUtils.progressPaused = true;
                    Logger.Log("Interpolating alpha channel...");
                    await RunFlavrCudaProcess(framesPath + Paths.alphaSuffix, Paths.interpDir + Paths.alphaSuffix, script, interpFactor, mdl);
                }
            }
            catch (Exception e)
            {
                Logger.Log("Error running FLAVR-CUDA: " + e.Message);
            }

            await AiFinished("FLAVR");
        }
Exemple #2
0
        public static async Task RunRifeCuda(string framesPath, float interpFactor, string mdl)
        {
            if (Interpolate.currentlyUsingAutoEnc)      // Ensure AutoEnc is not paused
            {
                AutoEncode.paused = false;
            }

            try
            {
                string rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName));
                string script  = "rife.py";

                if (!File.Exists(Path.Combine(rifeDir, script)))
                {
                    Interpolate.Cancel("RIFE script not found! Make sure you didn't modify any files.");
                    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 + Paths.alphaSuffix, Paths.interpDir + Paths.alphaSuffix, script, interpFactor, mdl);
                }
            }
            catch (Exception e)
            {
                Logger.Log("Error running RIFE-CUDA: " + e.Message);
            }

            await AiFinished("RIFE");
        }
Exemple #3
0
        public static async Task ChunksToVideos(string tempFolder, string chunksFolder, string baseOutPath)
        {
            if (IOUtils.GetAmountOfFiles(chunksFolder, true, $"*{FFmpegUtils.GetExt(I.current.outMode)}") < 1)
            {
                I.Cancel("No video chunks found - An error must have occured during chunk encoding!", AiProcess.hasShownError);
                return;
            }

            await Task.Delay(10);

            Program.mainForm.SetStatus("Merging video chunks...");
            try
            {
                DirectoryInfo chunksDir = new DirectoryInfo(chunksFolder);
                foreach (DirectoryInfo dir in chunksDir.GetDirectories())
                {
                    string suffix            = dir.Name.Replace("chunks", "");
                    string tempConcatFile    = Path.Combine(tempFolder, $"chunks-concat{suffix}.ini");
                    string concatFileContent = "";
                    foreach (string vid in IOUtils.GetFilesSorted(dir.FullName))
                    {
                        concatFileContent += $"file '{Paths.chunksDir}/{dir.Name}/{Path.GetFileName(vid)}'\n";
                    }
                    File.WriteAllText(tempConcatFile, concatFileContent);

                    Logger.Log($"CreateVideo: Running MergeChunks() for vfrFile '{Path.GetFileName(tempConcatFile)}'", true);
                    await MergeChunks(tempConcatFile, baseOutPath.FilenameSuffix(suffix));
                }
            }
            catch (Exception e)
            {
                Logger.Log("ChunksToVideo Error: " + e.Message, false);
                MessageBox.Show("An error occured while trying to merge the video chunks.\nCheck the log for details.");
            }
        }
Exemple #4
0
        private void cancelBtn_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show($"Are you sure you want to cancel the interpolation?", "Are you sure?", MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                SetTab("interpolation");
                Interpolate.Cancel();
            }
        }
Exemple #5
0
        static async Task DiskSpaceCheckLoop()
        {
            while (true)
            {
                if (busy)
                {
                    try
                    {
                        if (Interpolate.current == null || Interpolate.current.tempFolder.Length < 3)
                        {
                            return;
                        }

                        string drivePath = Interpolate.current.tempFolder.Substring(0, 2);
                        long   mb        = IoUtils.GetDiskSpace(Interpolate.current.tempFolder);

                        Logger.Log($"Disk space check for '{drivePath}/': {(mb / 1024f).ToString("0.0")} GB free.", true);

                        bool   lowDiskSpace    = mb < (Config.GetInt(Config.Key.lowDiskSpacePauseGb, 5) * 1024);
                        bool   tooLowDiskSpace = mb < (Config.GetInt(Config.Key.lowDiskSpaceCancelGb, 2) * 1024);
                        string spaceGb         = (mb / 1024f).ToString("0.0");

                        if (!Interpolate.canceled && (AiProcess.lastAiProcess != null && !AiProcess.lastAiProcess.HasExited) && lowDiskSpace)
                        {
                            if (tooLowDiskSpace)
                            {
                                Interpolate.Cancel($"Not enough disk space on '{drivePath}/' ({spaceGb} GB)!");
                            }
                            else
                            {
                                bool showMsg = !AiProcessSuspend.aiProcFrozen;
                                AiProcessSuspend.SuspendIfRunning();

                                if (showMsg)
                                {
                                    UiUtils.ShowMessageBox($"Interpolation has been paused because you are running out of disk space on '{drivePath}/' ({spaceGb} GB)!\n\n" +
                                                           $"Please either clear up some disk space or cancel the interpolation.", UiUtils.MessageType.Warning);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Log($"Disk space check failed: {e.Message}", true);
                    }
                }

                await Task.Delay(15000);
            }
        }
        static string currentOutFile;   // Keeps track of the out file, in case it gets renamed (FPS limiting, looping, etc) before finishing export

        public static async Task Export(string path, string outFolder, I.OutMode mode, bool stepByStep)
        {
            if (!mode.ToString().ToLower().Contains("vid"))     // Copy interp frames out of temp folder and skip video export for image seq export
            {
                try
                {
                    string folder = Path.Combine(outFolder, IOUtils.GetCurrentExportFilename(false, false));
                    await CopyOutputFrames(path, folder, stepByStep);
                }
                catch (Exception e)
                {
                    Logger.Log("Failed to move interp frames folder: " + e.Message);
                }

                return;
            }

            if (IOUtils.GetAmountOfFiles(path, false, $"*.{InterpolateUtils.GetOutExt()}") <= 1)
            {
                I.Cancel("Output folder does not contain frames - An error must have occured during interpolation!", AiProcess.hasShownError);
                return;
            }

            await Task.Delay(10);

            Program.mainForm.SetStatus("Creating output video from frames...");

            try
            {
                float maxFps   = Config.GetFloat("maxFps");
                bool  fpsLimit = maxFps != 0 && I.current.outFps > maxFps;

                bool dontEncodeFullFpsVid = fpsLimit && Config.GetInt("maxFpsMode") == 0;

                if (!dontEncodeFullFpsVid)
                {
                    await Encode(mode, path, Path.Combine(outFolder, IOUtils.GetCurrentExportFilename(false, true)), I.current.outFps);
                }

                if (fpsLimit)
                {
                    await Encode(mode, path, Path.Combine(outFolder, IOUtils.GetCurrentExportFilename(true, true)), I.current.outFps, maxFps);
                }
            }
            catch (Exception e)
            {
                Logger.Log("FramesToVideo Error: " + e.Message, false);
                MessageBox.Show("An error occured while trying to convert the interpolated frames to a video.\nCheck the log for details.");
            }
        }
Exemple #7
0
        static async Task DiskSpaceCheckLoop()
        {
            while (true)
            {
                if (busy)
                {
                    string drivePath = Interpolate.current.tempFolder.Substring(0, 2);
                    long   mb        = IOUtils.GetDiskSpace(Interpolate.current.tempFolder);

                    Logger.Log($"Disk space check for '{drivePath}/': {(mb / 1024f).ToString("0.0")} GB free.", true);

                    if (!Interpolate.canceled && mb < (Config.GetInt("minDiskSpaceGb", 6) * 1024))
                    {
                        Interpolate.Cancel("Running out of disk space!");
                    }
                }

                await Task.Delay(15000);
            }
        }
        static async Task Encode(I.OutMode mode, string framesPath, string outPath, float fps, float resampleFps = -1)
        {
            currentOutFile = outPath;
            string vfrFile = Path.Combine(framesPath.GetParentDir(), Paths.GetFrameOrderFilename(I.current.interpFactor));

            if (!File.Exists(vfrFile))
            {
                bool sbs = Config.GetInt("processingMode") == 1;
                I.Cancel($"Frame order file for this interpolation factor not found!{(sbs ? "\n\nDid you run the interpolation step with the current factor?" : "")}");
                return;
            }

            if (mode == I.OutMode.VidGif)
            {
                await FfmpegEncode.FramesToGifConcat(vfrFile, outPath, fps, true, Config.GetInt("gifColors"), resampleFps);
            }
            else
            {
                await FfmpegEncode.FramesToVideoConcat(vfrFile, outPath, mode, fps, resampleFps);
                await MuxOutputVideo(I.current.inPath, outPath);
                await Loop(currentOutFile, GetLoopTimes());
            }
        }
Exemple #9
0
        static void FfmpegOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            timeSinceLastOutput.Restart();
            if (outLine == null || outLine.Data == null)
            {
                return;
            }
            string line = outLine.Data;

            lastOutputFfmpeg = lastOutputFfmpeg + "\n" + line;
            bool   hidden          = currentLogMode == LogMode.Hidden;
            bool   replaceLastLine = currentLogMode == LogMode.OnlyLastLine;
            string trimmedLine     = line.Remove("q=-0.0").Remove("size=N/A").Remove("bitrate=N/A").TrimWhitespaces();

            Logger.Log(trimmedLine, hidden, replaceLastLine, "ffmpeg");

            if (line.Contains(".srt: Invalid data found"))
            {
                Logger.Log($"Warning: Failed to encode subtitle track {line.Split(':')[2]}. This track will be missing in the output file.");
            }

            if (line.Contains("Could not open file"))
            {
                Interpolate.Cancel($"FFmpeg Error: {line}");
            }

            if (line.Contains("No NVENC capable devices found") || line.Contains("Cannot load nvcuda.dll"))
            {
                Interpolate.Cancel($"FFmpeg Error: {line}\nMake sure you have an NVENC-capable Nvidia GPU.");
            }

            if (!hidden && showProgressBar && line.Contains("time="))
            {
                Regex timeRegex = new Regex("(?<=time=).*(?= )");
                UpdateFfmpegProgress(timeRegex.Match(line).Value);
            }
        }
Exemple #10
0
 private void cancelBtn_Click(object sender, EventArgs e)
 {
     SetTab("interpolation");
     Interpolate.Cancel();
 }
Exemple #11
0
        static void LogOutput(string line, string logFilename, bool err = false)
        {
            if (string.IsNullOrWhiteSpace(line) || line.Length < 6)
            {
                return;
            }

            Stopwatch sw = new Stopwatch();

            sw.Restart();

            if (line.Contains("iVBOR"))
            {
                try
                {
                    string[] split = line.Split(':');
                    //MemoryStream stream = new MemoryStream(Convert.FromBase64String(split[1]));
                    //Image img = Image.FromStream(stream);
                    Logger.Log($"Received image {split[0]} in {sw.ElapsedMilliseconds} ms", true);
                }
                catch (Exception e)
                {
                    Logger.Log($"Failed to decode b64 string - {e}:");
                    Logger.Log(line);
                }
                return;
            }

            Logger.LogToFile(line, false, logFilename);

            if (line.Contains("ff:nocuda-cpu"))
            {
                Logger.Log("WARNING: CUDA-capable GPU device is not available, running on CPU instead!");
            }

            if (!hasShownError && err && line.ToLower().Contains("out of memory"))
            {
                hasShownError = true;
                InterpolateUtils.ShowMessage($"Your GPU ran out of VRAM! Please try a video with a lower resolution or use the Max Video Size option in the settings.\n\n{line}", "Error");
            }

            if (!hasShownError && err && line.ToLower().Contains("modulenotfounderror"))
            {
                hasShownError = true;
                InterpolateUtils.ShowMessage($"A python module is missing.\nCheck {logFilename} for details.\n\n{line}", "Error");
                if (!Python.HasEmbeddedPyFolder())
                {
                    Process.Start("https://github.com/n00mkrad/flowframes/blob/main/PythonDependencies.md");
                }
            }

            if (!hasShownError && line.ToLower().Contains("no longer supports this gpu"))
            {
                hasShownError = true;
                InterpolateUtils.ShowMessage($"Your GPU seems to be outdated and is not supported!\n\n{line}", "Error");
            }

            if (!hasShownError && err && (line.Contains("RuntimeError") || line.Contains("ImportError") || line.Contains("OSError")))
            {
                hasShownError = true;
                InterpolateUtils.ShowMessage($"A python error occured during interpolation!\nCheck {logFilename} for details.\n\n{line}", "Error");
            }

            if (!hasShownError && err && line.Contains("vk") && line.Contains(" failed"))
            {
                hasShownError = true;
                string dain = (Interpolate.current.ai.aiName == Networks.dainNcnn.aiName) ? "\n\nTry reducing the tile size in the AI settings." : "";
                InterpolateUtils.ShowMessage($"A Vulkan error occured during interpolation!\n\n{line}{dain}", "Error");
            }

            if (!hasShownError && err && line.Contains("vkAllocateMemory failed"))
            {
                hasShownError = true;
                bool   usingDain = (Interpolate.current.ai.aiName == Networks.dainNcnn.aiName);
                string msg       = usingDain ? "\n\nTry reducing the tile size in the AI settings." : "Try a lower resolution (Settings -> Max Video Size).";
                InterpolateUtils.ShowMessage($"Vulkan ran out of memory!\n\n{line}{msg}", "Error");
            }

            if (!hasShownError && err && line.Contains("invalid gpu device"))
            {
                hasShownError = true;
                InterpolateUtils.ShowMessage($"A Vulkan error occured during interpolation!\n\n{line}\n\nAre your GPU IDs set correctly?", "Error");
            }

            if (hasShownError)
            {
                Interpolate.Cancel();
            }

            InterpolateUtils.UpdateLastFrameFromInterpOutput(line);
        }