diff --git a/Code/Data/MediaFile.cs b/Code/Data/MediaFile.cs index 2c30a43..01c86d5 100644 --- a/Code/Data/MediaFile.cs +++ b/Code/Data/MediaFile.cs @@ -100,7 +100,7 @@ namespace Flowframes.Data // } } - public async Task Initialize(bool progressBar = true) + public async Task Initialize(bool progressBar = true, bool countFrames = true) { Logger.Log($"MediaFile {Name}: Initializing", true); @@ -110,7 +110,7 @@ namespace Flowframes.Data await InitializeSequence(); await LoadFormatInfo(ImportPath); - AllStreams = await FfmpegUtils.GetStreams(ImportPath, progressBar, StreamCount, (Fraction)InputRate, true); + AllStreams = await FfmpegUtils.GetStreams(ImportPath, progressBar, StreamCount, (Fraction)InputRate, countFrames); VideoStreams = AllStreams.Where(x => x.Type == Stream.StreamType.Video).Select(x => (VideoStream)x).ToList(); AudioStreams = AllStreams.Where(x => x.Type == Stream.StreamType.Audio).Select(x => (AudioStream)x).ToList(); SubtitleStreams = AllStreams.Where(x => x.Type == Stream.StreamType.Subtitle).Select(x => (SubtitleStream)x).ToList(); diff --git a/Code/Form1.cs b/Code/Form1.cs index 12687bf..98ef616 100644 --- a/Code/Form1.cs +++ b/Code/Form1.cs @@ -320,6 +320,9 @@ namespace Flowframes public void runBtn_Click(object sender, EventArgs e) { + if (Interpolate.currentMediaFile == null || !Interpolate.currentMediaFile.Initialized) + return; + ValidateFactor(); if (!BatchProcessing.busy) // Don't load values from gui if batch processing is used diff --git a/Code/Main/BatchProcessing.cs b/Code/Main/BatchProcessing.cs index c2b7615..7ec5c44 100644 --- a/Code/Main/BatchProcessing.cs +++ b/Code/Main/BatchProcessing.cs @@ -1,4 +1,5 @@ -using Flowframes.Forms; +using Flowframes.Data; +using Flowframes.Forms; using Flowframes.IO; using Flowframes.Os; using System; @@ -83,6 +84,11 @@ namespace Flowframes.Main if (IoUtils.IsPathDirectory(entry.inPath)) fname = Path.GetDirectoryName(entry.inPath); Logger.Log($"Queue: Processing {fname} ({entry.interpFactor}x {entry.ai.AiNameShort})."); + MediaFile mf = new MediaFile(entry.inPath); + await mf.Initialize(); + + Interpolate.currentMediaFile = mf; + Program.mainForm.LoadBatchEntry(entry); // Load entry into GUI Interpolate.currentSettings = entry; Program.mainForm.runBtn_Click(null, null); diff --git a/Code/Media/AvProcess.cs b/Code/Media/AvProcess.cs index 42b2dd2..99632c3 100644 --- a/Code/Media/AvProcess.cs +++ b/Code/Media/AvProcess.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Flowframes.MiscUtils; using Microsoft.VisualBasic; using Flowframes.Media; +using System.Windows.Input; namespace Flowframes { @@ -101,7 +102,7 @@ namespace Flowframes return processOutput; } - public static string GetFfmpegDefaultArgs (string loglevel = "warning") + public static string GetFfmpegDefaultArgs(string loglevel = "warning") { return $"-hide_banner -stats -loglevel {loglevel} -y"; } @@ -114,9 +115,10 @@ namespace Flowframes public bool SetBusy { get; set; } = false; } - public static async Task RunFfprobe(FfprobeSettings settings) + public static async Task RunFfprobe(FfprobeSettings settings, bool asyncOutput = false) { bool show = Config.GetInt(Config.Key.cmdDebugMode) > 0; + string processOutput = ""; Process ffprobe = OsUtils.NewProcess(!show); NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch(); @@ -126,11 +128,14 @@ namespace Flowframes if (settings.LoggingMode != LogMode.Hidden) Logger.Log("Running FFprobe...", false); Logger.Log($"ffprobe -v {settings.LogLevel} {settings.Args}", true, false, "ffmpeg"); + if (!asyncOutput) + return await Task.Run(() => GetProcOutput(ffprobe)); + if (!show) { string[] ignore = new string[0]; - ffprobe.OutputDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", settings.LoggingMode, false); timeSinceLastOutput.sw.Restart(); }; - ffprobe.ErrorDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", settings.LoggingMode, false); timeSinceLastOutput.sw.Restart(); }; + ffprobe.OutputDataReceived += (sender, outLine) => { processOutput += outLine + Environment.NewLine; }; + ffprobe.ErrorDataReceived += (sender, outLine) => { processOutput += outLine + Environment.NewLine; }; } ffprobe.Start(); @@ -148,44 +153,16 @@ namespace Flowframes return processOutput; } - public static async Task RunFfprobe(string args, LogMode logMode = LogMode.Hidden, string loglevel = "quiet") + private static string GetProcOutput (Process proc) { - bool show = Config.GetInt(Config.Key.cmdDebugMode) > 0; - string processOutput = ""; - Process ffprobe = OsUtils.NewProcess(!show); - NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch(); - lastAvProcess = ffprobe; - - if (string.IsNullOrWhiteSpace(loglevel)) - loglevel = defLogLevel; - - ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe -v {loglevel} {args}"; - - if (logMode != LogMode.Hidden) Logger.Log("Running FFprobe...", false); - Logger.Log($"ffprobe -v {loglevel} {args}", true, false, "ffmpeg"); - - if (!show) - { - ffprobe.OutputDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); }; - ffprobe.ErrorDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); }; - } - - ffprobe.Start(); - ffprobe.PriorityClass = ProcessPriorityClass.BelowNormal; - - if (!show) - { - ffprobe.BeginOutputReadLine(); - ffprobe.BeginErrorReadLine(); - } - - while (!ffprobe.HasExited) await Task.Delay(10); - while (timeSinceLastOutput.ElapsedMs < 200) await Task.Delay(50); - - return processOutput; + proc.Start(); + proc.PriorityClass = ProcessPriorityClass.BelowNormal; + string output = proc.StandardOutput.ReadToEnd(); + proc.WaitForExit(); + return output; } - public static string GetFfprobeOutput (string args) + public static string GetFfprobeOutput(string args) { Process ffprobe = OsUtils.NewProcess(true); ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe.exe {args}"; @@ -197,23 +174,23 @@ namespace Flowframes if (!string.IsNullOrWhiteSpace(err)) output += "\n" + err; return output; } - - static string GetAvDir () + + static string GetAvDir() { return Path.Combine(Paths.GetPkgPath(), Paths.audioVideoDir); } - static string GetCmdArg () + static string GetCmdArg() { return "/C"; } - public static async Task SetBusyWhileRunning () + public static async Task SetBusyWhileRunning() { if (Program.busy) return; await Task.Delay(100); - while(!lastAvProcess.HasExited) + while (!lastAvProcess.HasExited) await Task.Delay(10); } } diff --git a/Code/Media/FfmpegCommands.cs b/Code/Media/FfmpegCommands.cs index 78b86bb..2241d03 100644 --- a/Code/Media/FfmpegCommands.cs +++ b/Code/Media/FfmpegCommands.cs @@ -187,7 +187,8 @@ namespace Flowframes public static async Task ReadFrameCountFfprobePacketCount(string filePath) { - string output = await RunFfprobe($"-select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 {filePath.Wrap()}", LogMode.Hidden, "error"); + FfprobeSettings settings = new FfprobeSettings() { Args = $"-select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 {filePath.Wrap()}", LoggingMode = LogMode.Hidden, LogLevel = "error" }; + string output = await RunFfprobe(settings); string[] lines = output.SplitIntoLines().Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); if (lines == null || lines.Length < 1) @@ -198,8 +199,8 @@ namespace Flowframes public static async Task ReadFrameCountFfprobe(string filePath) { - string args = $"-threads 0 -select_streams v:0 -show_entries stream=nb_frames -of default=noprint_wrappers=1 {filePath.Wrap()}"; - string info = await RunFfprobe(args, LogMode.Hidden, "panic"); + FfprobeSettings s = new FfprobeSettings() { Args = $"-threads 0 -select_streams v:0 -show_entries stream=nb_frames -of default=noprint_wrappers=1 {filePath.Wrap()}", LoggingMode = LogMode.Hidden, LogLevel = "panic" }; + string info = await RunFfprobe(s); string[] entries = info.SplitIntoLines(); try diff --git a/Code/Ui/MainUiFunctions.cs b/Code/Ui/MainUiFunctions.cs index 369a99f..c2c28f7 100644 --- a/Code/Ui/MainUiFunctions.cs +++ b/Code/Ui/MainUiFunctions.cs @@ -19,6 +19,7 @@ namespace Flowframes.Ui { 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(); diff --git a/Code/Ui/UiUtils.cs b/Code/Ui/UiUtils.cs index 511f168..9d3c37c 100644 --- a/Code/Ui/UiUtils.cs +++ b/Code/Ui/UiUtils.cs @@ -85,6 +85,12 @@ namespace Flowframes.Ui { Logger.Log($"MessageBox: {text} ({type}){(BatchProcessing.busy ? "[Batch Mode - Will not display messagebox]" : "")}", true); + if (BatchProcessing.busy) + { + Logger.Log(text); + return new DialogResult(); + } + if (BatchProcessing.busy) return new DialogResult();