feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
Owner review 1 R5 + R6. Camera rotation, mirror, flip, straighten and crop handles locked to the output; an Exposure Look group; Export output size ("proportions win"); settings format 2 with older-node gates. Also fixes project text and hashes differing between Windows and Linux.
Closes #19
Closes #20
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 #26.
This commit is contained in:
1 parent
db389a54f2
commit
188b2c2e55
355 files changed
+10549
-1061
No files matched your search
@@ -2,6 +2,8 @@ using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Protocol;
|
||||
@@ -32,8 +34,11 @@ internal sealed class ManagedRenderJobHandler(RenderJobHandler render, Processin
|
||||
try
|
||||
{
|
||||
parameters = ProcessingJobs.ReadParameters(job.ParametersJson);
|
||||
// Most jobs are decided by the main codec, before the export is read.
|
||||
if (Produces(parameters.Codec) && RenderJobHandler.Targets(ProcessingJobs.ReadExport(parameters.PresetJson), parameters.PresetName).All(t => Produces(t.Export)))
|
||||
// Most jobs are decided by the main codec, before the export is read. The job's own output is checked at the size the
|
||||
// job names (the server's: the chosen proportions fitted in a fixed-size preset, owner review 1, phase 4).
|
||||
if (Produces(parameters.Codec) && RenderJobHandler.Targets(ProcessingJobs.ReadExport(parameters.PresetJson), parameters.PresetName)
|
||||
.Select((t, i) => i == 0 && t.Export is { Width: > 0, Height: > 0 } ? Produces(t.Export, parameters.Width, parameters.Height) : Produces(t.Export))
|
||||
.All(produced => produced))
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
@@ -55,7 +60,7 @@ internal sealed class ManagedRenderJobHandler(RenderJobHandler render, Processin
|
||||
}
|
||||
|
||||
public Task RunAsync(JobContext context) =>
|
||||
render.RunAsync(context, target => Produces(target.Export) ? target : Fallback(context, target));
|
||||
render.RunAsync(context, (target, project) => Produces(target.Export, project) ? target : Fallback(context, target));
|
||||
|
||||
/// <summary>The output as MJPEG in AVI with the managed preset's quality, at the size and frame rate asked for.</summary>
|
||||
private static ExportTarget Fallback(JobContext context, ExportTarget target)
|
||||
@@ -83,6 +88,21 @@ internal sealed class ManagedRenderJobHandler(RenderJobHandler render, Processin
|
||||
private bool Produces(string codec) =>
|
||||
_capabilities.Any(c => string.Equals(ProcessingJobs.CodecName(c.Codec), codec, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
private bool Produces(ResolvedExport export) =>
|
||||
_capabilities.Any(c => c.Codec == export.Codec && export.Width <= c.MaxWidth && export.Height <= c.MaxHeight);
|
||||
/// <summary>A managed encoder writes <paramref name="export"/> at the preset's size (a free-size preset is not checked by size).</summary>
|
||||
private bool Produces(ResolvedExport export) => Produces(export, export.Width, export.Height);
|
||||
|
||||
/// <summary>
|
||||
/// A managed encoder writes <paramref name="export"/> at the size <paramref name="project"/> gives it: a fixed-size preset
|
||||
/// adapted to the chosen proportions (<see cref="RenderSize"/>, 4K at 9:16 = 2160×3840).
|
||||
/// </summary>
|
||||
private bool Produces(ResolvedExport export, ProjectSettings project)
|
||||
{
|
||||
if (export is not { Width: > 0, Height: > 0 }) return Produces(export);
|
||||
// A fixed-size preset's output does not depend on the source's size.
|
||||
var (width, height) = RenderSize.Of(project.Camera, export, export.Width, export.Height);
|
||||
return Produces(export, width, height);
|
||||
}
|
||||
|
||||
private bool Produces(ResolvedExport export, int width, int height) =>
|
||||
_capabilities.Any(c => c.Codec == export.Codec && EncoderSelector.Takes(c, width, height));
|
||||
}
|
||||
@@ -30,10 +30,13 @@ internal sealed class RenderJobHandler(ChronosDatabase db, ProcessingOptions opt
|
||||
{
|
||||
public JobKind Kind => JobKind.Render;
|
||||
|
||||
public Task RunAsync(JobContext context) => RunAsync(context, target => target);
|
||||
public Task RunAsync(JobContext context) => RunAsync(context, (target, _) => target);
|
||||
|
||||
/// <summary>Runs the job with each output still to render passed through <paramref name="adapt"/> (the server's managed stand-ins).</summary>
|
||||
internal async Task RunAsync(JobContext context, Func<ExportTarget, ExportTarget> adapt)
|
||||
/// <summary>
|
||||
/// Runs the job with each output still to render passed through <paramref name="adapt"/> with the settings rendered (the
|
||||
/// server's managed stand-ins, which look at the size those settings give the output).
|
||||
/// </summary>
|
||||
internal async Task RunAsync(JobContext context, Func<ExportTarget, ProjectSettings, ExportTarget> adapt)
|
||||
{
|
||||
var cancellation = context.Cancellation;
|
||||
var (parameters, export) = ProcessingJobs.ReadRender(context.Job.ParametersJson);
|
||||
@@ -72,7 +75,7 @@ internal sealed class RenderJobHandler(ChronosDatabase db, ProcessingOptions opt
|
||||
Discard(output, keepOutput: recorded.Any(r => r.OutputPath == Stored(paths, output)));
|
||||
names.Release(output); // free again for the entry's new attempt
|
||||
}
|
||||
var targets = all.Select((t, i) => (i, t)).Where(t => !done.Contains(t.i)).Select(t => (t.i, adapt(t.t))).ToList();
|
||||
var targets = all.Select((t, i) => (i, t)).Where(t => !done.Contains(t.i)).Select(t => (t.i, adapt(t.t, project))).ToList();
|
||||
if (targets.Count == 0) return;
|
||||
|
||||
var companions = await GprCompanions.FindAsync(db, archive, frames.Frames, cancellation).ConfigureAwait(false);
|
||||
@@ -154,7 +157,7 @@ internal sealed class RenderJobHandler(ChronosDatabase db, ProcessingOptions opt
|
||||
|| await db.Projects.GetVersionAsync(versionId, cancellationToken).ConfigureAwait(false) is not { } version
|
||||
|| (project is { } named && version.ProjectId != named)
|
||||
|| await db.Projects.GetAsync(version.ProjectId, cancellationToken).ConfigureAwait(false) is not { } of || of.SequenceId != sequence.Id
|
||||
|| (parameters.SettingsJson is { } embedded && !ProjectContent.Verifies(embedded, version.ContentHash)))
|
||||
|| (parameters.SettingsJson is { } embedded && !ProjectContent.MatchesHash(embedded, version.ContentHash)))
|
||||
return (project, null);
|
||||
return (version.ProjectId, versionId);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Chronos.Core.Export;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Data.Archiving.Jobs;
|
||||
using Chronos.Protocol;
|
||||
@@ -28,15 +29,17 @@ public static class ProcessingJobs
|
||||
/// <summary>
|
||||
/// <see cref="JobKind.Render"/> of one sequence. <paramref name="export"/> (preset, overrides, name template,
|
||||
/// folder, batch) replaces the project's export section; <paramref name="project"/> embeds the settings to render,
|
||||
/// null renders the sequence's current project. <paramref name="sourceWidth"/>×<paramref name="sourceHeight"/>
|
||||
/// stands in for a preset without a fixed size, so render nodes can match the job by resolution.
|
||||
/// null renders the sequence's current project. <paramref name="sourceWidth"/>×<paramref name="sourceHeight"/> (the
|
||||
/// frames' Exif-oriented size) gives the output size of the settings rendered (<see cref="RenderSize"/>; the sequence's
|
||||
/// own when <paramref name="project"/> is null), so render nodes can match the job by resolution, and the settings
|
||||
/// format the render needs (<see cref="RenderRules.RequiredFormat"/>).
|
||||
/// </summary>
|
||||
public static ArchiveJobRequest Render(Sequence sequence, ExportSettings export, int sourceWidth, int sourceHeight, ProjectSettings? project = null,
|
||||
bool useProxies = false)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sequence);
|
||||
ArgumentNullException.ThrowIfNull(export);
|
||||
var parameters = Parameters(export, sourceWidth, sourceHeight, project?.ToJson(), useProxies);
|
||||
var parameters = Parameters(export, sourceWidth, sourceHeight, project?.ToJson(), useProxies, project ?? ReadSettings(sequence.SettingsJson));
|
||||
return new ArchiveJobRequest(JobKind.Render, [sequence.Id], RenderLabel(sequence.DisplayTitle, parameters.PresetName),
|
||||
JsonSerializer.Serialize(parameters, ProtocolJson.Default.RenderJobParameters), JobPriority.User);
|
||||
}
|
||||
@@ -80,20 +83,22 @@ public static class ProcessingJobs
|
||||
/// <summary>
|
||||
/// A posted render job as one job per preset, as <see cref="RenderEach"/> makes them (a render node uploads one file
|
||||
/// per job): the job itself when it has no batch; otherwise its own preset, then each batch preset with its own values,
|
||||
/// all with the job's project and proxy choice. <paramref name="sourceWidth"/>×<paramref name="sourceHeight"/> stands in
|
||||
/// for a batch preset without a fixed size.
|
||||
/// all with the job's project and proxy choice. <paramref name="sourceWidth"/>×<paramref name="sourceHeight"/> (the
|
||||
/// frames' Exif-oriented size) stands in for a batch preset without a fixed size. With the <paramref name="settings"/>
|
||||
/// the job renders, every job gets the output size and the settings format its render needs (<see cref="Routed"/>);
|
||||
/// without them, the job keeps the size it was posted with and each batch preset its preset's.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidDataException">The preset JSON is not an export section.</exception>
|
||||
public static IReadOnlyList<RenderJobParameters> Split(RenderJobParameters parameters, int sourceWidth, int sourceHeight)
|
||||
public static IReadOnlyList<RenderJobParameters> Split(RenderJobParameters parameters, int sourceWidth, int sourceHeight, ProjectSettings? settings = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(parameters);
|
||||
var export = ReadExport(parameters.PresetJson);
|
||||
var batch = BatchPresets(export).ToList();
|
||||
if (batch.Count == 0) return [parameters];
|
||||
var own = batch.Count == 0 ? parameters : parameters with { PresetJson = JsonSerializer.Serialize(export with { Batch = [] }, ProcessingJson.Default.ExportSettings) };
|
||||
return
|
||||
[
|
||||
parameters with { PresetJson = JsonSerializer.Serialize(export with { Batch = [] }, ProcessingJson.Default.ExportSettings) },
|
||||
.. batch.Select(id => Parameters(BatchExport(export, id), sourceWidth, sourceHeight, parameters.SettingsJson, parameters.UseProxies) with
|
||||
settings is null ? own : Routed(own, settings, sourceWidth, sourceHeight),
|
||||
.. batch.Select(id => Parameters(BatchExport(export, id), sourceWidth, sourceHeight, parameters.SettingsJson, parameters.UseProxies, settings) with
|
||||
{
|
||||
ProjectId = parameters.ProjectId,
|
||||
ProjectVersionId = parameters.ProjectVersionId,
|
||||
@@ -101,6 +106,59 @@ public static class ProcessingJobs
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A render job's parameters with the output size and the settings format a render of <paramref name="settings"/> needs
|
||||
/// (owner review 1, phase 4: the chosen proportions win over a fixed-size preset, a quarter turn swaps a source-sized
|
||||
/// output). The size comes from the job's preset, as the render does: never from the size the job was posted with,
|
||||
/// which a newer client already adapted to the settings of the moment (a long edge kept for 1:1 cannot be adapted back
|
||||
/// to 16:9 once the sequence's settings change). Other presets are sized on the source. The format is at least the one
|
||||
/// the job was posted with.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidDataException">The preset JSON is not an export section.</exception>
|
||||
public static RenderJobParameters Routed(RenderJobParameters parameters, ProjectSettings settings, int sourceWidth, int sourceHeight)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(parameters);
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
var resolved = ExportResolver.Resolve(ReadExport(parameters.PresetJson));
|
||||
var (width, height) = Size(settings, resolved, sourceWidth, sourceHeight) ?? (parameters.Width, parameters.Height);
|
||||
return parameters with
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
RequiredSettingsFormat = int.Max(parameters.RequiredSettingsFormat, RequiredFormat(settings, resolved, sourceWidth, sourceHeight)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <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
|
||||
/// to render it as this Chronos would.
|
||||
/// </summary>
|
||||
public static int RequiredFormat(ProjectSettings settings, ExportSettings export, int sourceWidth, int sourceHeight)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Project settings read for their output size and format, a newer Chronos's too (its format stands); null when there
|
||||
/// are none or the text is not a project.
|
||||
/// </summary>
|
||||
public static ProjectSettings? ReadSettings(string? settingsJson)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(settingsJson)) return null;
|
||||
try
|
||||
{
|
||||
return ProjectSettings.FromJson(settingsJson, allowNewer: true);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One <see cref="Render"/> job per preset of <paramref name="export"/>: its preset, then each batch preset with its
|
||||
/// own values. For a server: a render node uploads one file per job, so a batch must not travel as one job.
|
||||
@@ -128,13 +186,27 @@ public static class ProcessingJobs
|
||||
internal static ExportSettings BatchExport(ExportSettings export, string presetId) =>
|
||||
new() { Preset = new Auto<string>().WithManual(presetId), NameTemplate = export.NameTemplate, Folder = export.Folder };
|
||||
|
||||
private static RenderJobParameters Parameters(ExportSettings export, int sourceWidth, int sourceHeight, string? settingsJson, bool useProxies)
|
||||
/// <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,
|
||||
ProjectSettings? settings = null)
|
||||
{
|
||||
var resolved = ExportResolver.Resolve(export);
|
||||
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);
|
||||
return new RenderJobParameters(PresetName(resolved), JsonSerializer.Serialize(export, ProcessingJson.Default.ExportSettings), CodecName(resolved.Codec),
|
||||
resolved.Width > 0 ? resolved.Width : sourceWidth, resolved.Height > 0 ? resolved.Height : sourceHeight, useProxies, settingsJson);
|
||||
width, height, useProxies, settingsJson, RequiredSettingsFormat: format);
|
||||
}
|
||||
|
||||
/// <summary>The output size of <paramref name="settings"/> with <paramref name="export"/> (<see cref="RenderSize.Of"/>); null without a source size.</summary>
|
||||
private static (int Width, int Height)? Size(ProjectSettings settings, ResolvedExport export, int sourceWidth, int sourceHeight) =>
|
||||
sourceWidth > 0 && sourceHeight > 0 ? RenderSize.Of(settings.Camera, export, sourceWidth, sourceHeight) : null;
|
||||
|
||||
/// <summary><see cref="RenderRules.RequiredFormat"/>; without a source size, the format the settings are written in.</summary>
|
||||
private static int RequiredFormat(ProjectSettings settings, ResolvedExport export, int sourceWidth, int sourceHeight) =>
|
||||
sourceWidth > 0 && sourceHeight > 0 ? RenderRules.RequiredFormat(settings, export, sourceWidth, sourceHeight) : settings.WrittenFormat;
|
||||
|
||||
/// <summary>Codec name in job parameters and render-node capabilities ("h264", "hevc", "mjpeg", "pngsequence"…).</summary>
|
||||
public static string CodecName(VideoCodec codec) => codec.ToString().ToLowerInvariant();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
@@ -22,7 +23,10 @@ internal sealed class ProjectStore(ChronosDatabase db, SequenceWriter writer)
|
||||
public static ProjectSettings Read(Sequence sequence, SequencePaths folder) =>
|
||||
Parse(sequence.SettingsJson ?? (File.Exists(folder.ProjectPath) ? AtomicFile.ReadAllText(folder.ProjectPath) : null));
|
||||
|
||||
/// <exception cref="InvalidDataException">The settings are not valid JSON or come from a newer Chronos.</exception>
|
||||
/// <exception cref="InvalidDataException">
|
||||
/// The settings are not valid JSON, or come from a newer Chronos (<c>Errors.Render.NewerSettings</c>, which a render's
|
||||
/// job shows as its error).
|
||||
/// </exception>
|
||||
public static ProjectSettings Parse(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json)) return new ProjectSettings();
|
||||
@@ -34,6 +38,11 @@ internal sealed class ProjectStore(ChronosDatabase db, SequenceWriter writer)
|
||||
{
|
||||
throw new InvalidDataException(ex.Message, ex);
|
||||
}
|
||||
catch (InvalidDataException ex)
|
||||
{
|
||||
// A settings format above this Chronos's (owner review 1, phase 4: a server, a node or a desktop that is older).
|
||||
throw new InvalidDataException(Loc.L("Errors.Render.NewerSettings"), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Applies <paramref name="edit"/> to the settings in force and stores the result when it differs; false when nothing changed.</summary>
|
||||
|
||||
@@ -7,6 +7,7 @@ using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Data.Archiving;
|
||||
@@ -117,10 +118,11 @@ public sealed class RenderNodeClient : IAsyncDisposable
|
||||
/// <summary>Registers this node (again) and returns its id.</summary>
|
||||
public async Task<Guid> RegisterAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// Each encoder carries its own limit; the node-wide one (for servers that read only that) is the largest offered.
|
||||
// Each encoder carries its own limit; the node-wide one (for servers that read only that) is the largest offered. The
|
||||
// settings format the node reads keeps it from jobs it would render otherwise than asked (owner review 1, phase 4).
|
||||
var encoders = Encoders;
|
||||
var request = new RegisterNodeRequest(_options.ClientName, encoders, encoders.Select(e => e.MaxWidth).DefaultIfEmpty().Max(),
|
||||
encoders.Select(e => e.MaxHeight).DefaultIfEmpty().Max());
|
||||
encoders.Select(e => e.MaxHeight).DefaultIfEmpty().Max(), ProjectSettings.CurrentVersion);
|
||||
var node = await _client.RegisterNodeAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
_nodeId = node.Id;
|
||||
return node.Id;
|
||||
|
||||
@@ -137,9 +137,9 @@ internal sealed class SequenceAnalyser(ChronosDatabase db, ProcessingOptions opt
|
||||
}
|
||||
try
|
||||
{
|
||||
// The frame rate follows the user's "fit to N seconds" when one is set (BRIEF §10.3).
|
||||
// The frame rate follows the user's "fit to N seconds" when one is set (BRIEF §10.3), the aspect the camera's turns.
|
||||
changed = await projects.UpdateLockedAsync(paths, sequence,
|
||||
settings => Advisor.Apply(settings, Advisor.Recommend(light, report, context with { TargetDurationSeconds = settings.Timing.FitToSeconds })),
|
||||
settings => Advisor.Apply(settings, Advisor.Recommend(light, report, context.ForCamera(settings.Camera) with { TargetDurationSeconds = settings.Timing.FitToSeconds })),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (InvalidDataException ex)
|
||||
|
||||
Reference in new issue
Block a user