feat(P2): videos library, verified video trash and copy job, render hashes and still jobs

Renders now record their SHA-256 and kind, so copies, deletes and restores can
be verified. The new videos library lists every render with paging and
filters, deletes into the archive trash after a dry run whose fingerprint must
still match (journalled, so a crash mid-move is settled on open), restores by id
refusing a tampered file, and a VideoCopy job copies renders hash-verified into
a videos folder outside the archive, never overwriting. A still job saves one
frame as an image through an interim Data-side path until P1's Core still API
lands. Batch exports keep the playback and routing uses the job's own export,
so a playback job needs settings format 3 and an older node never claims it.

Refs #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-05 02:27:37 +01:00
1 parent d472dfdec1
commit 03b4d0ef60
23 files changed
+2123 -72

No files matched your search

@@ -134,6 +134,99 @@ internal sealed class SequenceRender : IAsyncDisposable
return outcomes;
}
/// <summary>
/// Saves frame <paramref name="frameIndex"/> as one image ("Save frame", owner review 1, R8): the sequence prepared whole
/// as for a video (so its exposure, colour and stabilisation corrections are the ones the video gives that frame), then
/// that frame alone rendered at the export's output size with every correction and the look, without interpolation,
/// motion blur or playback, through the image encoder of <paramref name="target"/>'s codec (PNG, JPEG or TIFF 16-bit). It
/// is written into a hidden working folder beside the output (<c>.&lt;name&gt;.&lt;random&gt;.tmp</c>, which
/// leftover clean-ups find) and moved to <paramref name="name"/>'s path once complete. The result's path is the image's,
/// its duration 0 and its frame count 1.
/// </summary>
/// <param name="name">The output path of the still from its setup.</param>
/// <param name="starting">Runs with that path before anything is written (checkpoints).</param>
/// <exception cref="RenderException">The frame is not one of the sequence's, or no encoder writes the codec.</exception>
public async Task<RenderResult> RenderStillAsync(ExportTarget target, int frameIndex, Func<RenderSetup, string> name, Func<string, ValueTask> starting,
Func<long, long, string?, ValueTask> progress, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(target);
ArgumentNullException.ThrowIfNull(name);
if ((uint)frameIndex >= (uint)Input.Frames.Count) throw new RenderException("Export.Render.NoFrames", $"Frame {frameIndex} is not in the sequence.");
// That frame alone, one output period long, whatever the timing would have made of it.
var project = Input.Project with
{
ExcludedFrames = [.. Enumerable.Range(0, Input.Frames.Count).Where(i => i != frameIndex)],
Timing = Input.Project.Timing with { Mode = Input.Project.Timing.Mode.WithManual(TimingMode.Constant), FitToSeconds = null },
Motion = Input.Project.Motion with { MotionBlur = Input.Project.Motion.MotionBlur.WithManual(false) },
};
var still = Input with { Project = project };
var pipeline = Pipeline(target.Export);
var setup = pipeline.Setup(still, new RenderTarget(target.Export, ExportNaming.FallbackName), _options);
if (!setup.Encoder.IsReady || setup.Plan.Frames.Count == 0) throw new RenderException("Export.Render.NoFrames", Reason(setup));
var output = name(setup);
await starting(output).ConfigureAwait(false);
var chain = new ProgressChain(progress);
var whole = pipeline.Setup(Input, new RenderTarget(target.Export, ExportNaming.FallbackName), _options);
var preparing = whole.NeedsPreparation ? whole.Plan.IncludedFrames.Count : 0;
var total = preparing + 1L;
// The corrections of the whole sequence, indexed by source frame: the frame gets what the video gives it.
var corrections = await RenderPreparation.PrepareAsync(Input, _options, Stage(chain, 0, preparing, total, Loc.L("Export.Job.Preparing")), cancellationToken)
.ConfigureAwait(false);
var work = Path.Combine(Path.GetDirectoryName(output)!, "." + Path.GetFileName(output) + "." + Guid.NewGuid().ToString("N")[..8] + ".tmp");
Directory.CreateDirectory(work);
try
{
var result = await pipeline.RenderAsync(still, corrections, new RenderTarget(target.Export, Path.Combine(work, "still")), _options,
Stage(chain, preparing, 1, total, target.PresetName), cancellationToken).ConfigureAwait(false);
await chain.FlushAsync().ConfigureAwait(false);
var image = Directory.EnumerateFiles(result.OutputPath).Order(StringComparer.Ordinal).FirstOrDefault()
?? throw new RenderException("Export.Render.NoFrames", "The still was not written.");
File.Move(image, output, overwrite: false);
return result with { OutputPath = output, Bytes = new FileInfo(output).Length, DurationSeconds = 0, FrameCount = 1 };
}
finally
{
try
{
Directory.Delete(work, recursive: true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Core.Diagnostics.Log.Warning("processing", $"The still's working folder {work} could not be removed", ex);
}
}
}
/// <summary>
/// The path of a still of frame <paramref name="frameIndex"/> (0-based) in <paramref name="folder"/>: the export's name
/// template expanded, then " - " and the 1-based frame number in four digits, with the codec's extension
/// ("2026-09-28 Harbour sunset - PNG - 0124.png"); " (2)" and so on when taken.
/// </summary>
public static string StillPath(ExportSettings export, string folder, ExportNameContext context, int frameIndex, Func<string, bool>? taken = null)
{
ArgumentNullException.ThrowIfNull(export);
var name = ExportNaming.Expand(export.NameTemplate, context).Name + " - " + (frameIndex + 1).ToString("0000", System.Globalization.CultureInfo.InvariantCulture);
return ExportNaming.Unique(string.IsNullOrWhiteSpace(export.Folder) ? folder : export.Folder, name, Core.Video.VideoCodecInfo.FileExtension(context.Codec), taken);
}
/// <summary>
/// The frame a still job saves (<see cref="Protocol.RenderJobParameters.StillFrame"/>, <see cref="Protocol.RenderJobParameters.StillPhoto"/>):
/// the frame holding the photo when its SHA-256 is given and found (the frames may have moved since), else the index;
/// null when neither names a frame of the sequence.
/// </summary>
public static int? StillIndex(SequenceFrames frames, int? frameIndex, string? photoSha256)
{
ArgumentNullException.ThrowIfNull(frames);
if (photoSha256 is { Length: > 0 } sha)
{
for (var i = 0; i < frames.Frames.Count; i++)
{
if (string.Equals(frames.Frames[i].Sha256, sha, StringComparison.OrdinalIgnoreCase)) return i;
}
}
return frameIndex is { } index && (uint)index < (uint)frames.Frames.Count ? index : null;
}
/// <summary>Values of the output name tokens: the shoot date and title of the sequence, the codec and size the encoder will use.</summary>
public static ExportNameContext NameContext(Sequence sequence, ExportTarget target, RenderSetup setup) => new()
{