diff --git a/Code/AudioVideo/FFmpegCommands.cs b/Code/AudioVideo/FFmpegCommands.cs index fedf806..b9ced88 100644 --- a/Code/AudioVideo/FFmpegCommands.cs +++ b/Code/AudioVideo/FFmpegCommands.cs @@ -25,20 +25,20 @@ namespace Flowframes static string mpDecDef = "\"mpdecimate\""; static string mpDecAggr = "\"mpdecimate=hi=64*32:lo=64*32:frac=0.1\""; - public static async Task ExtractSceneChanges(string inputFile, string frameFolderPath) + public static async Task ExtractSceneChanges(string inputFile, string frameFolderPath, float rate) { Logger.Log("Extracting scene changes..."); - await VideoToFrames(inputFile, frameFolderPath, false, false, new Size(320, 180), false, true); + await VideoToFrames(inputFile, frameFolderPath, rate, false, false, new Size(320, 180), false, true); bool hiddenLog = Interpolate.currentInputFrameCount <= 50; Logger.Log($"Detected {IOUtils.GetAmountOfFiles(frameFolderPath, false)} scene changes.".Replace(" 0 ", " no "), false, !hiddenLog); } - public static async Task VideoToFrames(string inputFile, string frameFolderPath, bool deDupe, bool delSrc, bool timecodes = true) + public static async Task VideoToFrames(string inputFile, string frameFolderPath, float rate, bool deDupe, bool delSrc, bool timecodes = true) { - await VideoToFrames(inputFile, frameFolderPath, deDupe, delSrc, new Size(), timecodes); + await VideoToFrames(inputFile, frameFolderPath, rate, deDupe, delSrc, new Size(), timecodes); } - public static async Task VideoToFrames(string inputFile, string frameFolderPath, bool deDupe, bool delSrc, Size size, bool timecodes, bool sceneDetect = false) + public static async Task VideoToFrames(string inputFile, string frameFolderPath, 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}" : ""; @@ -49,8 +49,9 @@ namespace Flowframes string fpsFilter = $"\"fps=fps={Interpolate.current.inFps.ToString().Replace(",", ".")}\""; string filters = FormatUtils.ConcatStrings(new string[] { scnDetect, mpStr/*, fpsFilter*/ } ); string vf = filters.Length > 2 ? $"-vf {filters}" : ""; + string rateArg = (rate > 0) ? $" -r {rate.ToStringDot()}" : ""; string pad = Padding.inputFrames.ToString(); - string args = $"-i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} {vf} {sizeStr} \"{frameFolderPath}/%{pad}d.png\""; + string args = $"{rateArg} -i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} {vf} {sizeStr} \"{frameFolderPath}/%{pad}d.png\""; AvProcess.LogMode logMode = Interpolate.currentInputFrameCount > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden; await AvProcess.RunFfmpeg(args, logMode); if (!sceneDetect) Logger.Log($"Extracted {IOUtils.GetAmountOfFiles(frameFolderPath, false, "*.png")} frames from input.", false, true); diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index 849d3f5..b306925 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -77,13 +77,13 @@ namespace Flowframes if (Config.GetBool("scnDetect")) { Program.mainForm.SetStatus("Extracting scenes from video..."); - await FFmpegCommands.ExtractSceneChanges(inPath, Path.Combine(current.tempFolder, Paths.scenesDir)); + await FFmpegCommands.ExtractSceneChanges(inPath, Path.Combine(current.tempFolder, Paths.scenesDir), current.inFps); await Task.Delay(10); } Program.mainForm.SetStatus("Extracting frames from video..."); bool mpdecimate = Config.GetInt("dedupMode") == 2; - await FFmpegCommands.VideoToFrames(inPath, outPath, mpdecimate, false, Utils.GetOutputResolution(inPath, true), false); + await FFmpegCommands.VideoToFrames(inPath, outPath, current.inFps, mpdecimate, false, Utils.GetOutputResolution(inPath, true), false); if (mpdecimate) { diff --git a/Code/Main/InterpolateSteps.cs b/Code/Main/InterpolateSteps.cs index 1b2a192..2d9c125 100644 --- a/Code/Main/InterpolateSteps.cs +++ b/Code/Main/InterpolateSteps.cs @@ -70,7 +70,7 @@ namespace Flowframes.Main return; } Program.mainForm.SetStatus("Extracting scenes from video..."); - await FFmpegCommands.ExtractSceneChanges(current.inPath, scenesPath); + await FFmpegCommands.ExtractSceneChanges(current.inPath, scenesPath, current.inFps); await Task.Delay(10); } diff --git a/Code/OS/AiProcess.cs b/Code/OS/AiProcess.cs index ef0effe..2775fe8 100644 --- a/Code/OS/AiProcess.cs +++ b/Code/OS/AiProcess.cs @@ -49,12 +49,12 @@ namespace Flowframes logStr += " - Waiting for encoding to finish..."; Logger.Log(logStr); processTime.Stop(); - while (Program.busy) + while (Interpolate.currentlyUsingAutoEnc && Program.busy) { if(AvProcess.lastProcess != null && !AvProcess.lastProcess.HasExited && AvProcess.lastTask == AvProcess.TaskType.Encode) { string lastLine = AvProcess.lastOutputFfmpeg.SplitIntoLines().Last(); - Logger.Log(lastLine.Trim(), false, Logger.GetLastLine().Contains("frame")); + Logger.Log(lastLine.Trim().TrimWhitespaces(), false, Logger.GetLastLine().Contains("frame")); } await Task.Delay(1000); } diff --git a/Code/UI/UtilsTab.cs b/Code/UI/UtilsTab.cs index aa329ae..54d5e7f 100644 --- a/Code/UI/UtilsTab.cs +++ b/Code/UI/UtilsTab.cs @@ -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), false, false, false); + await FFmpegCommands.VideoToFrames(videoPath, Path.Combine(outPath, Paths.framesDir), 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"));