mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-07-13 05:50:33 +02:00
Fixed and refactored code to include output FPS in export filename
This commit is contained in:
@@ -28,7 +28,6 @@ namespace Flowframes
|
||||
public string framesFolder;
|
||||
public string interpFolder;
|
||||
public bool inputIsFrames;
|
||||
public string outFilename;
|
||||
public Size inputResolution;
|
||||
public Size scaledResolution;
|
||||
|
||||
@@ -55,7 +54,6 @@ namespace Flowframes
|
||||
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
|
||||
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
|
||||
inputIsFrames = IOUtils.IsPathDirectory(inPath);
|
||||
outFilename = Path.Combine(outPath, IOUtils.GetExportFilename(inPath, interpFactor, ai, model, outFps)) + FFmpegUtils.GetExt(outMode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -64,7 +62,6 @@ namespace Flowframes
|
||||
framesFolder = "";
|
||||
interpFolder = "";
|
||||
inputIsFrames = false;
|
||||
outFilename = "";
|
||||
}
|
||||
|
||||
inputResolution = new Size(0, 0);
|
||||
@@ -120,7 +117,6 @@ namespace Flowframes
|
||||
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
|
||||
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
|
||||
inputIsFrames = IOUtils.IsPathDirectory(inPath);
|
||||
outFilename = Path.Combine(outPath, IOUtils.GetExportFilename(inPath, interpFactor, ai, model, outFps)) + FFmpegUtils.GetExt(outMode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -129,7 +125,6 @@ namespace Flowframes
|
||||
framesFolder = "";
|
||||
interpFolder = "";
|
||||
inputIsFrames = false;
|
||||
outFilename = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +136,6 @@ namespace Flowframes
|
||||
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
|
||||
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
|
||||
inputIsFrames = IOUtils.IsPathDirectory(inPath);
|
||||
outFilename = Path.Combine(outPath, IOUtils.GetExportFilename(inPath, interpFactor, ai, model, outFps)) + FFmpegUtils.GetExt(outMode);
|
||||
}
|
||||
|
||||
public async Task<Size> GetInputRes()
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Flowframes.IO
|
||||
|
||||
public const string alphaSuffix = "-a";
|
||||
public const string prevSuffix = "-previous";
|
||||
public const string fpsLimitSuffix = "-fpsLimit";
|
||||
|
||||
public const string frameOrderPrefix = "frames";
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Flowframes.Data;
|
||||
using Flowframes.Main;
|
||||
using Flowframes.Media;
|
||||
using Flowframes.MiscUtils;
|
||||
using Flowframes.UI;
|
||||
using Force.Crc32;
|
||||
@@ -406,25 +407,31 @@ namespace Flowframes.IO
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string GetCurrentExportFilename()
|
||||
public static string GetCurrentExportFilename(bool fpsLimit, bool withExt)
|
||||
{
|
||||
InterpSettings curr = Interpolate.current;
|
||||
return GetExportFilename(curr.inPath, curr.interpFactor, curr.ai, curr.model, curr.outFps);
|
||||
}
|
||||
float fps = fpsLimit ? Config.GetFloat("maxFps") : curr.outFps;
|
||||
|
||||
public static string GetExportFilename (string inputName, float factor, AI ai, string mdl, float fps)
|
||||
{
|
||||
string name = Config.Get("exportNamePattern");
|
||||
string pattern = Config.Get("exportNamePattern");
|
||||
string inName = Interpolate.current.inputIsFrames ? Path.GetFileName(curr.inPath) : Path.GetFileNameWithoutExtension(curr.inPath);
|
||||
bool addSuffix = fpsLimit && (!pattern.Contains("[FPS]") && !pattern.Contains("[ROUNDFPS]"));
|
||||
string filename = pattern;
|
||||
|
||||
name = name.Replace("[NAME]", Path.GetFileNameWithoutExtension(inputName));
|
||||
name = name.Replace("[NAMEWITHEXT]", Path.GetFileName(inputName));
|
||||
name = name.Replace("[FACTOR]", factor.ToStringDot());
|
||||
name = name.Replace("[AI]", ai.aiNameShort.ToUpper());
|
||||
name = name.Replace("[MODEL]", mdl);
|
||||
name = name.Replace("[FPS]", fps.ToStringDot());
|
||||
name = name.Replace("[ROUNDFPS]", fps.RoundToInt().ToString());
|
||||
filename = filename.Replace("[NAME]", inName);
|
||||
filename = filename.Replace("[NAMEWITHEXT]", Path.GetFileName(curr.inPath));
|
||||
filename = filename.Replace("[FACTOR]", curr.interpFactor.ToStringDot());
|
||||
filename = filename.Replace("[AI]", curr.ai.aiNameShort.ToUpper());
|
||||
filename = filename.Replace("[MODEL]", curr.model);
|
||||
filename = filename.Replace("[FPS]", fps.ToStringDot());
|
||||
filename = filename.Replace("[ROUNDFPS]", fps.RoundToInt().ToString());
|
||||
|
||||
return name;
|
||||
if (addSuffix)
|
||||
filename += Paths.fpsLimitSuffix;
|
||||
|
||||
if (withExt)
|
||||
filename += FFmpegUtils.GetExt(curr.outMode);
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
public static string GetHighestFrameNumPath (string path)
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Flowframes.Main
|
||||
}
|
||||
|
||||
if (Interpolate.canceled) return;
|
||||
await CreateVideo.ChunksToVideos(Interpolate.current.tempFolder, videoChunksFolder, Interpolate.current.outFilename);
|
||||
await CreateVideo.ChunksToVideos(Interpolate.current.tempFolder, videoChunksFolder, Interpolate.current.outPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -21,13 +21,14 @@ namespace Flowframes.Main
|
||||
{
|
||||
static string currentOutFile; // Keeps track of the out file, in case it gets renamed (FPS limiting, looping, etc) before finishing export
|
||||
|
||||
public static async Task Export(string path, string outPath, I.OutMode mode, bool stepByStep)
|
||||
public static async Task Export(string path, string outFolder, I.OutMode mode, bool stepByStep)
|
||||
{
|
||||
if (!mode.ToString().ToLower().Contains("vid")) // Copy interp frames out of temp folder and skip video export for image seq export
|
||||
{
|
||||
try
|
||||
{
|
||||
await CopyOutputFrames(path, Path.GetFileNameWithoutExtension(outPath), stepByStep);
|
||||
string folder = Path.Combine(outFolder, IOUtils.GetCurrentExportFilename(false, false));
|
||||
await CopyOutputFrames(path, folder, stepByStep);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -54,17 +55,10 @@ namespace Flowframes.Main
|
||||
bool dontEncodeFullFpsVid = fpsLimit && Config.GetInt("maxFpsMode") == 0;
|
||||
|
||||
if(!dontEncodeFullFpsVid)
|
||||
await Encode(mode, path, outPath, I.current.outFps);
|
||||
await Encode(mode, path, Path.Combine(outFolder, IOUtils.GetCurrentExportFilename(false, true)), I.current.outFps);
|
||||
|
||||
if (fpsLimit)
|
||||
{
|
||||
bool addSuffix = (!Config.Get("exportNamePattern").Contains("[FPS]") && !Config.Get("exportNamePattern").Contains("[ROUNDFPS]"));
|
||||
|
||||
if (addSuffix)
|
||||
outPath = outPath.FilenameSuffix($"_{maxFps.ToStringDot("0.00")}fpsLimit");
|
||||
|
||||
await Encode(mode, path, outPath, I.current.outFps, maxFps);
|
||||
}
|
||||
await Encode(mode, path, Path.Combine(outFolder, IOUtils.GetCurrentExportFilename(true, true)), I.current.outFps, maxFps);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -149,12 +143,15 @@ namespace Flowframes.Main
|
||||
string suffix = dir.Name.Replace("chunks", "");
|
||||
string tempConcatFile = Path.Combine(tempFolder, $"chunks-concat{suffix}.ini");
|
||||
string concatFileContent = "";
|
||||
|
||||
foreach (string vid in IOUtils.GetFilesSorted(dir.FullName))
|
||||
concatFileContent += $"file '{Paths.chunksDir}/{dir.Name}/{Path.GetFileName(vid)}'\n";
|
||||
File.WriteAllText(tempConcatFile, concatFileContent);
|
||||
|
||||
Logger.Log($"CreateVideo: Running MergeChunks() for vfrFile '{Path.GetFileName(tempConcatFile)}'", true);
|
||||
await MergeChunks(tempConcatFile, baseOutPath.FilenameSuffix(suffix));
|
||||
File.WriteAllText(tempConcatFile, concatFileContent);
|
||||
Logger.Log($"CreateVideo: Running MergeChunks() for frames file '{Path.GetFileName(tempConcatFile)}'", true);
|
||||
bool fpsLimit = dir.Name.Contains(Paths.fpsLimitSuffix);
|
||||
string outPath = Path.Combine(baseOutPath, IOUtils.GetCurrentExportFilename(fpsLimit, true));
|
||||
await MergeChunks(tempConcatFile, outPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -188,7 +185,7 @@ namespace Flowframes.Main
|
||||
if (fpsLimit)
|
||||
{
|
||||
string filename = Path.GetFileName(outPath);
|
||||
string newParentDir = outPath.GetParentDir() + "-" + maxFps.ToStringDot("0.00") + "fps";
|
||||
string newParentDir = outPath.GetParentDir() + Paths.fpsLimitSuffix;
|
||||
outPath = Path.Combine(newParentDir, filename);
|
||||
await FfmpegEncode.FramesToVideoConcat(vfrFile, outPath, mode, I.current.outFps, maxFps, AvProcess.LogMode.Hidden, true); // Encode with limited fps
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Flowframes
|
||||
if (canceled) return;
|
||||
Program.mainForm.SetProgress(100);
|
||||
if(!currentlyUsingAutoEnc)
|
||||
await CreateVideo.Export(current.interpFolder, current.outFilename, current.outMode, false);
|
||||
await CreateVideo.Export(current.interpFolder, current.outPath, current.outMode, false);
|
||||
await IOUtils.ReverseRenaming(current.framesFolder, AiProcess.filenameMap); // Get timestamps back
|
||||
AiProcess.filenameMap.Clear();
|
||||
await Cleanup();
|
||||
|
||||
@@ -130,8 +130,7 @@ namespace Flowframes.Main
|
||||
return;
|
||||
}
|
||||
|
||||
string outPath = Path.Combine(current.outPath, IOUtils.GetCurrentExportFilename()) + FFmpegUtils.GetExt(current.outMode);
|
||||
await CreateVideo.Export(current.interpFolder, outPath, current.outMode, true);
|
||||
await CreateVideo.Export(current.interpFolder, current.outPath, current.outMode, true);
|
||||
}
|
||||
|
||||
public static async Task Reset()
|
||||
|
||||
@@ -6,7 +6,6 @@ using Flowframes.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -174,7 +173,7 @@ namespace Flowframes.Media
|
||||
|
||||
public static async Task MergeStreamsFromInput (string inputVideo, string interpVideo, string tempFolder)
|
||||
{
|
||||
if (!File.Exists(inputVideo))
|
||||
if (!File.Exists(inputVideo) && !I.current.inputIsFrames)
|
||||
{
|
||||
Logger.Log("Warning: Input video file not found, can't copy audio/subtitle streams to output video!");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user