using Chronos.Core.Export; using Chronos.Core.Video; namespace Chronos.Core.Render; /// A finished render, for the render history and the database (). public sealed record RenderResult { /// The output file, or folder for image sequences. public required string OutputPath { get; init; } /// Effective preset id (or ). public required string PresetId { get; init; } public required VideoCodec Codec { get; init; } public ContainerFormat Container => VideoCodecInfo.DefaultContainer(Codec); public required int Width { get; init; } public required int Height { get; init; } public required Rational FrameRate { get; init; } public required double DurationSeconds { get; init; } /// Output pictures rendered (held frames count once). public required int FrameCount { get; init; } /// Size of the file, or of every file of a sequence. public required long Bytes { get; init; } public required string EncoderName { get; init; } public required bool Hardware { get; init; } public required TimeSpan Elapsed { get; init; } /// Plan, geometry, encoder and preparation remarks. public IReadOnlyList Warnings { get; init; } = []; /// The render-history entity. /// Display name of the preset at render time. /// The project settings used (). /// Client or render-node name. public Model.Render ToEntity(Guid sequenceId, string presetName, string? settingsJson, string? producedBy) => new() { Id = Guid.CreateVersion7(), SequenceId = sequenceId, PresetName = presetName, SettingsJson = settingsJson, OutputPath = OutputPath, Codec = Codec.ToString(), Width = Width, Height = Height, Fps = FrameRate.Value, DurationSeconds = DurationSeconds, Bytes = Bytes, Created = DateTimeOffset.UtcNow, ProducedBy = producedBy, }; /// Bytes of a file, or the total of the files in a folder. internal static long SizeOf(string path) { if (File.Exists(path)) return new FileInfo(path).Length; if (!Directory.Exists(path)) return 0; long total = 0; foreach (var file in new DirectoryInfo(path).EnumerateFiles("*", SearchOption.AllDirectories)) total += file.Length; return total; } } /// Outcome of one target of : a result or the failure that stopped it. public sealed record BatchItemResult(RenderTarget Target, RenderResult? Result, Exception? Error) { public bool Succeeded => Result is not null; }