1
mirror of https://github.com/n00mkrad/flowframes synced 2024-11-16 19:10:31 +01:00

Unified zero padding for frames

This commit is contained in:
N00MKRAD 2020-12-02 17:23:24 +01:00
parent bd408f3423
commit e7e913f5a7
6 changed files with 20 additions and 17 deletions

View File

@ -37,11 +37,12 @@ namespace Flowframes
IOUtils.CreateDir(frameFolderPath);
string timecodeStr = timecodes ? "-copyts -r 1000 -frame_pts true" : "";
string scnDetect = sceneDetect ? $"\"select='gt(scene,{Config.Get("scnDetectValue")})'\"," : "";
string args = $"-i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} -vf {scnDetect}{divisionFilter} {sizeStr} \"{frameFolderPath}/%08d.png\"";
string pad = Padding.inputFrames.ToString();
string args = $"-i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} -vf {scnDetect}{divisionFilter} {sizeStr} \"{frameFolderPath}/%{pad}d.png\"";
if (deDupe)
{
string mpStr = (Config.GetInt("mpdecimateMode") == 0) ? mpDecDef : mpDecAggr;
args = $"-i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} -vf {scnDetect}{mpStr},{divisionFilter} {sizeStr} \"{frameFolderPath}/%08d.png\"";
args = $"-i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} -vf {scnDetect}{mpStr},{divisionFilter} {sizeStr} \"{frameFolderPath}/%{pad}d.png\"";
}
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine);
await Task.Delay(1);

View File

@ -8,7 +8,6 @@ namespace Flowframes.Data
{
class Padding
{
public const int inputFrames = 10;
public const int timestampFrames = 10;
public const int inputFrames = 9;
}
}

View File

@ -11,6 +11,7 @@ using Flowframes.UI;
using Microsoft.VisualBasic.Devices;
using ImageMagick;
using Flowframes.OS;
using Flowframes.Data;
namespace Flowframes.Magick
{
@ -254,7 +255,7 @@ namespace Flowframes.Magick
int currentDupesAmount = kvp[1].GetInt();
// Copy Source Frame
paddedFilename = sourceFrameNum.ToString().PadLeft(8, '0') + $".{ext}";
paddedFilename = sourceFrameNum.ToString().PadLeft(Padding.inputFrames, '0') + $".{ext}";
sourceFramePath = Path.Combine(path, paddedFilename);
if(debugLog) Logger.Log("[Source] Moving " + Path.GetFileName(sourceFramePath) + " => " + outFrameNum + $".{ext}");
if (!IOUtils.TryCopy(sourceFramePath, Path.Combine(tempSubFolder, outFrameNum + $".{ext}")))
@ -264,7 +265,7 @@ namespace Flowframes.Magick
// Insert dupes for source frame
for (int copyTimes = 0; copyTimes < currentDupesAmount; copyTimes++)
{
paddedFilename = sourceFrameNum.ToString().PadLeft(8, '0') + $".{ext}";
paddedFilename = sourceFrameNum.ToString().PadLeft(Padding.inputFrames, '0') + $".{ext}";
sourceFramePath = Path.Combine(path, paddedFilename);
if (debugLog) Logger.Log("[Source Dupes] Moving " + Path.GetFileName(sourceFramePath) + " => " + outFrameNum + $".{ext}");
if (!IOUtils.TryCopy(sourceFramePath, Path.Combine(tempSubFolder, outFrameNum + $".{ext}")))
@ -280,7 +281,7 @@ namespace Flowframes.Magick
sourceFrameNum++;
// Copy Interp Frame
paddedFilename = sourceFrameNum.ToString().PadLeft(8, '0') + $".{ext}";
paddedFilename = sourceFrameNum.ToString().PadLeft(Padding.inputFrames, '0') + $".{ext}";
sourceFramePath = Path.Combine(path, paddedFilename);
if (debugLog) Logger.Log("[Interp] Moving " + Path.GetFileName(sourceFramePath) + " => " + outFrameNum + $".{ext}");
if (!IOUtils.TryCopy(sourceFramePath, Path.Combine(tempSubFolder, outFrameNum + $".{ext}")))
@ -290,7 +291,7 @@ namespace Flowframes.Magick
// Insert dupes for interp frame
for (int copyTimes = 0; copyTimes < currentDupesAmount; copyTimes++)
{
paddedFilename = sourceFrameNum.ToString().PadLeft(8, '0') + $".{ext}";
paddedFilename = sourceFrameNum.ToString().PadLeft(Padding.inputFrames, '0') + $".{ext}";
sourceFramePath = Path.Combine(path, paddedFilename);
if (debugLog) if (debugLog) Logger.Log("[Interp Dupes] Moving " + Path.GetFileName(sourceFramePath) + " => " + outFrameNum + $".{ext}");
if (!IOUtils.TryCopy(sourceFramePath, Path.Combine(tempSubFolder, outFrameNum + $".{ext}")))

View File

@ -14,6 +14,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Padding = Flowframes.Data.Padding;
using Utils = Flowframes.Main.InterpolateUtils;
namespace Flowframes
@ -133,7 +134,7 @@ namespace Flowframes
{
string lastFrame = IOUtils.GetHighestFrameNumPath(outPath);
int newNum = Path.GetFileName(lastFrame).GetInt() + 1;
string newFilename = Path.Combine(lastFrame.GetParentDir(), newNum.ToString().PadLeft(8, '0') + ".png");
string newFilename = Path.Combine(lastFrame.GetParentDir(), newNum.ToString().PadLeft(Padding.inputFrames, '0') + ".png");
string firstFrame = new DirectoryInfo(outPath).GetFiles("*.png")[0].FullName;
File.Copy(firstFrame, newFilename);
Logger.Log("Copied loop frame.");

View File

@ -124,10 +124,10 @@ namespace Flowframes.Main
}
if (!canceled && Config.GetBool("enableLoop") && Config.GetInt("timingMode") != 1)
{
string lastFrame = IOUtils.GetHighestFrameNumPath(currentOutPath);
string lastFrame = IOUtils.GetHighestFrameNumPath(currentFramesPath);
int newNum = Path.GetFileName(lastFrame).GetInt() + 1;
string newFilename = Path.Combine(lastFrame.GetParentDir(), newNum.ToString().PadLeft(8, '0') + ".png");
string firstFrame = new DirectoryInfo(currentOutPath).GetFiles("*.png")[0].FullName;
string newFilename = Path.Combine(lastFrame.GetParentDir(), newNum.ToString().PadLeft(Padding.inputFrames, '0') + ".png");
string firstFrame = new DirectoryInfo(currentFramesPath).GetFiles("*.png")[0].FullName;
File.Copy(firstFrame, newFilename);
Logger.Log("Copied loop frame.");
}

View File

@ -1,4 +1,5 @@
using Flowframes.IO;
using Flowframes.Data;
using Flowframes.IO;
using Flowframes.UI;
using System;
using System.Collections.Generic;
@ -89,13 +90,13 @@ namespace Flowframes.Main
int lastNum = totalFileCount - 1;
for (int dupeCount = 1; dupeCount < interpFramesAmount; dupeCount++)
{
fileContent += $"file '{interpPath}/{lastNum.ToString().PadLeft(8, '0')}.png'\nduration {durationStr}\n";
fileContent += $"file '{interpPath}/{lastNum.ToString().PadLeft(Padding.inputFrames, '0')}.png'\nduration {durationStr}\n";
totalFileCount++;
}
frm = interpFramesAmount - 1;
}
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(8, '0')}.png'\nduration {durationStr}\n";
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.inputFrames, '0')}.png'\nduration {durationStr}\n";
totalFileCount++;
}
@ -110,7 +111,7 @@ namespace Flowframes.Main
if (firstFrameFix)
{
string[] lines = IOUtils.ReadLines(vfrFile);
File.WriteAllText(vfrFile, lines[0].Replace("00000001.png", "00000000.png"));
File.WriteAllText(vfrFile, lines[0].Replace($"{"1".PadLeft(Padding.inputFrames, '0')}.png", $"{"0".PadLeft(Padding.inputFrames, '0')}.png"));
File.AppendAllText(vfrFile, "\n" + lines[1] + "\n");
File.AppendAllLines(vfrFile, lines);
}
@ -119,7 +120,7 @@ namespace Flowframes.Main
{
int lastFileNumber = frameFiles.Last().Name.GetInt();
lastFileNumber += lastFrameDuration;
string loopFrameTargetPath = Path.Combine(frameFiles.First().FullName.GetParentDir(), lastFileNumber.ToString().PadLeft(8, '0') + ".png");
string loopFrameTargetPath = Path.Combine(frameFiles.First().FullName.GetParentDir(), lastFileNumber.ToString().PadLeft(Padding.inputFrames, '0') + ".png");
if (File.Exists(loopFrameTargetPath))
return;
File.Copy(frameFiles.First().FullName, loopFrameTargetPath);