Symlink to frame sequence if compatible (no copying)

This commit is contained in:
N00MKRAD
2021-05-24 13:42:53 +02:00
parent a3053a2ffc
commit fd9f5235b1
4 changed files with 40 additions and 17 deletions

View File

@@ -59,6 +59,7 @@ namespace Flowframes
{
if (str.Length < 1 || str == null)
return 0f;
string num = str.TrimNumbers(true).Replace(",", ".");
float value;
float.TryParse(num, NumberStyles.Any, CultureInfo.InvariantCulture, out value);

View File

@@ -282,6 +282,7 @@ namespace Flowframes.IO
allowConsecutiveSceneChanges,
allowCustomInputRate,
allowSymlinkEncoding,
allowSymlinkImport,
audioSubTransferMode,
autoDedupFrames,
autoEncDebug,

View File

@@ -32,7 +32,7 @@ namespace Flowframes.IO
return false;
}
public static async Task CreateSymlinksParallel(Dictionary<string, string> pathsLinkTarget, int maxThreads = 150)
public static async Task CreateSymlinksParallel(Dictionary<string, string> pathsLinkTarget, bool debug = false, int maxThreads = 150)
{
Stopwatch sw = new Stopwatch();
sw.Restart();
@@ -40,7 +40,10 @@ namespace Flowframes.IO
Task forEach = Task.Run(async () => Parallel.ForEach(pathsLinkTarget, opts, pair =>
{
CreateSymbolicLink(pair.Key, pair.Value, Flag.Unprivileged);
bool success = CreateSymbolicLink(pair.Key, pair.Value, Flag.Unprivileged);
if (debug)
Logger.Log($"Created Symlink - Source: '{pair.Key}' - Target: '{pair.Value}' - Sucess: {success}", true);
}));
while (!forEach.IsCompleted) await Task.Delay(1);

View File

@@ -92,29 +92,47 @@ namespace Flowframes.Media
DeleteSource(inputFile);
}
public static async Task ImportImagesCheckCompat(string inpath, string outpath, bool alpha, Size size, bool showLog, string format)
public static async Task ImportImagesCheckCompat(string inPath, string outPath, bool alpha, Size size, bool showLog, string format)
{
bool compatible = await Task.Run(async () => { return AreImagesCompatible(inpath, Config.GetInt(Config.Key.maxVidHeight)); });
bool compatible = await Task.Run(async () => { return AreImagesCompatible(inPath, Config.GetInt(Config.Key.maxVidHeight)); });
if (!alpha && compatible)
{
if (showLog) Logger.Log($"Copying images from {new DirectoryInfo(inpath).Name}...");
Directory.CreateDirectory(outpath);
await Task.Run(async () => {
int counter = 0;
foreach (FileInfo file in IOUtils.GetFileInfosSorted(inpath))
{
string newFilename = counter.ToString().PadLeft(Padding.inputFrames, '0') + file.Extension;
File.Copy(file.FullName, Path.Combine(outpath, newFilename));
counter++;
}
});
await CopyImages(inPath, outPath, showLog);
}
else
{
await ImportImages(inpath, outpath, alpha, size, showLog, format);
await ImportImages(inPath, outPath, alpha, size, showLog, format);
}
}
public static async Task CopyImages (string inpath, string outpath, bool showLog)
{
if (showLog) Logger.Log($"Copying images from {new DirectoryInfo(inpath).Name}...");
Directory.CreateDirectory(outpath);
Dictionary<string, string> moveFromTo = new Dictionary<string, string>();
int counter = 0;
foreach (FileInfo file in IOUtils.GetFileInfosSorted(inpath))
{
string newFilename = counter.ToString().PadLeft(Padding.inputFrames, '0') + file.Extension;
moveFromTo.Add(file.FullName, Path.Combine(outpath, newFilename));
counter++;
}
if (Config.GetBool(Config.Key.allowSymlinkEncoding) && Config.GetBool(Config.Key.allowSymlinkImport, true))
{
Dictionary<string, string> moveFromToSwapped = moveFromTo.ToDictionary(x => x.Value, x => x.Key); // From/To => To/From (Link/Target)
await Symlinks.CreateSymlinksParallel(moveFromToSwapped);
}
else
{
await Task.Run(async () => {
foreach (KeyValuePair<string, string> moveFromToPair in moveFromTo)
File.Copy(moveFromToPair.Key, moveFromToPair.Value);
});
}
}