mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-09-01 19:51:28 +02:00
Progress bar for async frame counting with ffmpeg
This commit is contained in:
@@ -462,10 +462,5 @@ namespace Flowframes.Main
|
||||
foreach (string frame in sceneFramesToDelete)
|
||||
IOUtils.TryDeleteIfExists(Path.Combine(sceneFramesPath, frame + ".png"));
|
||||
}
|
||||
|
||||
public static void UpdateVideoDuration(string path)
|
||||
{
|
||||
Program.mainForm.currInDuration = FfmpegCommands.GetDuration(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,13 @@ namespace Flowframes
|
||||
lastOutputFfmpeg += "\n";
|
||||
lastOutputFfmpeg = lastOutputFfmpeg + line;
|
||||
Logger.Log(line, true, false, "ffmpeg");
|
||||
|
||||
if (showProgressBar && line.Contains("time="))
|
||||
{
|
||||
Logger.Log($"showProgressBar, contains: {line.Contains("time=")}", true, false, "ffmpeg");
|
||||
Regex timeRegex = new Regex("(?<=time=).*(?= )");
|
||||
UpdateFfmpegProgress(timeRegex.Match(line).Value);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFfmpegOutput (string args)
|
||||
@@ -111,11 +118,12 @@ namespace Flowframes
|
||||
return output;
|
||||
}
|
||||
|
||||
public static async Task<string> GetFfmpegOutputAsync(string args, bool setBusy = false)
|
||||
public static async Task<string> GetFfmpegOutputAsync(string args, bool setBusy = false, bool progressBar = false)
|
||||
{
|
||||
timeSinceLastOutput.Restart();
|
||||
if (Program.busy) setBusy = false;
|
||||
lastOutputFfmpeg = "";
|
||||
showProgressBar = progressBar;
|
||||
Process ffmpeg = OSUtils.NewProcess(true);
|
||||
lastProcess = ffmpeg;
|
||||
ffmpeg.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffmpeg.exe -hide_banner -y -stats {args}";
|
||||
|
||||
@@ -103,35 +103,19 @@ namespace Flowframes
|
||||
return new Size(0, 0);
|
||||
}
|
||||
|
||||
public static int GetFrameCount(string inputFile)
|
||||
{
|
||||
int frames = 0;
|
||||
|
||||
Logger.Log("Reading frame count using ffprobe.", true, false, "ffmpeg");
|
||||
frames = ReadFrameCountFfprobe(inputFile, Config.GetBool("ffprobeCountFrames")); // Try reading frame count with ffprobe
|
||||
if (frames > 0)
|
||||
return frames;
|
||||
|
||||
Logger.Log($"Failed to get frame count using ffprobe (frames = {frames}). Reading frame count using ffmpeg.", true, false, "ffmpeg");
|
||||
frames = ReadFrameCountFfmpeg(inputFile); // Try reading frame count with ffmpeg
|
||||
if (frames > 0)
|
||||
return frames;
|
||||
|
||||
Logger.Log("Failed to get total frame count of video.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static async Task<int> GetFrameCountAsync(string inputFile)
|
||||
{
|
||||
Logger.Log($"GetFrameCountAsync('{inputFile}') - Trying ffprobe first.", true, false, "ffmpeg");
|
||||
int frames = 0;
|
||||
|
||||
Logger.Log("Reading frame count using ffprobe.", true, false, "ffmpeg");
|
||||
frames = await ReadFrameCountFfprobeAsync(inputFile, Config.GetBool("ffprobeCountFrames")); // Try reading frame count with ffprobe
|
||||
|
||||
if (frames > 0)
|
||||
return frames;
|
||||
|
||||
Logger.Log($"Failed to get frame count using ffprobe (frames = {frames}). Reading frame count using ffmpeg.", true, false, "ffmpeg");
|
||||
frames = await ReadFrameCountFfmpegAsync(inputFile); // Try reading frame count with ffmpeg
|
||||
|
||||
if (frames > 0)
|
||||
return frames;
|
||||
|
||||
@@ -204,7 +188,7 @@ namespace Flowframes
|
||||
static async Task<int> ReadFrameCountFfmpegAsync (string inputFile)
|
||||
{
|
||||
string args = $" -loglevel panic -i {inputFile.Wrap()} -map 0:v:0 -c copy -f null - ";
|
||||
string info = await GetFfmpegOutputAsync(args, true);
|
||||
string info = await GetFfmpegOutputAsync(args, true, true);
|
||||
try
|
||||
{
|
||||
string[] lines = info.SplitIntoLines();
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace Flowframes.UI
|
||||
Logger.Log("Your file seems to be on an HDD or USB device. It is recommended to interpolate videos on an SSD drive for best performance.");
|
||||
|
||||
Logger.Log("Loading metadata...");
|
||||
Program.mainForm.currInDuration = FfmpegCommands.GetDuration(path);
|
||||
int frameCount = await InterpolateUtils.GetInputFrameCountAsync(path);
|
||||
|
||||
string fpsStr = "Not Found";
|
||||
float fps = await IOUtils.GetFpsFolderOrVideo(path);
|
||||
fpsInTbox.Text = fps.ToString();
|
||||
@@ -50,7 +50,6 @@ namespace Flowframes.UI
|
||||
|
||||
Program.mainForm.currInFps = fps;
|
||||
Program.mainForm.currInFrames = frameCount;
|
||||
InterpolateUtils.UpdateVideoDuration(path);
|
||||
Program.mainForm.UpdateInputInfo();
|
||||
CheckExistingFolder(path, outputTbox.Text.Trim());
|
||||
await Task.Delay(10);
|
||||
|
||||
Reference in New Issue
Block a user