mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-24 04:09:29 +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);
|
Logger.Log($"MediaFile {Name}: Initializing", true);
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ namespace Flowframes.Data
|
|||||||
await InitializeSequence();
|
await InitializeSequence();
|
||||||
|
|
||||||
await LoadFormatInfo(ImportPath);
|
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();
|
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();
|
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();
|
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)
|
public void runBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (Interpolate.currentMediaFile == null || !Interpolate.currentMediaFile.Initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
ValidateFactor();
|
ValidateFactor();
|
||||||
|
|
||||||
if (!BatchProcessing.busy) // Don't load values from gui if batch processing is used
|
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.IO;
|
||||||
using Flowframes.Os;
|
using Flowframes.Os;
|
||||||
using System;
|
using System;
|
||||||
@@ -83,6 +84,11 @@ namespace Flowframes.Main
|
|||||||
if (IoUtils.IsPathDirectory(entry.inPath)) fname = Path.GetDirectoryName(entry.inPath);
|
if (IoUtils.IsPathDirectory(entry.inPath)) fname = Path.GetDirectoryName(entry.inPath);
|
||||||
Logger.Log($"Queue: Processing {fname} ({entry.interpFactor}x {entry.ai.AiNameShort}).");
|
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
|
Program.mainForm.LoadBatchEntry(entry); // Load entry into GUI
|
||||||
Interpolate.currentSettings = entry;
|
Interpolate.currentSettings = entry;
|
||||||
Program.mainForm.runBtn_Click(null, null);
|
Program.mainForm.runBtn_Click(null, null);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
|||||||
using Flowframes.MiscUtils;
|
using Flowframes.MiscUtils;
|
||||||
using Microsoft.VisualBasic;
|
using Microsoft.VisualBasic;
|
||||||
using Flowframes.Media;
|
using Flowframes.Media;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Flowframes
|
namespace Flowframes
|
||||||
{
|
{
|
||||||
@@ -101,7 +102,7 @@ namespace Flowframes
|
|||||||
return processOutput;
|
return processOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetFfmpegDefaultArgs (string loglevel = "warning")
|
public static string GetFfmpegDefaultArgs(string loglevel = "warning")
|
||||||
{
|
{
|
||||||
return $"-hide_banner -stats -loglevel {loglevel} -y";
|
return $"-hide_banner -stats -loglevel {loglevel} -y";
|
||||||
}
|
}
|
||||||
@@ -114,9 +115,10 @@ namespace Flowframes
|
|||||||
public bool SetBusy { get; set; } = false;
|
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;
|
bool show = Config.GetInt(Config.Key.cmdDebugMode) > 0;
|
||||||
|
|
||||||
string processOutput = "";
|
string processOutput = "";
|
||||||
Process ffprobe = OsUtils.NewProcess(!show);
|
Process ffprobe = OsUtils.NewProcess(!show);
|
||||||
NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch();
|
NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch();
|
||||||
@@ -126,11 +128,14 @@ namespace Flowframes
|
|||||||
if (settings.LoggingMode != LogMode.Hidden) Logger.Log("Running FFprobe...", false);
|
if (settings.LoggingMode != LogMode.Hidden) Logger.Log("Running FFprobe...", false);
|
||||||
Logger.Log($"ffprobe -v {settings.LogLevel} {settings.Args}", true, false, "ffmpeg");
|
Logger.Log($"ffprobe -v {settings.LogLevel} {settings.Args}", true, false, "ffmpeg");
|
||||||
|
|
||||||
|
if (!asyncOutput)
|
||||||
|
return await Task.Run(() => GetProcOutput(ffprobe));
|
||||||
|
|
||||||
if (!show)
|
if (!show)
|
||||||
{
|
{
|
||||||
string[] ignore = new string[0];
|
string[] ignore = new string[0];
|
||||||
ffprobe.OutputDataReceived += (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) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", settings.LoggingMode, false); timeSinceLastOutput.sw.Restart(); };
|
ffprobe.ErrorDataReceived += (sender, outLine) => { processOutput += outLine + Environment.NewLine; };
|
||||||
}
|
}
|
||||||
|
|
||||||
ffprobe.Start();
|
ffprobe.Start();
|
||||||
@@ -148,44 +153,16 @@ namespace Flowframes
|
|||||||
return processOutput;
|
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;
|
proc.Start();
|
||||||
string processOutput = "";
|
proc.PriorityClass = ProcessPriorityClass.BelowNormal;
|
||||||
Process ffprobe = OsUtils.NewProcess(!show);
|
string output = proc.StandardOutput.ReadToEnd();
|
||||||
NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch();
|
proc.WaitForExit();
|
||||||
lastAvProcess = ffprobe;
|
return output;
|
||||||
|
|
||||||
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();
|
public static string GetFfprobeOutput(string args)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
Process ffprobe = OsUtils.NewProcess(true);
|
Process ffprobe = OsUtils.NewProcess(true);
|
||||||
ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe.exe {args}";
|
ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe.exe {args}";
|
||||||
@@ -198,22 +175,22 @@ namespace Flowframes
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetAvDir ()
|
static string GetAvDir()
|
||||||
{
|
{
|
||||||
return Path.Combine(Paths.GetPkgPath(), Paths.audioVideoDir);
|
return Path.Combine(Paths.GetPkgPath(), Paths.audioVideoDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetCmdArg ()
|
static string GetCmdArg()
|
||||||
{
|
{
|
||||||
return "/C";
|
return "/C";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task SetBusyWhileRunning ()
|
public static async Task SetBusyWhileRunning()
|
||||||
{
|
{
|
||||||
if (Program.busy) return;
|
if (Program.busy) return;
|
||||||
|
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
while(!lastAvProcess.HasExited)
|
while (!lastAvProcess.HasExited)
|
||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,8 @@ namespace Flowframes
|
|||||||
|
|
||||||
public static async Task<int> ReadFrameCountFfprobePacketCount(string filePath)
|
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();
|
string[] lines = output.SplitIntoLines().Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
|
||||||
|
|
||||||
if (lines == null || lines.Length < 1)
|
if (lines == null || lines.Length < 1)
|
||||||
@@ -198,8 +199,8 @@ namespace Flowframes
|
|||||||
|
|
||||||
public static async Task<int> ReadFrameCountFfprobe(string filePath)
|
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()}";
|
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(args, LogMode.Hidden, "panic");
|
string info = await RunFfprobe(s);
|
||||||
string[] entries = info.SplitIntoLines();
|
string[] entries = info.SplitIntoLines();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Flowframes.Ui
|
|||||||
{
|
{
|
||||||
public static async Task InitInput (TextBox outputTbox, TextBox inputTbox, TextBox fpsInTbox, bool start = false)
|
public static async Task InitInput (TextBox outputTbox, TextBox inputTbox, TextBox fpsInTbox, bool start = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
Program.mainForm.SetTab("interpolate");
|
Program.mainForm.SetTab("interpolate");
|
||||||
Program.mainForm.ResetInputInfo();
|
Program.mainForm.ResetInputInfo();
|
||||||
string path = inputTbox.Text.Trim();
|
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);
|
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)
|
if (BatchProcessing.busy)
|
||||||
return new DialogResult();
|
return new DialogResult();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user