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
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:
1 parent
188b2c2e55
commit
728ffa35cb
729 files changed
+26954
-1652
No files matched your search
@@ -16,7 +16,9 @@ namespace Chronos.Core.Render;
|
||||
/// <see cref="IRenderFrameSource"/> at the working size; per-frame exposure corrections (deflicker, holy grail, white
|
||||
/// balance, regions) are applied; stabilisation, virtual camera and crop are resampled once to the output size;
|
||||
/// fractional positions are synthesised from the bidirectional flow; motion blur follows the flow with shutter-angle
|
||||
/// composition; stacking (median, mean, star trails) and the finish (look, then highlight knee: <see cref="FrameFinish"/>) come last, then the encoder. Encoding of a
|
||||
/// composition; stacking (median, mean, star trails) and the finish (look, then highlight knee, then the fade:
|
||||
/// <see cref="FrameFinish"/>) come last, then the encoder. Frames are rendered in the order of the <see cref="OutputProgram"/>
|
||||
/// (direction, loops, hold, fades); a still target renders one source frame into one image. Encoding of a
|
||||
/// frame overlaps the processing of the next. Cancellation and failures leave no output behind (sessions delete their
|
||||
/// partial files on dispose) and every background task is awaited, so exceptions surface exactly once.
|
||||
/// </summary>
|
||||
@@ -60,7 +62,7 @@ public sealed class RenderPipeline(IReadOnlyList<IVideoEncoderProvider> encoders
|
||||
var notice = setup.Encoder.Notices.LastOrDefault() ?? new EncoderNotice(EncoderNotices.NoEncoder, setup.Encoder.Settings.Codec.ToString());
|
||||
throw new RenderException(notice.Key, $"No encoder can produce {target.Export.Codec} here ({setup.Encoder.Status})", notice.Args);
|
||||
}
|
||||
if (setup.Plan.Frames.Count == 0) throw new RenderException("Export.Render.NoFrames", "Every frame is excluded.");
|
||||
if (setup.Still is null && setup.Program.Count == 0) throw new RenderException("Export.Render.NoFrames", "Every frame is excluded.");
|
||||
using var run = new RenderRun(input, corrections, setup, options, progress);
|
||||
return await run.ExecuteAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -98,12 +100,16 @@ internal sealed class RenderRun : IDisposable
|
||||
/// <summary>Largest speed (source frames per output period) that scales motion blur; faster plans blur no further.</summary>
|
||||
private const double MaxBlurSpeed = 4;
|
||||
|
||||
/// <summary>Warning key prefix of a setting the encoder refused (<see cref="IVideoEncoderSession.Ignored"/>), followed by its <see cref="EncoderSetting"/>.</summary>
|
||||
internal const string IgnoredWarningPrefix = "Export.Encoder.Ignored.";
|
||||
|
||||
private readonly RenderInput _input;
|
||||
private readonly RenderCorrections _corrections;
|
||||
private readonly RenderSetup _setup;
|
||||
private readonly RenderOptions _options;
|
||||
private readonly IProgress<RenderProgress>? _progress;
|
||||
private readonly RenderPlan _plan;
|
||||
private readonly OutputProgram _program;
|
||||
private readonly RenderGeometry _geometry;
|
||||
private readonly PreparedFrameCache _prepared;
|
||||
private readonly FlowCache _flows = new(2);
|
||||
@@ -129,6 +135,7 @@ internal sealed class RenderRun : IDisposable
|
||||
_options = options;
|
||||
_progress = progress;
|
||||
_plan = setup.Plan;
|
||||
_program = setup.Program;
|
||||
_geometry = setup.Geometry;
|
||||
_prepared = new PreparedFrameCache(int.Max(3, options.CacheFrames));
|
||||
_workingEdge = _geometry.WorkingLongEdge;
|
||||
@@ -148,14 +155,19 @@ internal sealed class RenderRun : IDisposable
|
||||
{
|
||||
var settings = _setup.Encoder.Settings;
|
||||
_clock.Start();
|
||||
Log.Info(RenderPipeline.LogCategory, $"Rendering {_plan.Frames.Count} frames ({_plan.SlotCount} periods) to {settings.Codec} {settings.Width}×{settings.Height} @ {settings.FrameRate}: {settings.OutputPath}");
|
||||
if (_setup.Still is { } still)
|
||||
Log.Info(RenderPipeline.LogCategory, $"Saving frame {still.From} as {settings.Codec} {settings.Width}×{settings.Height}: {settings.OutputPath}");
|
||||
else
|
||||
Log.Info(RenderPipeline.LogCategory, $"Rendering {_program.Count} frames of a {_plan.Frames.Count}-frame plan ({_plan.SlotCount} periods) to {settings.Codec} {settings.Width}×{settings.Height} @ {settings.FrameRate}: {settings.OutputPath}");
|
||||
var session = _session = _setup.Encoder.Open();
|
||||
IReadOnlyList<EncoderSetting> ignored;
|
||||
try
|
||||
{
|
||||
await RenderFramesAsync(cancellationToken).ConfigureAwait(false);
|
||||
await FlushEncodingAsync().ConfigureAwait(false);
|
||||
_progress?.Report(new RenderProgress(RenderStage.Finishing, _done, _plan.Frames.Count, Fps(), _clock.Elapsed, TimeSpan.Zero));
|
||||
_progress?.Report(new RenderProgress(RenderStage.Finishing, _done, _program.Count, Fps(), _clock.Elapsed, TimeSpan.Zero));
|
||||
session.Complete();
|
||||
ignored = [.. session.Ignored];
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -170,6 +182,8 @@ internal sealed class RenderRun : IDisposable
|
||||
var warnings = new List<RenderWarning>(_setup.Warnings);
|
||||
warnings.AddRange(_corrections.Report.Warnings);
|
||||
warnings.AddRange(_warnings);
|
||||
// What the encoder did not take: the output was encoded with its own value, which the job's log says.
|
||||
warnings.AddRange(ignored.Select(s => new RenderWarning(IgnoredWarningPrefix + s)));
|
||||
var result = new RenderResult
|
||||
{
|
||||
OutputPath = settings.OutputPath,
|
||||
@@ -178,8 +192,9 @@ internal sealed class RenderRun : IDisposable
|
||||
Width = settings.Width,
|
||||
Height = settings.Height,
|
||||
FrameRate = settings.FrameRate,
|
||||
DurationSeconds = _plan.DurationSeconds,
|
||||
FrameCount = _plan.Frames.Count,
|
||||
DurationSeconds = _setup.Still is null ? _program.DurationSeconds : 0,
|
||||
FrameCount = _program.Count,
|
||||
Kind = _setup.Still is null ? null : Model.RenderKind.Still,
|
||||
Bytes = RenderResult.SizeOf(settings.OutputPath),
|
||||
EncoderName = session.EncoderName,
|
||||
Hardware = session.IsHardware,
|
||||
@@ -199,6 +214,13 @@ internal sealed class RenderRun : IDisposable
|
||||
|
||||
private async Task RenderFramesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_setup.Still is { } still)
|
||||
{
|
||||
// Save frame: the one source frame, whole, with every correction and the finish; no stacking and no playback.
|
||||
var picture = await RenderFrameAsync(still, blur: false, cancellationToken).ConfigureAwait(false);
|
||||
await EmitAsync(picture, new ProgramEntry(0, still.Duration90k, 1)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var stack = _input.Project.Stack;
|
||||
switch (stack.Mode)
|
||||
{
|
||||
@@ -206,58 +228,132 @@ internal sealed class RenderRun : IDisposable
|
||||
await RenderWindowStackAsync(stack, cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
case StackSetting.StarTrails:
|
||||
using (var trails = new StarTrailStacker(StarTrailStacker.DecayForTrailLength(stack.Length > 0 ? stack.Length : double.PositiveInfinity)))
|
||||
// The trails accumulate in program order: a reversed video grows its trails from the end, and each loop grows
|
||||
// them again from nothing (a stacker carried over would freeze on the trails the first pass finished).
|
||||
var decay = StarTrailStacker.DecayForTrailLength(stack.Length > 0 ? stack.Length : double.PositiveInfinity);
|
||||
StarTrailStacker? trails = null;
|
||||
var pass = -1;
|
||||
try
|
||||
{
|
||||
foreach (var planned in _plan.Frames)
|
||||
await RenderProgramAsync(async (entry, token) =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
using (var frame = await RenderFrameAsync(planned, blur: false, cancellationToken).ConfigureAwait(false)) trails.Add(frame);
|
||||
await EmitAsync(trails.Result!.Clone(), planned.Duration90k).ConfigureAwait(false);
|
||||
}
|
||||
if (entry.Pass != pass || trails is null)
|
||||
{
|
||||
trails?.Dispose();
|
||||
trails = new StarTrailStacker(decay);
|
||||
pass = entry.Pass;
|
||||
}
|
||||
using (var frame = await RenderFrameAsync(_plan.Frames[entry.PlanIndex], blur: false, token).ConfigureAwait(false)) trails.Add(frame);
|
||||
return trails.Result!.Clone();
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
trails?.Dispose();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
foreach (var planned in _plan.Frames)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var frame = await RenderFrameAsync(planned, _setup.MotionBlur, cancellationToken).ConfigureAwait(false);
|
||||
await EmitAsync(frame, planned.Duration90k).ConfigureAwait(false);
|
||||
}
|
||||
await RenderProgramAsync((entry, token) => RenderFrameAsync(_plan.Frames[entry.PlanIndex], _setup.MotionBlur, token), cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Centred median/mean window: output k is emitted once frame k + half has been pushed (the tail reuses the
|
||||
/// last full window).</summary>
|
||||
/// <summary>
|
||||
/// Emits the program's entries in order, each rendered by <paramref name="render"/> from its plan index. Consecutive
|
||||
/// entries of one plan frame and one pass (a held frame split over the periods of a fade) share one rendering, so a
|
||||
/// stack folds it in once; every other entry is rendered again (a boomerang's way back, each loop).
|
||||
/// </summary>
|
||||
private async Task RenderProgramAsync(Func<ProgramEntry, CancellationToken, Task<ImageBuffer>> render, CancellationToken cancellationToken)
|
||||
{
|
||||
var entries = _program.Entries;
|
||||
ImageBuffer? kept = null;
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < entries.Count; i++)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var entry = entries[i];
|
||||
var frame = kept ?? await render(entry, cancellationToken).ConfigureAwait(false);
|
||||
kept = null;
|
||||
if (i + 1 < entries.Count && entries[i + 1].PlanIndex == entry.PlanIndex && entries[i + 1].Pass == entry.Pass)
|
||||
{
|
||||
try
|
||||
{
|
||||
kept = frame.Clone();
|
||||
}
|
||||
catch
|
||||
{
|
||||
frame.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
await EmitAsync(frame, entry).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
kept?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Median/mean stacks, one centred window per plan frame whatever the program's order: frame k combines plan frames
|
||||
/// k − half … k + half, cut to the plan at the start and shifted inside it at the end (as a forward render always did).
|
||||
/// Stepping to the next frame in the direction the program travels pushes one frame; a turn or the shrinking window at the
|
||||
/// plan's start fills the window again.
|
||||
/// </summary>
|
||||
private async Task RenderWindowStackAsync(StackSettings stack, CancellationToken cancellationToken)
|
||||
{
|
||||
var window = int.Max(1, stack.Length);
|
||||
var half = (window - 1) / 2;
|
||||
var last = _plan.Frames.Count - 1;
|
||||
using var stacker = new TemporalStacker(window, stack.Mode == StackSetting.Median ? StackMode.Median : StackMode.Mean);
|
||||
var pending = new Queue<PlannedFrame>();
|
||||
foreach (var planned in _plan.Frames)
|
||||
// Plan indices in the stacker, oldest (the next evicted) first.
|
||||
var held = new List<int>(window + 1);
|
||||
var previous = -1;
|
||||
await RenderProgramAsync(async (entry, token) =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
using (var frame = await RenderFrameAsync(planned, blur: false, cancellationToken).ConfigureAwait(false)) stacker.Push(frame);
|
||||
pending.Enqueue(planned);
|
||||
if (pending.Count > half) await EmitStackAsync(stacker, pending.Dequeue(), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
while (pending.Count > 0) await EmitStackAsync(stacker, pending.Dequeue(), cancellationToken).ConfigureAwait(false);
|
||||
var index = entry.PlanIndex;
|
||||
var hi = int.Min(index + half, last);
|
||||
var lo = int.Max(0, hi - window + 1);
|
||||
await WindowAsync(stacker, held, lo, hi, index >= previous, token).ConfigureAwait(false);
|
||||
previous = index;
|
||||
var output = new ImageBuffer(_geometry.OutputWidth, _geometry.OutputHeight, 3, clear: false);
|
||||
try
|
||||
{
|
||||
stacker.Render(output, token);
|
||||
return output;
|
||||
}
|
||||
catch
|
||||
{
|
||||
output.Dispose();
|
||||
throw;
|
||||
}
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task EmitStackAsync(TemporalStacker stacker, PlannedFrame planned, CancellationToken cancellationToken)
|
||||
/// <summary>Makes the stacker hold exactly plan frames <paramref name="lo"/>…<paramref name="hi"/>.</summary>
|
||||
private async Task WindowAsync(TemporalStacker stacker, List<int> held, int lo, int hi, bool forward, CancellationToken cancellationToken)
|
||||
{
|
||||
var output = new ImageBuffer(_geometry.OutputWidth, _geometry.OutputHeight, 3, clear: false);
|
||||
try
|
||||
bool Holds(IEnumerable<int> frames) => frames.Count() == hi - lo + 1 && frames.All(i => i >= lo && i <= hi);
|
||||
if (Holds(held)) return;
|
||||
var missing = Enumerable.Range(lo, hi - lo + 1).Where(i => !held.Contains(i)).ToList();
|
||||
if (missing.Count == 1 && Holds(held.Skip(held.Count == stacker.Window ? 1 : 0).Append(missing[0])))
|
||||
{
|
||||
stacker.Render(output, cancellationToken);
|
||||
await PushAsync(stacker, held, missing[0], cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
output.Dispose();
|
||||
throw;
|
||||
}
|
||||
await EmitAsync(output, planned.Duration90k).ConfigureAwait(false);
|
||||
stacker.Clear();
|
||||
held.Clear();
|
||||
// Pushed in the direction of travel, so the next step evicts the frame it leaves behind.
|
||||
for (var k = 0; k <= hi - lo; k++) await PushAsync(stacker, held, forward ? lo + k : hi - k, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task PushAsync(TemporalStacker stacker, List<int> held, int index, CancellationToken cancellationToken)
|
||||
{
|
||||
using (var frame = await RenderFrameAsync(_plan.Frames[index], blur: false, cancellationToken).ConfigureAwait(false)) stacker.Push(frame);
|
||||
held.Add(index);
|
||||
if (held.Count > stacker.Window) held.RemoveAt(0);
|
||||
}
|
||||
|
||||
/// <summary>The picture of one planned frame at the output size (a new buffer owned by the caller).</summary>
|
||||
@@ -400,14 +496,19 @@ internal sealed class RenderRun : IDisposable
|
||||
if (ev != 0 || (gains is { } g && g != ChannelGains.Identity)) ExposureProcessor.Apply(frame, ev, gains);
|
||||
}
|
||||
|
||||
/// <summary>Finishes the frame (look, then knee) and hands it to the encoder once the previous frame is encoded; owns <paramref name="frame"/>.</summary>
|
||||
private async Task EmitAsync(ImageBuffer frame, long duration90k)
|
||||
/// <summary>
|
||||
/// Finishes the frame (look, then knee, then the entry's fade) and hands it to the encoder for the entry's duration once
|
||||
/// the previous frame is encoded; owns <paramref name="frame"/>.
|
||||
/// </summary>
|
||||
private async Task EmitAsync(ImageBuffer frame, ProgramEntry entry)
|
||||
{
|
||||
ImageBuffer? preview = null;
|
||||
var duration90k = entry.Duration90k;
|
||||
try
|
||||
{
|
||||
await FlushEncodingAsync().ConfigureAwait(false);
|
||||
FrameFinish.Apply(frame, _look, _knee);
|
||||
if (entry.Gain < 1) FrameFinish.Fade(frame, entry.Gain);
|
||||
_done++;
|
||||
if (_options.PreviewInterval > 0 && (_done - 1) % _options.PreviewInterval == 0) preview = Resampler.Thumbnail(frame, _options.PreviewLongEdge);
|
||||
}
|
||||
@@ -424,8 +525,8 @@ internal sealed class RenderRun : IDisposable
|
||||
if (_progress is not null)
|
||||
{
|
||||
var fps = Fps();
|
||||
_progress.Report(new RenderProgress(RenderStage.Rendering, _done, _plan.Frames.Count, fps, _clock.Elapsed,
|
||||
fps > 0 ? TimeSpan.FromSeconds((_plan.Frames.Count - _done) / fps) : null, preview));
|
||||
_progress.Report(new RenderProgress(RenderStage.Rendering, _done, _program.Count, fps, _clock.Elapsed,
|
||||
fps > 0 ? TimeSpan.FromSeconds((_program.Count - _done) / fps) : null, preview));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user