feat: export panel and Render menu, playback options, videos library (owner review 1 phase 5) (#27)
CI / Build and test (push) Successful in 9m41s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 14m49s
CI / PostgreSQL 16 integration (push) Successful in 8m51s
CI / PostgreSQL 17 integration (push) Successful in 9m48s
CI / Docker image (push) Successful in 54s
Release / Server image (push) Successful in 1m39s

Owner review 1 R3, R8, R9. A grouped Export step and Render menu; encoding, playback (reverse, boomerang, loops, fades, hold) and still frames; one videos library on the desktop and the server with a verified trash and copies to a videos folder.

Closes #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #27.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-05 09:18:40 +01:00
1 parent 188b2c2e55
commit 728ffa35cb
729 files changed
+26954 -1652

No files matched your search

@@ -59,7 +59,11 @@ internal sealed class RenderJobHandler(ChronosDatabase db, ProcessingOptions opt
var (projectId, projectVersionId) = await ProvenanceAsync(parameters, sequence, cancellation).ConfigureAwait(false);
using var names = new OutputNames();
var all = Targets(export, parameters.PresetName);
// A still saves one frame through the job's preset alone: a batch is a video's.
var all = parameters.IsStill ? [new ExportTarget(ExportResolver.Resolve(export), parameters.PresetName)] : Targets(export, parameters.PresetName);
var still = parameters.IsStill
? SequenceRender.StillIndex(frames, parameters.StillFrame, parameters.StillPhoto) ?? throw new InvalidOperationException(Loc.L("Export.Render.StillMissing"))
: -1;
var resume = RenderCheckpoint.Parse(context.Checkpoint);
var done = resume.Done.ToList();
// A crash after a render row was written but before the checkpoint: that entry is finished.
@@ -83,29 +87,46 @@ internal sealed class RenderJobHandler(ChronosDatabase db, ProcessingOptions opt
await using (var render = new SequenceRender(frames, project, SequenceAnalyser.ReadReport(folder, frames), options, originals: !parameters.UseProxies,
companions))
{
outcomes = await render.RenderAllAsync(
targets,
(target, setup) => names.Reserve(taken => ExportNaming.OutputPath(project.Export, folder.Exports, SequenceRender.NameContext(sequence, target, setup), taken)),
(index, path) => context.CheckpointAsync(new RenderCheckpoint(done, index, path, sequence.Folder).ToJson(), context.Done, context.Total),
async (index, target, result) =>
async ValueTask Record(int index, ExportTarget target, RenderResult result)
{
// The output is complete: record it even if the job is being cancelled, so it is never orphaned. A file is
// hashed first (owner review 1, R9: copies and restores are verified against it); an image sequence's folder is not.
string? sha = null;
if (File.Exists(result.OutputPath))
{
// The output is complete: record it even if the job is being cancelled, so it is never orphaned.
var entity = result.ToEntity(sequence.Id, target.PresetName, settingsJson, options.ProducedBy) with
{
Id = RenderId(context.Job.Id, index),
OutputPath = Stored(paths, result.OutputPath),
ProjectId = projectId,
ProjectVersionId = projectVersionId,
};
await db.Renders.InsertAsync(entity, CancellationToken.None).ConfigureAwait(false);
done.Add(index);
await context.CheckpointAsync(new RenderCheckpoint(done, null, null).ToJson(), context.Done, context.Total).ConfigureAwait(false);
context.Log(Loc.L("Export.Log.Rendered", target.PresetName, Path.GetFileName(result.OutputPath)));
foreach (var remark in SequenceRender.Remarks(result)) context.Log(remark);
await options.NotifyAsync(sequence.Id, ProcessingOptions.RenderedChange, CancellationToken.None).ConfigureAwait(false);
},
context.ReportAsync,
cancellation).ConfigureAwait(false);
await context.ReportAsync(context.Done, context.Total, Loc.L("Export.Job.Verifying")).ConfigureAwait(false);
sha = await ContentHash.Sha256Async(result.OutputPath, cancellationToken: CancellationToken.None).ConfigureAwait(false);
}
var entity = result.ToEntity(sequence.Id, target.PresetName, settingsJson, options.ProducedBy) with
{
Id = RenderId(context.Job.Id, index),
OutputPath = Stored(paths, result.OutputPath),
ProjectId = projectId,
ProjectVersionId = projectVersionId,
Sha256 = sha,
Kind = parameters.IsStill ? RenderKind.Still : null,
};
if (parameters.IsStill) entity = entity with { Fps = 0, DurationSeconds = 0 };
await db.Renders.InsertAsync(entity, CancellationToken.None).ConfigureAwait(false);
done.Add(index);
await context.CheckpointAsync(new RenderCheckpoint(done, null, null).ToJson(), context.Done, context.Total).ConfigureAwait(false);
context.Log(parameters.IsStill
? Loc.L("Export.Log.StillSaved", (still + 1).ToString(Loc.Culture), Path.GetFileName(result.OutputPath))
: Loc.L("Export.Log.Rendered", target.PresetName, Path.GetFileName(result.OutputPath)));
foreach (var remark in SequenceRender.Remarks(result)) context.Log(remark);
await options.NotifyAsync(sequence.Id, ProcessingOptions.RenderedChange, CancellationToken.None).ConfigureAwait(false);
}
if (parameters.IsStill)
outcomes = [await StillAsync(context, render, targets[0], still, sequence, project.Export, folder, names, done, Record).ConfigureAwait(false)];
else
outcomes = await render.RenderAllAsync(
targets,
(target, setup) => names.Reserve(taken => ExportNaming.OutputPath(project.Export, folder.Exports, SequenceRender.NameContext(sequence, target, setup), taken)),
(index, path) => context.CheckpointAsync(new RenderCheckpoint(done, index, path, sequence.Folder).ToJson(), context.Done, context.Total),
Record,
context.ReportAsync,
cancellation).ConfigureAwait(false);
if (render.StandIns.Count > 0)
context.Log(Loc.L("Export.Log.StandIns", string.Join(", ", render.StandIns.Select(i => (i + 1).ToString(Loc.Culture)))));
// Recorded without the job's token: what decoding found holds even if the job is cancelled meanwhile, and a
@@ -128,6 +149,34 @@ internal sealed class RenderJobHandler(ChronosDatabase db, ProcessingOptions opt
throw new InvalidOperationException(failed.Count == 1 ? failed[0].Error : Loc.L("Errors.Render.Failed", failed.Count, outcomes.Count));
}
/// <summary>
/// The still of a still job: frame <paramref name="frame"/> saved through the job's preset under the export's name and
/// the frame number (<see cref="SequenceRender.StillPath"/>), checkpointed and recorded like a video's output.
/// </summary>
private static async Task<TargetOutcome> StillAsync(JobContext context, SequenceRender render, (int Index, ExportTarget Target) entry, int frame,
Sequence sequence, ExportSettings export, SequencePaths folder, OutputNames names, List<int> done,
Func<int, ExportTarget, RenderResult, ValueTask> record)
{
var (index, target) = entry;
try
{
var result = await render.RenderStillAsync(
target,
frame,
setup => names.Reserve(taken => SequenceRender.StillPath(export, folder.Exports, SequenceRender.NameContext(sequence, target, setup), frame, taken)),
path => context.CheckpointAsync(new RenderCheckpoint(done, index, path, sequence.Folder).ToJson(), context.Done, context.Total),
context.ReportAsync,
context.Cancellation).ConfigureAwait(false);
await record(index, target, result).ConfigureAwait(false);
return new TargetOutcome(target, result, null);
}
catch (Exception ex) when (!(ex is OperationCanceledException && context.Cancellation.IsCancellationRequested))
{
Core.Diagnostics.Log.Warning("processing", $"The still of frame {frame + 1} of {sequence.DisplayTitle} failed", ex);
return new TargetOutcome(target, null, SequenceRender.Reason(ex));
}
}
/// <summary>
/// The settings of the project version a job names without embedding them (owner review 2, R8); null when it names none.
/// </summary>
+50 -6
View File
@@ -44,6 +44,34 @@ public static class ProcessingJobs
JsonSerializer.Serialize(parameters, ProtocolJson.Default.RenderJobParameters), JobPriority.User);
}
/// <summary>
/// <see cref="JobKind.Render"/> of one frame saved as an image (owner review 1, R8, "Save frame"): frame
/// <paramref name="frameIndex"/> of the sequence (its photo <paramref name="photoSha256"/> wins when both are given and the
/// frames moved since) with <paramref name="codec"/>, one of <see cref="RenderRules.StillCodecs"/>, at the output size of
/// <paramref name="export"/>, with every correction and no playback. <paramref name="project"/> embeds the settings to
/// render, as <see cref="Render"/>. The job needs settings format <see cref="RenderRules.StillFormat"/>, so an older node,
/// which would render the whole video, never claims it.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="codec"/> is not a still codec, or <paramref name="frameIndex"/> is negative.</exception>
public static ArchiveJobRequest Still(Sequence sequence, ExportSettings export, VideoCodec codec, int frameIndex, string? photoSha256, int sourceWidth,
int sourceHeight, ProjectSettings? project = null)
{
ArgumentNullException.ThrowIfNull(sequence);
ArgumentNullException.ThrowIfNull(export);
if (!RenderRules.StillCodecs.Contains(codec)) throw new ArgumentOutOfRangeException(nameof(codec), codec, "Not a still codec.");
ArgumentOutOfRangeException.ThrowIfNegative(frameIndex);
var still = export with { Batch = [], Playback = null, Overrides = export.Overrides with { Codec = CodecName(codec), Container = null } };
var parameters = Parameters(still, sourceWidth, sourceHeight, project?.ToJson(), false, project ?? ReadSettings(sequence.SettingsJson));
parameters = parameters with
{
StillFrame = frameIndex,
StillPhoto = string.IsNullOrEmpty(photoSha256) ? null : photoSha256.ToLowerInvariant(),
RequiredSettingsFormat = int.Max(parameters.RequiredSettingsFormat, RenderRules.StillFormat),
};
return new ArchiveJobRequest(JobKind.Render, [sequence.Id], RenderLabel(sequence.DisplayTitle, parameters.PresetName),
JsonSerializer.Serialize(parameters, ProtocolJson.Default.RenderJobParameters), JobPriority.User);
}
/// <summary>
/// <see cref="JobKind.Render"/> of a project version (owner review 2, R8) on the sequence's home: the version's portable
/// settings, placed on the sequence's frames by the render, with <paramref name="export"/> as their export section; the
@@ -125,10 +153,19 @@ public static class ProcessingJobs
{
Width = width,
Height = height,
RequiredSettingsFormat = int.Max(parameters.RequiredSettingsFormat, RequiredFormat(settings, resolved, sourceWidth, sourceHeight)),
// The job's own export (playback included) is what renders, not the export the settings carry; but a node parses
// the settings text as it is, so never less than the format that text is written in.
RequiredSettingsFormat = int.Max(parameters.RequiredSettingsFormat, int.Max(TextFormat(settings),
RequiredFormat(settings with { Export = ReadExport(parameters.PresetJson) }, resolved, sourceWidth, sourceHeight))),
};
}
/// <summary>
/// The format of the settings text a node parses: the version it was read with, or the one <see cref="ProjectSettings.ToJson"/>
/// writes for it. A node that reads less refuses that text, whatever export the job renders.
/// </summary>
private static int TextFormat(ProjectSettings settings) => int.Max(settings.Version, settings.WrittenFormat);
/// <summary>
/// The settings format a render of <paramref name="settings"/> with <paramref name="export"/> and each of its batch
/// presets needs (the highest <see cref="RenderRules.RequiredFormat"/> of them): what a server or a render node must read
@@ -138,8 +175,8 @@ public static class ProcessingJobs
{
ArgumentNullException.ThrowIfNull(settings);
ArgumentNullException.ThrowIfNull(export);
return BatchPresets(export).Select(id => ExportResolver.Resolve(BatchExport(export, id))).Prepend(ExportResolver.Resolve(export))
.Max(resolved => RequiredFormat(settings, resolved, sourceWidth, sourceHeight));
return BatchPresets(export).Select(id => BatchExport(export, id)).Prepend(export)
.Max(each => RequiredFormat(settings with { Export = each }, ExportResolver.Resolve(each), sourceWidth, sourceHeight));
}
/// <summary>
@@ -182,9 +219,12 @@ public static class ProcessingJobs
.Where(id => !id.Equals(main, StringComparison.OrdinalIgnoreCase));
}
/// <summary>A batch preset rendered with its own values, named and placed like the export it belongs to.</summary>
/// <summary>
/// A batch preset rendered with its own values, named, placed and played like the export it belongs to: its playback
/// (owner review 1, R8: direction, loops, fades, hold) lives in the export, so every batch preset inherits it.
/// </summary>
internal static ExportSettings BatchExport(ExportSettings export, string presetId) =>
new() { Preset = new Auto<string>().WithManual(presetId), NameTemplate = export.NameTemplate, Folder = export.Folder };
new() { Preset = new Auto<string>().WithManual(presetId), NameTemplate = export.NameTemplate, Folder = export.Folder, Playback = export.Playback };
/// <param name="settings">The settings rendered, for the output size and the format (else read from <paramref name="settingsJson"/>); unknown, the preset's size.</param>
private static RenderJobParameters Parameters(ExportSettings export, int sourceWidth, int sourceHeight, string? settingsJson, bool useProxies,
@@ -194,7 +234,11 @@ public static class ProcessingJobs
settings ??= ReadSettings(settingsJson);
var (width, height) = (settings is null ? null : Size(settings, resolved, sourceWidth, sourceHeight))
?? (resolved.Width > 0 ? resolved.Width : sourceWidth, resolved.Height > 0 ? resolved.Height : sourceHeight);
var format = settings is null ? ProjectSettings.BaseVersion : RequiredFormat(settings, resolved, sourceWidth, sourceHeight);
// The format of what renders: the settings with this export in place of their own (its playback raises it to 3), and
// never less than the format of the settings text the node parses.
var format = settings is null
? new ProjectSettings { Export = export }.RequiredFormat
: int.Max(TextFormat(settings), RequiredFormat(settings with { Export = export }, resolved, sourceWidth, sourceHeight));
return new RenderJobParameters(PresetName(resolved), JsonSerializer.Serialize(export, ProcessingJson.Default.ExportSettings), CodecName(resolved.Codec),
width, height, useProxies, settingsJson, RequiredSettingsFormat: format);
}
+72 -5
View File
@@ -98,13 +98,14 @@ internal sealed class SequenceRender : IAsyncDisposable
outcomes.Add(new TargetOutcome(target, null, Reason(ex)));
continue;
}
if (setup.Encoder.IsReady && setup.Plan.Frames.Count > 0) ready.Add((index, target, setup));
if (setup.Encoder.IsReady && setup.Program.Count > 0) ready.Add((index, target, setup));
else outcomes.Add(new TargetOutcome(target, null, Reason(setup)));
}
if (ready.Count == 0) return outcomes;
var preparing = ready[0].Setup.NeedsPreparation ? ready[0].Setup.Plan.IncludedFrames.Count : 0;
var total = preparing + ready.Sum(r => (long)r.Setup.Plan.Frames.Count);
// Rendered pictures are counted in the output program's entries (loops, a boomerang and fades add to the plan's).
var total = preparing + ready.Sum(r => (long)r.Setup.Program.Count);
var stage = Loc.L("Export.Job.Preparing");
var chain = new ProgressChain(progress);
var corrections = await RenderPreparation.PrepareAsync(Input, _options, Stage(chain, 0, preparing, total, stage), cancellationToken).ConfigureAwait(false);
@@ -119,7 +120,7 @@ internal sealed class SequenceRender : IAsyncDisposable
try
{
var result = await Pipeline(target.Export).RenderAsync(Input, corrections, new RenderTarget(target.Export, output), _options,
Stage(chain, done, setup.Plan.Frames.Count, total, target.PresetName), cancellationToken).ConfigureAwait(false);
Stage(chain, done, setup.Program.Count, total, target.PresetName), cancellationToken).ConfigureAwait(false);
await chain.FlushAsync().ConfigureAwait(false);
await finished(index, target, result).ConfigureAwait(false);
outcomes.Add(new TargetOutcome(target, result, null));
@@ -129,11 +130,77 @@ internal sealed class SequenceRender : IAsyncDisposable
Core.Diagnostics.Log.Warning("processing", $"Render of {target.PresetName} to {output} failed", ex);
outcomes.Add(new TargetOutcome(target, null, Reason(ex)));
}
done += setup.Plan.Frames.Count;
done += setup.Program.Count;
}
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 rendered by the pipeline's still path (<see cref="RenderTarget.StillFrame"/>) at the export's output size
/// with every correction and the look, without stacking, interpolation, motion blur or playback, through the image
/// encoder of <paramref name="target"/>'s codec (PNG, JPEG or TIFF 16-bit). The encoder writes a temporary name and
/// renames it once complete, so a cancelled or failed still leaves nothing behind.
/// </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);
var pipeline = Pipeline(target.Export);
var setup = pipeline.Setup(Input, new RenderTarget(target.Export, ExportNaming.FallbackName, frameIndex), _options);
if (!setup.Encoder.IsReady)
{
var notice = setup.Encoder.Notices.LastOrDefault() ?? new EncoderNotice(EncoderNotices.NoEncoder, setup.Encoder.Settings.Codec.ToString());
throw new RenderException(notice.Key, $"No encoder can save {target.Export.Codec} here ({setup.Encoder.Status})", notice.Args);
}
var output = name(setup);
await starting(output).ConfigureAwait(false);
var chain = new ProgressChain(progress);
var preparing = setup.NeedsPreparation ? setup.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);
await chain.FlushAsync().ConfigureAwait(false);
var result = await pipeline.RenderAsync(Input, corrections, new RenderTarget(target.Export, output, frameIndex), _options,
Stage(chain, preparing, 1, total, target.PresetName), cancellationToken).ConfigureAwait(false);
await chain.FlushAsync().ConfigureAwait(false);
return result;
}
/// <summary>
/// The path of a still of frame <paramref name="frameIndex"/> (0-based) in <paramref name="folder"/> (or the export's own
/// folder): <see cref="ExportNaming.StillPath(ExportSettings, string, ExportNameContext, int, Func{string, bool}?)"/>,
/// "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) =>
ExportNaming.StillPath(export, folder, context, frameIndex, 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 (the frames may have moved since), null when that photo is no
/// longer in the sequence (the index would name another photo now); without a hash (a photo not hashed yet) 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 null;
}
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()
{
@@ -166,7 +233,7 @@ internal sealed class SequenceRender : IAsyncDisposable
private static string Reason(RenderSetup setup)
{
if (setup.Plan.Frames.Count == 0) return Loc.L("Export.Render.NoFrames");
if (setup.Program.Count == 0) return Loc.L("Export.Render.NoFrames");
var notice = setup.Encoder.Notices.LastOrDefault() ?? new EncoderNotice(EncoderNotices.NoEncoder, setup.Encoder.Settings.Codec.ToString());
return Loc.L(notice.Key, [.. notice.Args]);
}