fix: address the phase 5 review
Video trash moves across volumes commit once the verified copy has its name and leave an undeletable source whole behind a .leftover marker that the next start settles; deletes rehash under the lease. Restores honour the names renders are writing, and encoders never overwrite an output. Routing floors at the stored settings' format, kindless stills read as stills, star trails restart per loop, and settings the encoder ignored become render warnings. The Videos section fits beside the player, plays downloaded server copies, names blocked videos and says why actions are off; the admin panel offers no download for sequences or missing files and names a filtered sequence from its record. Refs #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d87a1bc6d
commit
1be273d0e4
38 files changed
+958
-160
No files matched your search
@@ -93,6 +93,18 @@ public static class AtomicFile
|
||||
Replace(tempPath, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commits an already-written temporary file as <paramref name="path"/>, which must not exist: an output whose free name
|
||||
/// something else took meanwhile (a restore, another program) is never overwritten.
|
||||
/// </summary>
|
||||
/// <exception cref="IOException"><paramref name="path"/> exists (the temporary file stays for the caller to discard).</exception>
|
||||
public static void CommitNew(string tempPath, string path)
|
||||
{
|
||||
using (var fs = new FileStream(tempPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
|
||||
fs.Flush(flushToDisk: true);
|
||||
File.Move(tempPath, path, overwrite: false);
|
||||
}
|
||||
|
||||
public static string TempPathFor(string path)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(Path.GetFullPath(path)) ?? ".";
|
||||
|
||||
@@ -201,11 +201,22 @@ public static class RenderKind
|
||||
: codec is { } c && c.EndsWith("sequence", StringComparison.OrdinalIgnoreCase) ? Sequence
|
||||
: Video;
|
||||
|
||||
/// <inheritdoc cref="Of(string?, string?)"/>
|
||||
/// <summary>
|
||||
/// <see cref="Of(string?, string?)"/>, telling a still apart when its kind was lost (one uploaded to a server of before
|
||||
/// phase 5, which does not record it): an image-sequence codec with fps 0 and duration 0, which every still records and
|
||||
/// no image sequence has.
|
||||
/// </summary>
|
||||
public static string Of(string? kind, string? codec, double fps, double durationSeconds)
|
||||
{
|
||||
var of = Of(kind, codec);
|
||||
return of == Sequence && fps <= 0 && durationSeconds <= 0 ? Still : of;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Of(string?, string?, double, double)"/>
|
||||
public static string Of(Render render)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(render);
|
||||
return Of(render.Kind, render.Codec);
|
||||
return Of(render.Kind, render.Codec, render.Fps, render.DurationSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace Chronos.Core.Render;
|
||||
/// <param name="Gain">The linear-light multiplier of the fade to and from black, applied after the look and the knee
|
||||
/// (<c>FrameFinish</c>): 1 leaves the frame as it is, 0 is black. Already in linear light (the sRGB ramp converted), so a
|
||||
/// fade looks even.</param>
|
||||
public readonly record struct ProgramEntry(int PlanIndex, long Duration90k, double Gain);
|
||||
/// <param name="Pass">The pass of the playback it belongs to (0 for the first; each loop is one more): a star-trail stack
|
||||
/// starts again at each pass, so every loop plays the trails growing.</param>
|
||||
public readonly record struct ProgramEntry(int PlanIndex, long Duration90k, double Gain, int Pass = 0);
|
||||
|
||||
/// <summary>
|
||||
/// The output program of a render (owner review 1, R8): the plan's frames in the order and for the time they are emitted,
|
||||
@@ -87,15 +89,15 @@ public sealed class OutputProgram
|
||||
switch (direction)
|
||||
{
|
||||
case PlaybackDirection.Reverse:
|
||||
for (var i = frames.Count - 1; i >= 0; i--) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1));
|
||||
for (var i = frames.Count - 1; i >= 0; i--) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1, pass));
|
||||
break;
|
||||
case PlaybackDirection.Boomerang:
|
||||
// The turning frame plays once, and a later pass starts after the first frame the previous one ended on.
|
||||
for (var i = pass == 0 ? 0 : 1; i < frames.Count; i++) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1));
|
||||
for (var i = frames.Count - 2; i >= 0; i--) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1));
|
||||
for (var i = pass == 0 ? 0 : 1; i < frames.Count; i++) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1, pass));
|
||||
for (var i = frames.Count - 2; i >= 0; i--) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1, pass));
|
||||
break;
|
||||
default:
|
||||
for (var i = 0; i < frames.Count; i++) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1));
|
||||
for (var i = 0; i < frames.Count; i++) entries.Add(new ProgramEntry(i, frames[i].Duration90k, 1, pass));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +150,7 @@ public sealed class OutputProgram
|
||||
{
|
||||
var boundary = (long)double.Round((double)entry.Duration90k * part / parts);
|
||||
if (boundary == previous) continue;
|
||||
faded.Add(new ProgramEntry(entry.PlanIndex, boundary - previous, Gain(start + previous, start + boundary, total, fadeIn, fadeOut)));
|
||||
faded.Add(entry with { Duration90k = boundary - previous, Gain = Gain(start + previous, start + boundary, total, fadeIn, fadeOut) });
|
||||
previous = boundary;
|
||||
}
|
||||
start = end;
|
||||
|
||||
@@ -100,6 +100,9 @@ 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;
|
||||
@@ -157,12 +160,14 @@ internal sealed class RenderRun : IDisposable
|
||||
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, _program.Count, Fps(), _clock.Elapsed, TimeSpan.Zero));
|
||||
session.Complete();
|
||||
ignored = [.. session.Ignored];
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -177,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,
|
||||
@@ -221,28 +228,42 @@ internal sealed class RenderRun : IDisposable
|
||||
await RenderWindowStackAsync(stack, cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
case StackSetting.StarTrails:
|
||||
// The trails accumulate in program order: a reversed video grows its trails from the end.
|
||||
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
|
||||
{
|
||||
await RenderProgramAsync(async (index, token) =>
|
||||
await RenderProgramAsync(async (entry, token) =>
|
||||
{
|
||||
using (var frame = await RenderFrameAsync(_plan.Frames[index], blur: false, token).ConfigureAwait(false)) trails.Add(frame);
|
||||
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:
|
||||
await RenderProgramAsync((index, token) => RenderFrameAsync(_plan.Frames[index], _setup.MotionBlur, token), cancellationToken).ConfigureAwait(false);
|
||||
await RenderProgramAsync((entry, token) => RenderFrameAsync(_plan.Frames[entry.PlanIndex], _setup.MotionBlur, token), cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emits the program's entries in order, each rendered by <paramref name="render"/> from its plan index. Consecutive
|
||||
/// entries of one plan frame (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).
|
||||
/// 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<int, CancellationToken, Task<ImageBuffer>> render, CancellationToken cancellationToken)
|
||||
private async Task RenderProgramAsync(Func<ProgramEntry, CancellationToken, Task<ImageBuffer>> render, CancellationToken cancellationToken)
|
||||
{
|
||||
var entries = _program.Entries;
|
||||
ImageBuffer? kept = null;
|
||||
@@ -252,9 +273,9 @@ internal sealed class RenderRun : IDisposable
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var entry = entries[i];
|
||||
var frame = kept ?? await render(entry.PlanIndex, cancellationToken).ConfigureAwait(false);
|
||||
var frame = kept ?? await render(entry, cancellationToken).ConfigureAwait(false);
|
||||
kept = null;
|
||||
if (i + 1 < entries.Count && entries[i + 1].PlanIndex == entry.PlanIndex)
|
||||
if (i + 1 < entries.Count && entries[i + 1].PlanIndex == entry.PlanIndex && entries[i + 1].Pass == entry.Pass)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -290,8 +311,9 @@ internal sealed class RenderRun : IDisposable
|
||||
// Plan indices in the stacker, oldest (the next evicted) first.
|
||||
var held = new List<int>(window + 1);
|
||||
var previous = -1;
|
||||
await RenderProgramAsync(async (index, token) =>
|
||||
await RenderProgramAsync(async (entry, token) =>
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -102,7 +102,11 @@ public sealed record EncodeSettings
|
||||
/// <summary>Distance between key frames in frames; 0 = encoder default (≈ 1 s).</summary>
|
||||
public int GopLength { get; init; }
|
||||
|
||||
public int BFrames { get; init; } = 2;
|
||||
public int BFrames { get; init; } = DefaultBFrames;
|
||||
|
||||
/// <summary>The B-frames an encode asks for unless told otherwise.</summary>
|
||||
public const int DefaultBFrames = 2;
|
||||
|
||||
public bool PreferHardware { get; init; } = true;
|
||||
|
||||
/// <summary>Optional specific encoder name from <see cref="EncoderCapability.Name"/>.</summary>
|
||||
@@ -128,6 +132,22 @@ public interface IVideoEncoderSession : IDisposable
|
||||
|
||||
/// <summary>Flushes and closes the output. Without it, <see cref="IDisposable.Dispose"/> deletes the partial file.</summary>
|
||||
void Complete();
|
||||
|
||||
/// <summary>
|
||||
/// The settings asked for that the encoder does not support or refused, so the output was encoded with its own instead;
|
||||
/// empty when it took every one (the managed encoders, which have none of them to refuse).
|
||||
/// </summary>
|
||||
IReadOnlyList<EncoderSetting> Ignored => [];
|
||||
}
|
||||
|
||||
/// <summary>An encoding setting an encoder may refuse (<see cref="IVideoEncoderSession.Ignored"/>).</summary>
|
||||
public enum EncoderSetting
|
||||
{
|
||||
RateControl,
|
||||
Quality,
|
||||
BitRate,
|
||||
KeyframeInterval,
|
||||
BFrames,
|
||||
}
|
||||
|
||||
/// <summary>A family of encoders (Media Foundation on Windows, managed everywhere).</summary>
|
||||
|
||||
@@ -108,7 +108,8 @@ internal abstract class SingleFileSession : ManagedSession
|
||||
Finish();
|
||||
File.Flush(flushToDisk: true);
|
||||
File.Dispose();
|
||||
AtomicFile.Commit(_tempPath, Settings.OutputPath);
|
||||
// The render picked a free name: something that took it meanwhile (a restore) is never overwritten.
|
||||
AtomicFile.CommitNew(_tempPath, Settings.OutputPath);
|
||||
}
|
||||
|
||||
protected override void Discard()
|
||||
|
||||
Reference in new issue
Block a user