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>
148 lines
7.1 KiB
C#
148 lines
7.1 KiB
C#
using Chronos.App.Editor;
|
||
using Chronos.Core.Advice;
|
||
using Chronos.Core.Export;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Core.Project;
|
||
using Chronos.Core.Video;
|
||
using Chronos.Core.Video.Managed;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.App.Tests.Editor;
|
||
|
||
public sealed class ExportPlannerTests
|
||
{
|
||
private static readonly SequenceContent Content = EditorFixture.Content(EditorFixture.Sunset);
|
||
|
||
private static ExportPlanner Planner(EncoderHost host = EncoderHost.Client) => new(Content, [new ManagedEncoderProvider()], host);
|
||
|
||
[Test]
|
||
public void TheListHasSequencePresetsFirstThenEveryBuiltInPreset()
|
||
{
|
||
var context = SequenceContext.FromFrames(Content.Frames);
|
||
var advice = Advisor.Recommend(Content.Light, Content.Deep, context);
|
||
var presets = SequencePresets.Generate(Content.Light, Content.Deep, context);
|
||
var choices = ExportPlanner.Choices(presets, advice);
|
||
|
||
Assert.Equal(presets.Count + ExportPresets.BuiltIn.Count, choices.Count);
|
||
Assert.True(choices.Take(presets.Count).All(c => c.Sequence is not null));
|
||
Assert.SequenceEqual(ExportPresets.BuiltIn.Select(p => p.Id), choices.Skip(presets.Count).Select(c => c.Id));
|
||
var recommended = Assert.Contains(choices, c => c.IsRecommended);
|
||
Assert.Equal(advice.Find(AdvisorParameters.ExportPreset)!.Value, recommended.ExportPresetId);
|
||
Assert.NotNull(recommended.Reason);
|
||
Assert.True(choices.All(c => c.Name.Length > 0 && !c.Name.StartsWith("Export.", StringComparison.Ordinal)), "names are localised");
|
||
}
|
||
|
||
[Test]
|
||
public void AnImageSequenceIsEstimatedAndNamedAsAFolder()
|
||
{
|
||
var project = new ProjectSettings();
|
||
project = project with { Export = project.Export with { Preset = project.Export.Preset.WithManual("png-sequence"), NameTemplate = "{title} {width}x{height} {codec}" } };
|
||
var plan = Planner().Plan(project);
|
||
Assert.NotNull(plan);
|
||
Assert.True(plan!.Setup.Encoder.IsReady);
|
||
Assert.Equal(96, plan.Setup.Encoder.Settings.Width);
|
||
Assert.Equal("Harbour sunset 96x64 PNG", plan.FileName, "no extension: a folder of frames");
|
||
Assert.Null(plan.NameError);
|
||
var workload = plan.Setup.Workload();
|
||
Assert.Equal(ExportEstimator.EstimateBytes(plan.Export with { Codec = VideoCodec.PngSequence }, workload), plan.Estimate.Bytes);
|
||
Assert.Greater(plan.Estimate.Bytes, 0);
|
||
Assert.Greater(plan.Estimate.Time.TotalSeconds, 0);
|
||
}
|
||
|
||
[Test]
|
||
public void ExcludedFramesShortenTheEstimate()
|
||
{
|
||
var project = new ProjectSettings();
|
||
project = project with { Export = project.Export with { Preset = project.Export.Preset.WithManual("jpeg-sequence") } };
|
||
var all = Planner().Plan(project)!;
|
||
var fewer = Planner().Plan(project with { ExcludedFrames = [.. Enumerable.Range(0, 36)] })!;
|
||
Assert.Equal(Content.Count, all.Setup.Plan.Frames.Count);
|
||
Assert.Less(fewer.Estimate.Bytes, all.Estimate.Bytes);
|
||
}
|
||
|
||
[Test]
|
||
public void VideoWithoutAnEncoderExplainsWhy()
|
||
{
|
||
var plan = Planner().Plan(new ProjectSettings())!;
|
||
Assert.False(plan.Setup.Encoder.IsReady, "only managed encoders here; H.264 needs Media Foundation or a render node");
|
||
Assert.Contains(plan.Setup.Encoder.Notices, n => n.Key == EncoderNotices.NoEncoder);
|
||
|
||
var server = Planner(EncoderHost.Server).Plan(new ProjectSettings())!;
|
||
Assert.Equal(EncoderSelectionStatus.NeedsRenderNode, server.Setup.Encoder.Status);
|
||
}
|
||
|
||
[Test]
|
||
public void ABrokenTemplateIsExplainedAndStillNamesTheFile()
|
||
{
|
||
var project = new ProjectSettings();
|
||
project = project with { Export = project.Export with { Preset = project.Export.Preset.WithManual("gif-preview"), NameTemplate = "{title} {nope}" } };
|
||
var plan = Planner().Plan(project)!;
|
||
Assert.Equal("Unknown token “nope” at position 9.", plan.NameError);
|
||
Assert.Equal("Harbour sunset.gif", plan.FileName);
|
||
}
|
||
|
||
[Test]
|
||
public void EditingAValueMakesThePresetCustom()
|
||
{
|
||
var project = new ProjectSettings();
|
||
project = project with { Export = project.Export with { Preset = project.Export.Preset.WithManual("png-sequence"), Overrides = new ExportOverrides { Width = 48 } } };
|
||
var plan = Planner().Plan(project)!;
|
||
Assert.True(plan.Export.IsCustom);
|
||
Assert.Equal("Custom", plan.PresetName);
|
||
Assert.Equal(48, plan.Setup.Encoder.Settings.Width);
|
||
}
|
||
|
||
/// <summary>An H.264 encoder that takes at most <paramref name="maxWidth"/>×<paramref name="maxHeight"/> (either way round).</summary>
|
||
private sealed class H264Provider(int maxWidth, int maxHeight) : IVideoEncoderProvider
|
||
{
|
||
public string Name => "h264";
|
||
|
||
public IReadOnlyList<EncoderCapability> Capabilities { get; } = [new(VideoCodec.H264, "Test H.264", false, maxWidth, maxHeight, false)];
|
||
|
||
public bool CanEncode(EncodeSettings settings) => settings.Codec == VideoCodec.H264;
|
||
|
||
public IVideoEncoderSession Open(EncodeSettings settings) => throw new NotSupportedException("Planning never encodes.");
|
||
}
|
||
|
||
private static ProjectSettings FourKAt(string aspect)
|
||
{
|
||
var project = new ProjectSettings();
|
||
return project with
|
||
{
|
||
Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect) },
|
||
Export = project.Export with { Preset = project.Export.Preset.WithManual("4k-h264") },
|
||
};
|
||
}
|
||
|
||
[Test]
|
||
public void TheChosenProportionsWinAndThePresetKeepsItsName()
|
||
{
|
||
var planner = new ExportPlanner(Content, [new H264Provider(4096, 2304)], EncoderHost.Client);
|
||
var plan = planner.Plan(FourKAt("9:16"))!;
|
||
Assert.Equal((2160, 3840), plan.OutputSize, "4K at 9:16");
|
||
Assert.Equal((2160, 3840), plan.EncodedSize, "the encoder takes it turned");
|
||
Assert.False(plan.IsCapped);
|
||
Assert.Equal("2160 × 3840", ExportTab.OutputSizeOf(plan));
|
||
Assert.Equal(Loc.L("Tooltips.Editor.Export.OutputSize"), ExportTab.OutputSizeToolTipOf(plan));
|
||
Assert.Equal(Loc.L("Export.Preset.4kH264"), plan.PresetName, "the preset is not made Custom");
|
||
Assert.False(plan.Export.IsCustom);
|
||
Assert.Equal((3840, 2160), (plan.Export.Width, plan.Export.Height), "Width × Height stay the preset's box");
|
||
var workload = plan.Setup.Workload();
|
||
Assert.Equal((2160, 3840), (workload.Width, workload.Height), "the estimate is of the adapted size");
|
||
|
||
var source = planner.Plan(FourKAt("source"))!;
|
||
Assert.Equal((3840, 2160), source.OutputSize, "source keeps the preset's ratio");
|
||
}
|
||
|
||
[Test]
|
||
public void AnOutputTheEncoderShrinksIsMarkedCapped()
|
||
{
|
||
var plan = new ExportPlanner(Content, [new H264Provider(1920, 1080)], EncoderHost.Client).Plan(FourKAt("9:16"))!;
|
||
Assert.Equal((2160, 3840), plan.OutputSize);
|
||
Assert.Equal((1080, 1920), plan.EncodedSize);
|
||
Assert.True(plan.IsCapped);
|
||
Assert.Equal(Loc.L("Editor.Export.Capped", "1080 × 1920"), ExportTab.OutputSizeOf(plan));
|
||
Assert.Equal(Loc.L("Tooltips.Editor.Export.OutputCapped", "1080 × 1920"), ExportTab.OutputSizeToolTipOf(plan), "the largest size it takes, turned");
|
||
}
|
||
}
|