1
mirror of https://github.com/n00mkrad/flowframes synced 2024-09-29 14:38:03 +02:00

Fixed problem with printing autoenc log

This commit is contained in:
N00MKRAD 2021-01-06 22:51:04 +01:00
parent 22b3ae2f18
commit abdc846fd3
4 changed files with 18 additions and 30 deletions

View File

@ -13,6 +13,8 @@ namespace Flowframes
class AvProcess
{
public static Process lastProcess;
public enum TaskType { ExtractFrames, Encode, GetInfo, Merge, Other };
public static TaskType lastTask = TaskType.Other;
public static string lastOutputFfmpeg;
public static string lastOutputGifski;
@ -20,17 +22,18 @@ namespace Flowframes
public enum LogMode { Visible, OnlyLastLine, Hidden }
static LogMode currentLogMode;
public static async Task RunFfmpeg(string args, LogMode logMode)
public static async Task RunFfmpeg(string args, LogMode logMode, TaskType taskType = TaskType.Other)
{
await RunFfmpeg(args, "", logMode);
}
public static async Task RunFfmpeg(string args, string workingDir, LogMode logMode)
public static async Task RunFfmpeg(string args, string workingDir, LogMode logMode, TaskType taskType = TaskType.Other)
{
lastOutputFfmpeg = "";
currentLogMode = logMode;
Process ffmpeg = OSUtils.NewProcess(true);
lastProcess = ffmpeg;
lastTask = taskType;
if(!string.IsNullOrWhiteSpace(workingDir))
ffmpeg.StartInfo.Arguments = $"{GetCmdArg()} cd /D {workingDir.Wrap()} & {Path.Combine(GetAvDir(), "ffmpeg.exe").Wrap()} -hide_banner -loglevel warning -y -stats {args}";
else

View File

@ -72,7 +72,7 @@ namespace Flowframes
string args = $" -loglevel panic -f concat -safe 0 -i {concatFile.Wrap()} {pngComprArg} -pix_fmt rgb24 -vsync 0 -vf {divisionFilter} \"{outpath}/%{Padding.inputFrames}d.png\"";
AvProcess.LogMode logMode = IOUtils.GetAmountOfFiles(inpath, false) > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden;
await AvProcess.RunFfmpeg(args, logMode);
await AvProcess.RunFfmpeg(args, logMode, AvProcess.TaskType.ExtractFrames);
if (delSrc)
DeleteSource(inpath);
}
@ -87,7 +87,7 @@ namespace Flowframes
{
string hdrStr = hdr ? hdrFilter : "";
string args = $"-i {inputFile.Wrap()} {pngComprArg} {hdrStr }-vf \"select=eq(n\\,{frameNum})\" -vframes 1 {outputPath.Wrap()}";
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden);
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden, AvProcess.TaskType.ExtractFrames);
if (delSrc)
DeleteSource(inputFile);
}
@ -109,7 +109,7 @@ namespace Flowframes
string vf = (resampleFps <= 0) ? "" : $"-vf fps=fps={resampleFps.ToString().Replace(",", ".")}";
string extraArgs = Config.Get("ffEncArgs");
string args = $"-loglevel error -vsync 0 -f concat -r {rate} -i {vfrFilename} {encArgs} {vf} {extraArgs} -threads {Config.GetInt("ffEncThreads")} {outPath.Wrap()}";
await AvProcess.RunFfmpeg(args, framesFile.GetParentDir(), logMode);
await AvProcess.RunFfmpeg(args, framesFile.GetParentDir(), logMode, AvProcess.TaskType.Encode);
}
public static async Task ConcatVideos(string concatFile, string outPath, int looptimes = -1)
@ -118,7 +118,7 @@ namespace Flowframes
string loopStr = (looptimes > 0) ? $"-stream_loop {looptimes}" : "";
string vfrFilename = Path.GetFileName(concatFile);
string args = $" {loopStr} -vsync 1 -f concat -i {vfrFilename} -c copy -movflags +faststart {outPath.Wrap()}";
await AvProcess.RunFfmpeg(args, concatFile.GetParentDir(), AvProcess.LogMode.Hidden);
await AvProcess.RunFfmpeg(args, concatFile.GetParentDir(), AvProcess.LogMode.Hidden, AvProcess.TaskType.Merge);
}
public static async Task ConvertFramerate(string inputPath, string outPath, bool useH265, int crf, float newFps, bool delSrc = false)
@ -142,7 +142,7 @@ namespace Flowframes
string vf = FormatUtils.ConcatStrings(new string[] { paletteFilter, fpsFilter });
string rate = fps.ToStringDot();
string args = $"-loglevel error -f concat -r {rate} -i {vfrFilename.Wrap()} -f gif {vf} {outPath.Wrap()}";
await AvProcess.RunFfmpeg(args, framesFile.GetParentDir(), AvProcess.LogMode.OnlyLastLine);
await AvProcess.RunFfmpeg(args, framesFile.GetParentDir(), AvProcess.LogMode.OnlyLastLine, AvProcess.TaskType.Encode);
}
public static async Task LoopVideo(string inputFile, int times, bool delSrc = false)
@ -187,7 +187,7 @@ namespace Flowframes
args = args.Replace("-c:a", "-an");
if (audioKbps < 0)
args = args.Replace($" -b:a {audioKbps}", "");
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine);
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine, AvProcess.TaskType.Encode);
if (delSrc)
DeleteSource(inputFile);
}

View File

@ -85,25 +85,7 @@ namespace Flowframes.Main
currentInputFrameCount = await InterpolateUtils.GetInputFrameCountAsync(current.inPath);
AiProcess.filenameMap.Clear();
ExtractFrames(current.inPath, current.framesFolder, false, true);
// Program.mainForm.SetStatus("Extracting frames from video...");
// await FFmpegCommands.VideoToFrames(current.inPath, current.framesFolder, Config.GetInt("dedupMode") == 2, false, InterpolateUtils.GetOutputResolution(current.inPath, true), false);
//
// if (extractAudio)
// {
// string audioFile = Path.Combine(current.tempFolder, "audio.m4a");
// if (audioFile != null && !File.Exists(audioFile))
// await FFmpegCommands.ExtractAudio(current.inPath, audioFile);
// }
// if (!canceled && Config.GetBool("enableLoop") && Config.GetInt("timingMode") != 1)
// {
// string lastFrame = IOUtils.GetHighestFrameNumPath(current.framesFolder);
// int newNum = Path.GetFileName(lastFrame).GetInt() + 1;
// string newFilename = Path.Combine(lastFrame.GetParentDir(), newNum.ToString().PadLeft(Padding.inputFrames, '0') + ".png");
// string firstFrame = new DirectoryInfo(current.framesFolder).GetFiles("*.png")[0].FullName;
// File.Copy(firstFrame, newFilename);
// }
await ExtractFrames(current.inPath, current.framesFolder, false, true);
}
public static async Task DoInterpolate()

View File

@ -49,10 +49,13 @@ namespace Flowframes
logStr += " - Waiting for encoding to finish...";
Logger.Log(logStr);
processTime.Stop();
while (AvProcess.lastProcess != null && !AvProcess.lastProcess.HasExited)
while (Program.busy)
{
string lastLine = AvProcess.lastOutputFfmpeg.SplitIntoLines().Last();
Logger.Log(lastLine.Trim(), false, Logger.GetLastLine().Contains("frame"));
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"));
}
await Task.Delay(1000);
}
}