FPS limiting now works with RIFE-NCNN-VS, as well as renaming existing files to avoid overwriting

This commit is contained in:
n00mkrad
2022-07-22 01:26:47 +02:00
parent 9213e79abb
commit f587f70c56
4 changed files with 42 additions and 30 deletions

View File

@@ -25,7 +25,7 @@ namespace Flowframes.Data
{
get
{
return new List<AI> { rifeCuda, rifeNcnnVs, rifeNcnn, flavrCuda, dainNcnn, xvfiCuda, /* ifrnetNcnn */ };
return new List<AI> { rifeCuda, rifeNcnnVs, rifeNcnn, flavrCuda, dainNcnn, xvfiCuda, ifrnetNcnn };
}
}

View File

@@ -72,6 +72,23 @@ namespace Flowframes.Main
}
}
public static async Task<string> GetPipedFfmpegCmd()
{
string encArgs = FfmpegUtils.GetEncArgs(FfmpegUtils.GetCodec(I.currentSettings.outMode), (I.currentSettings.ScaledResolution.IsEmpty ? I.currentSettings.InputResolution : I.currentSettings.ScaledResolution), I.currentSettings.outFps.GetFloat(), true).FirstOrDefault();
string max = Config.Get(Config.Key.maxFps);
Fraction maxFps = max.Contains("/") ? new Fraction(max) : new Fraction(max.GetFloat());
bool fpsLimit = maxFps.GetFloat() > 0f && I.currentSettings.outFps.GetFloat() > maxFps.GetFloat();
VidExtraData extraData = await FfmpegCommands.GetVidExtraInfo(I.currentSettings.inPath);
string extraArgs = FfmpegEncode.GetFfmpegExportArgs(fpsLimit ? maxFps : new Fraction(), extraData);
I.currentSettings.FullOutPath = Path.Combine(I.currentSettings.outPath, await IoUtils.GetCurrentExportFilename(fpsLimit, true));
IoUtils.RenameExistingFile(I.currentSettings.FullOutPath);
return $"{encArgs} {extraArgs} {I.currentSettings.FullOutPath.Wrap()}";
}
static async Task ExportImageSequence (string framesPath, bool stepByStep)
{
Program.mainForm.SetStatus("Copying output frames...");

View File

@@ -31,9 +31,26 @@ namespace Flowframes.Media
inArg = $"-i \"{linksDir}/%{Padding.interpFrames}d{GetConcatFileExt(framesFile)}\"";
}
string extraArgs = Config.Get(Config.Key.ffEncArgs);
fps = fps / new Fraction(itsScale);
string args = "";
for(int i = 0; i < encArgs.Length; i++)
{
string pre = i == 0 ? "" : $" && ffmpeg {AvProcess.GetFfmpegDefaultArgs()}";
string post = (i == 0 && encArgs.Length > 1) ? $"-f null -" : outPath.Wrap();
string fs = (!isChunk && outMode == Interpolate.OutMode.VidMp4) ? $"-movflags +faststart" : "";
args += $"{pre} -vsync 0 -r {fps} {inArg} {encArgs[i]} {GetFfmpegExportArgs(resampleFps, extraData)} -threads {Config.GetInt(Config.Key.ffEncThreads)} {fs} {post} ";
}
await RunFfmpeg(args, framesFile.GetParentDir(), logMode, !isChunk);
IoUtils.TryDeleteIfExists(linksDir);
}
public static string GetFfmpegExportArgs (Fraction resampleFps, VidExtraData extraData)
{
List<string> filters = new List<string>();
string extraArgs = "";
if (resampleFps.GetFloat() >= 0.1f)
filters.Add($"fps=fps={resampleFps}");
@@ -45,22 +62,10 @@ namespace Flowframes.Media
extraArgs += $" -colorspace {extraData.colorSpace} -color_primaries {extraData.colorPrimaries} -color_trc {extraData.colorTransfer} -color_range:v \"{extraData.colorRange}\"";
}
string vf = filters.Count > 0 ? $"-vf {string.Join(",", filters)}" : "";
fps = fps / new Fraction(itsScale);
if (!string.IsNullOrWhiteSpace(extraData.displayRatio) && !extraData.displayRatio.MatchesWildcard("*N/A*"))
extraArgs += $"-aspect {extraData.displayRatio}";
string args = "";
for(int i = 0; i < encArgs.Length; i++)
{
string pre = i == 0 ? "" : $" && ffmpeg {AvProcess.GetFfmpegDefaultArgs()}";
string post = (i == 0 && encArgs.Length > 1) ? $"-f null -" : outPath.Wrap();
string fs = (!isChunk && outMode == Interpolate.OutMode.VidMp4) ? $"-movflags +faststart" : "";
args += $"{pre} -vsync 0 -r {fps} {inArg} {encArgs[i]} {vf} {GetAspectArg(extraData)} {extraArgs} -threads {Config.GetInt(Config.Key.ffEncThreads)} {fs} {post} ";
}
//string argsOld = $"-vsync 0 -r {fps} {inArg} {encArgs} {vf} {GetAspectArg(extraData)} {extraArgs} -threads {Config.GetInt(Config.Key.ffEncThreads)} {outPath.Wrap()}";
await RunFfmpeg(args, framesFile.GetParentDir(), logMode, !isChunk);
IoUtils.TryDeleteIfExists(linksDir);
return filters.Count > 0 ? $"-vf {string.Join(",", filters)}" : "" + $" {extraArgs}";
}
public static string GetConcatFileExt (string concatFilePath)
@@ -68,14 +73,6 @@ namespace Flowframes.Media
return Path.GetExtension(File.ReadAllLines(concatFilePath).FirstOrDefault().Split('\'')[1]);
}
static string GetAspectArg (VidExtraData extraData)
{
if (!string.IsNullOrWhiteSpace(extraData.displayRatio) && !extraData.displayRatio.MatchesWildcard("*N/A*"))
return $"-aspect {extraData.displayRatio}";
else
return "";
}
public static async Task FramesToFrames(string framesFile, string outDir, int startNo, Fraction fps, Fraction resampleFps, string format = "png", int lossyQ = 1, LogMode logMode = LogMode.OnlyLastLine)
{
Directory.CreateDirectory(outDir);

View File

@@ -372,10 +372,8 @@ namespace Flowframes.Os
string avDir = Path.Combine(Paths.GetPkgPath(), Paths.audioVideoDir);
string rtArgs = $"-window_title \"Flowframes Realtime Interpolation ({Interpolate.currentSettings.inFps.GetString()} FPS x{factor} = {Interpolate.currentSettings.outFps.GetString()} FPS - {mdl})\" -autoexit -seek_interval {VapourSynthUtils.GetSeekSeconds(Program.mainForm.currInDuration)} ";
Interpolate.currentSettings.FullOutPath = Path.Combine(Interpolate.currentSettings.outPath, await IoUtils.GetCurrentExportFilename(false, true));
string encArgs = FfmpegUtils.GetEncArgs(FfmpegUtils.GetCodec(Interpolate.currentSettings.outMode), (Interpolate.currentSettings.ScaledResolution.IsEmpty ? Interpolate.currentSettings.InputResolution : Interpolate.currentSettings.ScaledResolution), Interpolate.currentSettings.outFps.GetFloat(), true).FirstOrDefault();
string ffmpegArgs = rt ? $"{Path.Combine(avDir, "ffplay").Wrap()} {rtArgs} - " : $"{Path.Combine(avDir, "ffmpeg").Wrap()} -y -i pipe: {encArgs} {Interpolate.currentSettings.FullOutPath.Wrap()}";
string pipedTargetArgs = rt ? $"{Path.Combine(avDir, "ffplay").Wrap()} {rtArgs} - " : $"{Path.Combine(avDir, "ffmpeg").Wrap()} -y -i pipe: {await Export.GetPipedFfmpegCmd()}";
string pkgDir = Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir);
@@ -395,7 +393,7 @@ namespace Flowframes.Os
Realtime = rt
};
rifeNcnnVs.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {pkgDir.Wrap()} & vspipe {VapourSynthUtils.CreateScript(vsSettings).Wrap()} -c y4m - | {ffmpegArgs}";
rifeNcnnVs.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {pkgDir.Wrap()} & vspipe {VapourSynthUtils.CreateScript(vsSettings).Wrap()} -c y4m - | {pipedTargetArgs}";
Logger.Log("cmd.exe " + rifeNcnnVs.StartInfo.Arguments, true);