mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-16 16:37:48 +01:00
Frame counting is reliable now
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<string> RunFfprobe(FfprobeSettings settings)
|
||||
public static async Task<string> 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<string> 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(); };
|
||||
proc.Start();
|
||||
proc.PriorityClass = ProcessPriorityClass.BelowNormal;
|
||||
string output = proc.StandardOutput.ReadToEnd();
|
||||
proc.WaitForExit();
|
||||
return output;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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}";
|
||||
@@ -198,22 +175,22 @@ namespace Flowframes
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,8 @@ namespace Flowframes
|
||||
|
||||
public static async Task<int> 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<int> 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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user