Some fixes
This commit is contained in:
@@ -15,7 +15,7 @@ public sealed class RenderPipeline
|
||||
_probe = new MediaProbe(_runner, null);
|
||||
}
|
||||
|
||||
public async Task RenderAsync(
|
||||
public async Task<IReadOnlyList<string>> RenderAsync(
|
||||
RenderSettings settings,
|
||||
IProgress<RenderProgress> progress,
|
||||
Action<string> log,
|
||||
@@ -105,7 +105,16 @@ public sealed class RenderPipeline
|
||||
finalArgs.AddRange(EncoderArguments(encoder));
|
||||
finalArgs.AddRange(["-c:a", "aac", "-b:a", "384k", "-ar", "48000", "-movflags", "+faststart", final]);
|
||||
await RunStageAsync(tools.Ffmpeg, finalArgs, log, progress, "Final render", 60, 99, finalDuration, settings.FramesPerSecond, token);
|
||||
|
||||
IReadOnlyList<string> inputPaths = settings.InputFiles;
|
||||
if (settings.MoveSourcesToOriginals)
|
||||
{
|
||||
progress.Report(new(99.5, "Moving sources", "Moving original recordings to originals"));
|
||||
inputPaths = MoveSourceVideos(settings.InputFiles, settings.OutputDirectory, log);
|
||||
}
|
||||
|
||||
progress.Report(new(100, "Complete", final));
|
||||
return inputPaths;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -285,6 +294,70 @@ public sealed class RenderPipeline
|
||||
return fallbackPath;
|
||||
}
|
||||
|
||||
internal static IReadOnlyList<string> MoveSourceVideos(
|
||||
IReadOnlyList<string> sources,
|
||||
string outputDirectory,
|
||||
Action<string> log)
|
||||
{
|
||||
string originalsDir = Path.Combine(outputDirectory, "originals");
|
||||
Directory.CreateDirectory(originalsDir);
|
||||
List<string> resolved = new(sources.Count);
|
||||
HashSet<string> claimed = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (string source in sources)
|
||||
{
|
||||
if (!File.Exists(source))
|
||||
{
|
||||
log($"WARNING: Source file no longer exists, skipped move: {source}");
|
||||
resolved.Add(source);
|
||||
continue;
|
||||
}
|
||||
|
||||
string sourceFull = Path.GetFullPath(source);
|
||||
string preferred = Path.GetFullPath(Path.Combine(originalsDir, Path.GetFileName(source)));
|
||||
if (string.Equals(sourceFull, preferred, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
claimed.Add(preferred);
|
||||
resolved.Add(preferred);
|
||||
continue;
|
||||
}
|
||||
|
||||
string dest = UniqueDestination(preferred, claimed);
|
||||
|
||||
try
|
||||
{
|
||||
File.Move(source, dest);
|
||||
claimed.Add(dest);
|
||||
log($"Moved source to {dest}");
|
||||
resolved.Add(dest);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
log($"WARNING: Could not move source '{source}' to originals: {exception.Message}");
|
||||
resolved.Add(source);
|
||||
}
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private static string UniqueDestination(string dest, HashSet<string> claimed)
|
||||
{
|
||||
string full = Path.GetFullPath(dest);
|
||||
if (!File.Exists(full) && !claimed.Contains(full))
|
||||
return full;
|
||||
|
||||
string directory = Path.GetDirectoryName(full)!;
|
||||
string name = Path.GetFileNameWithoutExtension(full);
|
||||
string extension = Path.GetExtension(full);
|
||||
for (int index = 2; ; index++)
|
||||
{
|
||||
string candidate = Path.Combine(directory, $"{name}_{index}{extension}");
|
||||
if (!File.Exists(candidate) && !claimed.Contains(candidate))
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Validate(RenderSettings s)
|
||||
{
|
||||
if (s.InputFiles.Count == 0) throw new ArgumentException("Select at least one AVI input file.");
|
||||
|
||||
Reference in New Issue
Block a user