Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Merge branch 'pr101-head' into HEAD

KnifeLemon21a83f241832
diff --cc src/Filee.App/ViewModels/PresetEditorViewModel.cs
index 46e3e9ee,6cb71104..13816958
--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs
+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
@@@ -111,9 -94,10 +111,11 @@@ public sealed partial class PresetEdito
_wavFormat = WavFormats.First(f => f.Value == _edit.Media.WavFormat);
_videoCodecValue = _edit.Media.VideoCodec;
_audioCodecValue = _edit.Media.AudioCodec;
+ _hardwareEncoding = _edit.Media.HardwareEncoding;
_archiveLevel = ArchiveLevels.First(l => l.Value == _edit.Archive.Level);
_combineIntoOne = _edit.Archive.CombineIntoOne;
+ _saveEveryFrame = _edit.Media.SaveEveryFrame;
+ _frameInterval = _edit.Media.FrameInterval > 0 ? _edit.Media.FrameInterval : 1;
_traceMode = TraceModes.First(m => m.Value == _edit.Trace.Mode);
_traceColors = Math.Clamp(_edit.Trace.Colors, TracingOptions.MinColors, TracingOptions.MaxColors);
_traceDetail = Math.Clamp(_edit.Trace.Detail, 0, 100);
@@@ -176,9 -160,10 +178,10 @@@
[NotifyPropertyChangedFor(nameof(ShowImage), nameof(ShowTurnForPdf), nameof(ShowQuality), nameof(ShowTiff), nameof(ShowMultiPageTiff), nameof(ShowWebp), nameof(ShowIco),
nameof(ShowPdf), nameof(ShowPdfBuild), nameof(ShowDocument), nameof(ShowPdfSplit), nameof(ShowPdfCombine),
nameof(ShowMedia), nameof(ShowMediaQuality), nameof(ShowMaxHeight), nameof(ShowAudioBitrate), nameof(ShowRemoveAudio),
- nameof(ShowAudioChannels), nameof(ShowWav), nameof(VideoCodecs), nameof(VideoCodecChoice), nameof(ShowVideoCodec),
+ nameof(ShowAudioChannels), nameof(ShowWav), nameof(VideoCodecs), nameof(VideoCodecChoice), nameof(ShowVideoCodec), nameof(ShowHardwareEncoding),
nameof(AudioCodecs), nameof(AudioCodecChoice), nameof(ShowAudioCodec),
- nameof(ShowArchive), nameof(ShowArchiveOptions), nameof(ShowExtractNote), nameof(ShowTrace))]
+ nameof(ShowArchive), nameof(ShowArchiveOptions), nameof(ShowExtractNote),
+ nameof(ShowSaveEveryFrame), nameof(ShowTrace))]
private Choice<string> _target;
private VideoCodec _videoCodecValue;
@@@ -311,11 -284,16 +314,19 @@@
[ObservableProperty] private Choice<int> _sampleRate;
[ObservableProperty] private Choice<WavSampleFormat> _wavFormat;
[ObservableProperty] private bool _removeAudio;
+
+ /// <summary>Encode H.264 / HEVC on the graphics chip when one works (MediaOptions.HardwareEncoding).</summary>
+ [ObservableProperty] private bool _hardwareEncoding;
[ObservableProperty] private Choice<ArchiveLevel> _archiveLevel;
[ObservableProperty] private bool _combineIntoOne;
+ [ObservableProperty] private bool _saveEveryFrame;
+
+ [ObservableProperty, NotifyPropertyChangedFor(nameof(FrameEstimate))]
+ private int _frameInterval = 1;
+
+ /// <summary>How many pictures a minute of 30 fps video gives at the chosen interval, and the limit per video.</summary>
+ public string FrameEstimate => _loc.Format("presets.frame_estimate",
+ (int)Math.Ceiling(1800.0 / Math.Clamp(FrameInterval, 1, 1000)), MediaOptions.MaxFrames.ToString("N0", System.Globalization.CultureInfo.InvariantCulture));
[ObservableProperty, NotifyPropertyChangedFor(nameof(ShowTraceColors))]
private Choice<TracingMode> _traceMode;
@@@ -467,7 -426,9 +480,10 @@@
media.WavFormat = WavFormat.Value;
media.VideoCodec = MediaCodecs.Effective(TargetId, _videoCodecValue);
media.AudioCodec = MediaCodecs.Effective(TargetId, _audioCodecValue);
+ media.HardwareEncoding = HardwareEncoding;
+ // Only where the option is shown: a box ticked for PNG and left behind by another target saves nothing.
+ media.SaveEveryFrame = ShowSaveEveryFrame && SaveEveryFrame;
+ media.FrameInterval = media.SaveEveryFrame ? Math.Clamp(FrameInterval, 1, 1000) : 1;
_original.Archive.Level = ArchiveLevel.Value;
_original.Archive.CombineIntoOne = CombineIntoOne;
_original.Trace.Mode = TraceMode.Value;
diff --cc src/Filee.Core/Conversion/IConverter.cs
index 0e4da67c,3bb5d7fb..6c1814f2
--- a/src/Filee.Core/Conversion/IConverter.cs
+++ b/src/Filee.Core/Conversion/IConverter.cs
@@@ -22,13 -22,28 +22,33 @@@ namespace Filee.Core.Conversion
/// The opposite: never used in routes that start from a raster image. PDF → SVG through LibreOffice keeps a PDF's
/// vectors, but a photo that became a PDF would only come back as a picture inside an SVG, so images are traced.
/// </param>
+/// <param name="DirectOnly">
+/// The edge is a route of its own only: the file being converted is a <paramref name="From"/> file and
+/// <paramref name="To"/> is what the user asked for. PDF → PPTX puts pictures of the pages on slides; a Word document
+/// rendered to PDF must not become pictures on slides, and a picture deck must not be a step towards ODP or PPSX.
+/// </param>
+ /// <param name="FrameSequence">
+ /// The edge writes every frame of a video as numbered pictures into a folder (<see cref="Presets.MediaOptions.SaveEveryFrame"/>).
+ /// It is never part of an ordinary route (a video → JPG stays one still frame), and with
+ /// <see cref="RoutePlanner.Plan(string, string, bool)"/> asking for frames it is the whole route.
+ /// </param>
public readonly record struct ConversionEdge(
- string From, string To, int Cost = 10, bool ImageSourcesOnly = false, bool NotForImageSources = false, bool DirectOnly = false);
+ string From, string To, int Cost = 10, bool ImageSourcesOnly = false, bool NotForImageSources = false,
- bool FrameSequence = false);
++ bool DirectOnly = false, bool FrameSequence = false);
+
+ /// <summary>
+ /// A conversion an engine refuses with a reason the user can act on, shown in their language (the file's
+ /// <see cref="FileResult.ErrorKey"/>) instead of "The engine reported an error".
+ /// </summary>
+ /// <param name="errorKey">Localization key of the reason, e.g. <c>error.too_many_frames</c>.</param>
+ /// <param name="detail">Non-localized detail shown after it in brackets (numbers, a name), or null.</param>
+ public sealed class ConversionRefusedException(string errorKey, string? detail = null)
+ : Exception(detail is null ? errorKey : $"{errorKey} ({detail})")
+ {
+ public string ErrorKey { get; } = errorKey;
+
+ public string? Detail { get; } = detail;
+ }
/// <summary>Whether an engine can currently be used.</summary>
/// <param name="IsAvailable">True if conversions can run.</param>
diff --cc src/Filee.Core/Conversion/RoutePlanner.cs
index 48573bd2,37551b6e..c9c6a7f4
--- a/src/Filee.Core/Conversion/RoutePlanner.cs
+++ b/src/Filee.Core/Conversion/RoutePlanner.cs
@@@ -89,8 -106,8 +106,9 @@@ public sealed class RoutePlanne
foreach (var (converter, edge, edgeCost) in EdgesFrom(node))
{
- if (edge.To == edge.From || (edge.ImageSourcesOnly && !imageSource) || (edge.NotForImageSources && imageSource)
+ if (edge.To == edge.From || edge.FrameSequence
- || (edge.ImageSourcesOnly && !imageSource) || (edge.NotForImageSources && imageSource))
++ || (edge.ImageSourcesOnly && !imageSource) || (edge.NotForImageSources && imageSource)
+ || (edge.DirectOnly && (node != from || edge.To != to)))
continue;
var next = cost + edgeCost;
if (dist.TryGetValue(edge.To, out var known) && known <= next)
diff --cc src/Filee.Core/Presets/BuiltInData.cs
index fd6ed8a3,e12dd414..c5ef5e7e
--- a/src/Filee.Core/Presets/BuiltInData.cs
+++ b/src/Filee.Core/Presets/BuiltInData.cs
@@@ -65,7 -65,7 +65,8 @@@ public static class BuiltInDat
Id = "pdf-split", NameKey = "preset.split_pdf", TargetFormat = "pdf",
Pdf = { SplitPages = true }, Output = { Location = OutputLocation.Subfolder, SubfolderName = "{name}" },
},
+ .. PdfSlidesPresets(),
+ .. FramePresets(),
new() { Id = "to-docx", Name = "DOCX", TargetFormat = "docx" },
new() { Id = "to-hwpx", Name = "HWPX", TargetFormat = "hwpx" },
.. HwpPresets(),
@@@ -82,15 -82,16 +83,25 @@@
.. TracePresets(),
];
+ /// <summary>
+ /// PDF → PowerPoint with a picture of each page on its own slide (added in settings schema 18). JPEG at 90 like the
+ /// JPG preset; the render DPI is the PDF default (150), which the converter never goes below.
+ /// </summary>
+ public static List<Preset> PdfSlidesPresets() =>
+ [
+ new() { Id = "pdf-slides", NameKey = "preset.pdf_slides", TargetFormat = "pptx", Image = { Quality = 90 } },
+ ];
+
+ /// <summary>
+ /// Every frame of a video as PNG or JPG pictures in a folder (added in settings schema 19), on no donut: a long
+ /// video gives thousands of files, so users add them in Settings → Toolbar.
+ /// </summary>
+ public static List<Preset> FramePresets() =>
+ [
+ new() { Id = "extract-frames-png", NameKey = "preset.extract_frames_png", TargetFormat = "png", Media = { SaveEveryFrame = true } },
+ new() { Id = "extract-frames-jpg", NameKey = "preset.extract_frames_jpg", TargetFormat = "jpg", Media = { SaveEveryFrame = true } },
+ ];
+
/// <summary>Raster → SVG tracing, in colour and as black line art (added in settings schema 16).</summary>
public static List<Preset> TracePresets() =>
[
diff --cc src/Filee.Core/Presets/Preset.cs
index adc9a2f2,37d093c9..9dcf6737
--- a/src/Filee.Core/Presets/Preset.cs
+++ b/src/Filee.Core/Presets/Preset.cs
@@@ -367,14 -377,25 +377,33 @@@ public sealed class MediaOption
/// <summary>Audio codec for targets that can hold several (<see cref="MediaCodecs.AudioCodecsFor"/>).</summary>
public AudioCodec AudioCodec { get; set; } = AudioCodec.Default;
+ /// <summary>
+ /// Encode H.264 and HEVC video with the graphics chip's encoder (NVENC, Quick Sync, AMF, VideoToolbox or VA-API)
+ /// when one works on this computer, else with x264 / x265 as usual. Much faster and lighter on power, a little
+ /// larger at the same quality. Off by default (and for presets saved before it existed), so results never change
+ /// without the user asking for it.
+ /// </summary>
+ public bool HardwareEncoding { get; set; }
+
+ /// <summary>Picture formats a video's frames can be saved as (<see cref="SaveEveryFrame"/>).</summary>
+ public static readonly IReadOnlyList<string> FrameTargets = ["png", "jpg"];
+
+ /// <summary>
+ /// Video → PNG or JPG: save every frame as a picture, in a folder, instead of one still frame. Only for video
+ /// sources and a target in <see cref="FrameTargets"/> (<see cref="Preset.SavesFramesOf"/>).
+ /// </summary>
+ public bool SaveEveryFrame { get; set; }
+
+ /// <summary>With <see cref="SaveEveryFrame"/>: extract every Nth frame (1 = every frame).</summary>
+ public int FrameInterval { get; set; } = 1;
+
+ /// <summary>
+ /// Most pictures one video may become (<see cref="SaveEveryFrame"/>): about an hour at 30 fps, already more than
+ /// anyone looks through. A longer video needs a larger <see cref="FrameInterval"/>.
+ /// </summary>
+ public const long MaxFrames = 100_000;
+
+
public MediaOptions Clone() => (MediaOptions)MemberwiseClone();
}
diff --cc src/Filee.Core/Settings/UserDataStore.cs
index a97fbc85,f5bdb7fa..7a05f099
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@@ -490,11 -480,20 +490,28 @@@ internal static class SettingsMigration
}
}
- // v19: "Extract frames" (every frame of a video as PNG or JPG pictures in a folder), on no donut, after "Split
- // PDF" as in a new library: a long video gives thousands of files, so users add them in Settings → Toolbar.
+ // v18: PDF → PPTX ("PPTX (slides)", a picture of each page per slide), on the PDF donut after DOCX. The default
+ // PDF donut is full: one the user never changed takes it in place of TIFF, as a new library has it; a donut
+ // the user changed gets it when it has room.
+ if (from < 18)
+ changed |= AddPdfSlides(presets, profiles);
++ // v19: "Extract frames" (every frame of a video as PNG or JPG pictures in a folder), on no donut, after "PPTX
++ // (slides)" or "Split PDF" as in a new library: a long video gives thousands of files, so users add them in
++ // Settings → Toolbar.
+ if (from < 19)
+ {
- var at = presets.FindIndex(p => p.Id == "pdf-split");
++ var at = presets.FindIndex(p => p.Id == "pdf-slides");
++ if (at < 0)
++ at = presets.FindIndex(p => p.Id == "pdf-split");
+ at = at < 0 ? presets.Count : at + 1;
+ foreach (var preset in BuiltInData.FramePresets())
+ {
+ if (presets.Any(p => p.Id == preset.Id))
+ continue;
+ presets.Insert(Math.Min(at++, presets.Count), preset);
+ changed = true;
+ }
+ }
return changed;
}
diff --cc src/Filee.Engines/Media/FfmpegConverter.cs
index 787de120,14336d3d..029416ca
--- a/src/Filee.Engines/Media/FfmpegConverter.cs
+++ b/src/Filee.Engines/Media/FfmpegConverter.cs
@@@ -1,11 -1,11 +1,11 @@@
// Video and audio conversion with FFmpeg (GPL-3.0 build, an optional download run as a separate program in
- // engines/ffmpeg): video ↔ video (H.264, HEVC, AV1, …), video → animated GIF / APNG or a still frame, audio
- // extraction, subtitle extraction (the first text track as SRT / ASS / WebVTT), audio ↔ audio and GIF, APNG or a still
- // picture → video, and images → HEIC (FFmpeg's HEVC encoder, Filee's own container writer).
- // Container and codec choices live in MediaEncoding, the process handling in FfmpegRunner, hardware encoders in
- // HardwareVideo (options) and HardwareProbe (which one works here).
+ // engines/ffmpeg): video ↔ video (H.264, HEVC, AV1, …), video → animated GIF / APNG, a still frame or every frame
+ // (FrameSequenceWriter), audio extraction, subtitle extraction (the first text track as SRT / ASS / WebVTT), audio ↔
+ // audio and GIF, APNG or a still picture → video, and images → HEIC (FFmpeg's HEVC encoder, Filee's own container
-// writer). Container and codec choices live in MediaEncoding, the process handling in FfmpegRunner.
++// writer). Container and codec choices live in MediaEncoding, the process handling in FfmpegRunner, hardware encoders
++// in HardwareVideo (options) and HardwareProbe (which one works here).
using System.Collections.Concurrent;
-using System.Diagnostics;
using System.Text.RegularExpressions;
using Filee.Core.Conversion;
using Filee.Core.Formats;
@@@ -155,51 -141,8 +162,51 @@@ public sealed partial class FfmpegConve
return [output];
}
+ /// <summary>
+ /// Runs <paramref name="passes"/>, planned with <paramref name="hardware"/>. When a hardware encode fails (a driver
+ /// error, a picture larger than the chip encodes, …) the file is encoded again as <paramref name="plan"/> plans it
+ /// without hardware: an encoder that passed its test encode can still refuse one particular video, and the user
+ /// asked for a converted file, not for the GPU. The failure is logged, not reported. Cancellation is never retried.
+ /// </summary>
+ internal static async Task RunWithFallbackAsync(IReadOnlyList<FfmpegPass> passes, HardwareEncoder? hardware,
+ Func<HardwareEncoder?, IReadOnlyList<FfmpegPass>> plan, Func<IReadOnlyList<FfmpegPass>, Task> run, string output, ILogger logger,
+ CancellationToken cancellationToken)
+ {
+ if (hardware is null)
+ {
+ await run(passes);
+ return;
+ }
+ try
+ {
+ await run(passes);
+ }
+ catch (Exception ex) when (ex is not OperationCanceledException && !cancellationToken.IsCancellationRequested)
+ {
+ logger.LogWarning("{File}: hardware encoder {Encoder} failed ({Reason}); encoding it again with the software encoder",
+ output, hardware.Name, ex.Message);
+ TryDelete(output);
+ // An FFmpeg without x265 says so here: the hardware encoder was the only way to write HEVC.
+ await run(plan(null));
+ }
+ }
+
+ /// <summary>Runs every pass, then checks that FFmpeg wrote something.</summary>
+ private static async Task RunPassesAsync(string ffmpeg, IReadOnlyList<FfmpegPass> passes, string output, TimeSpan? duration,
+ IProgress<double>? progress, CancellationToken cancellationToken)
+ {
+ var done = 0.0;
+ foreach (var pass in passes)
+ {
+ await RunPassAsync(ffmpeg, pass, duration, progress, done, cancellationToken);
+ done += pass.Weight;
+ }
+ if (!File.Exists(output) || new FileInfo(output).Length == 0)
+ throw new InvalidOperationException("FFmpeg did not write any output.");
+ }
+
/// <summary>Runs one pass and maps FFmpeg's position (seconds) onto this pass' share of the progress.</summary>
- private static async Task RunPassAsync(string ffmpeg, FfmpegPass pass, TimeSpan? duration, IProgress<double>? progress, double done, CancellationToken cancellationToken)
+ internal static async Task RunPassAsync(string ffmpeg, FfmpegPass pass, TimeSpan? duration, IProgress<double>? progress, double done, CancellationToken cancellationToken)
{
var total = duration?.TotalSeconds ?? 0;
Action<double>? onPosition = progress is null || total <= 0
diff --cc src/Filee.Engines/Media/MediaEncoding.cs
index 44ac80de,a2f87f61..c4f949bd
--- a/src/Filee.Engines/Media/MediaEncoding.cs
+++ b/src/Filee.Engines/Media/MediaEncoding.cs
@@@ -164,21 -160,53 +164,64 @@@ internal static class MediaEncodin
throw new NotSupportedException($"FFmpeg cannot write '{target}'.");
}
+ /// <summary>
+ /// Maps preset image quality (1..100, 100 best) to FFmpeg's mjpeg -q:v parameter (1..31, 1 best, 2..3 visually lossless).
+ /// </summary>
+ public static int QualityToQv(int quality)
+ {
+ var clamped = Math.Clamp(quality, 1, 100);
+ return Math.Clamp((int)Math.Round(2.0 + (100 - clamped) * 29.0 / 99.0), 1, 31);
+ }
+
+ /// <summary>
+ /// Every frame (or every <paramref name="frameInterval"/>th) of the first video stream as numbered pictures in
+ /// <paramref name="outputPattern"/> (an image2 pattern such as <c>frame_%06d.png</c>), for focus stacking and
+ /// picking a shot.
+ /// </summary>
+ /// <remarks>
+ /// Each decoded frame is written once. The image2 muxer would otherwise pace frames to a constant rate and
+ /// duplicate (or drop) frames of a variable frame rate video (phones), so frames pass through with their own
+ /// timestamps; with an interval the select filter leaves gaps, which <c>vfr</c> keeps as they are.
+ /// </remarks>
+ public static List<string> FrameSequence(
+ string input,
+ string outputPattern,
+ string imageExt,
+ VideoStreamInfo? video = null,
+ int quality = 90,
+ int frameInterval = 1)
+ {
+ var select = frameInterval > 1 ? $"select='not(mod(n\\,{frameInterval}))'" : "null";
+ List<string> args =
+ [
+ .. Common, "-i", input, "-map", "0:V:0", "-vf", (video is null ? "" : SquarePixels(video)) + select,
+ "-fps_mode", frameInterval > 1 ? "vfr" : "passthrough",
+ ];
+
+ if (imageExt is "jpg" or "jpeg")
+ args.AddRange(["-c:v", "mjpeg", "-q:v", QualityToQv(quality).ToString(CultureInfo.InvariantCulture)]);
+ else
+ args.AddRange(["-c:v", "png"]);
+
+ args.AddRange(["-f", "image2", "-progress", "pipe:1", outputPattern]);
+ return args;
+ }
+
// ───────────────────────── Video ─────────────────────────
+ /// <summary>
+ /// The codec a hardware encoder would have to write for this file ("h264" or "hevc"), or null when the preset does
+ /// not ask for hardware encoding, the target is written with another codec (VP9, AV1, MPEG-2, …), or the video is
+ /// copied anyway.
+ /// </summary>
+ internal static string? HardwareCodec(string target, MediaOptions options, MediaInfo info) =>
+ options.HardwareEncoding && info.Video is { } video && VideoTargets.ContainsKey(target)
+ && MediaCodecs.TakesHardwareEncoding(target, options.VideoCodec) && !CanCopyVideo(target, video, options)
+ ? MediaCodecs.Effective(target, options.VideoCodec) == Core.Presets.VideoCodec.Hevc ? "hevc" : "h264"
+ : null;
+
private static List<string> Video(string input, string output, string target, MediaTarget spec, MediaOptions options, MediaInfo info,
- IReadOnlySet<string>? encoders)
+ IReadOnlySet<string>? encoders, HardwareEncoder? hardware)
{
var video = info.Video ?? throw new InvalidOperationException("The file has no video stream.");
// An input without sound is fine: the output simply has no audio track.
diff --cc tests/Filee.Core.Tests/RoutePlannerTests.cs
index 5110fdaf,6a858e34..8a0fb7db
--- a/tests/Filee.Core.Tests/RoutePlannerTests.cs
+++ b/tests/Filee.Core.Tests/RoutePlannerTests.cs
@@@ -51,22 -51,29 +51,45 @@@ public class RoutePlannerTest
Assert.Equal(["pdf→svg"], planner.Plan("pdf", "svg")!.Steps.Select(s => $"{s.From}→{s.To}"));
}
+ [Fact]
+ public void Direct_only_edges_are_never_a_step_of_a_longer_route()
+ {
+ // PDF → PPTX puts pictures of the pages on slides: only for a PDF the user asked to turn into PPTX.
+ var slides = new FakeConverter("slides", new ConversionEdge("pdf", "pptx", DirectOnly: true));
+ var word = new FakeConverter("word", new ConversionEdge("docx", "pdf"));
+ var office = new FakeConverter("office", new ConversionEdge("pptx", "odp"), new ConversionEdge("pptx", "ppsx"));
+ var planner = new RoutePlanner([slides, word, office]);
+
+ Assert.Equal(["pdf→pptx"], planner.Plan("pdf", "pptx")!.Steps.Select(s => $"{s.From}→{s.To}"));
+ Assert.Null(planner.Plan("docx", "pptx")); // not after another step
+ Assert.Null(planner.Plan("pdf", "odp")); // nor before one
+ Assert.Null(planner.Plan("pdf", "ppsx"));
+ Assert.Equal(["pptx→odp"], planner.Plan("pptx", "odp")!.Steps.Select(s => $"{s.From}→{s.To}"));
+ }
+
+ [Fact]
+ public void Frame_sequence_edges_are_a_route_of_their_own_only_when_asked_for()
+ {
+ var ffmpeg = new FakeConverter("ffmpeg", new ConversionEdge("mp4", "png"),
+ new ConversionEdge("mp4", "png", FrameSequence: true), new ConversionEdge("mp4", "jpg", FrameSequence: true));
+ var magick = new FakeConverter("magick", new ConversionEdge("png", "jpg"), new ConversionEdge("png", "webp"));
+ var planner = new RoutePlanner([ffmpeg, magick]);
+
+ // Ordinary routes: one still frame, then the image engine. The frame edge to JPG is never taken.
+ var still = planner.Plan("mp4", "jpg")!;
+ Assert.Equal(["mp4→png", "png→jpg"], still.Steps.Select(s => $"{s.From}→{s.To}"));
+ Assert.DoesNotContain(still.Steps, s => s.FrameSequence);
+ Assert.False(planner.Plan("mp4", "png")!.Steps.Single().FrameSequence);
+
+ // Frames: the frame edge alone, never as a step towards another format.
+ var frames = planner.Plan("mp4", "jpg", frames: true)!;
+ Assert.Equal(("mp4", "jpg", true), (frames.Steps.Single().From, frames.Steps.Single().To, frames.Steps.Single().FrameSequence));
+ Assert.True(planner.Plan("mp4", "png", frames: true)!.Steps.Single().FrameSequence);
+ Assert.Null(planner.Plan("mp4", "webp", frames: true));
+ Assert.Null(planner.Plan("png", "jpg", frames: true));
+ Assert.False(planner.CanConvert("mov", "jpg", frames: true));
+ }
+
[Fact]
public void Cheaper_route_wins()
{
diff --cc tests/Filee.Core.Tests/UserDataStoreTests.cs
index 3e9faf5f,ac59c9e4..5064aec7
--- a/tests/Filee.Core.Tests/UserDataStoreTests.cs
+++ b/tests/Filee.Core.Tests/UserDataStoreTests.cs
@@@ -330,6 -302,33 +330,33 @@@ public class UserDataStoreTest
Assert.False(SettingsMigrations.ApplyToLibrary(9, presets, profiles)); // once only
}
+ [Fact]
- public void Version_18_libraries_get_the_extract_frames_presets_after_split_pdf_on_no_donut()
++ public void Version_18_libraries_get_the_extract_frames_presets_after_the_pdf_presets_on_no_donut()
+ {
+ var presets = BuiltInData.CreatePresets();
+ presets.RemoveAll(p => p.Id is "extract-frames-png" or "extract-frames-jpg");
+ var profiles = BuiltInData.CreateProfiles();
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(18, presets, profiles));
+
+ var pngPreset = presets.Single(p => p.Id == "extract-frames-png");
+ Assert.True(pngPreset.Media.SaveEveryFrame);
+ Assert.Equal("png", pngPreset.TargetFormat);
+
+ var jpgPreset = presets.Single(p => p.Id == "extract-frames-jpg");
+ Assert.True(jpgPreset.Media.SaveEveryFrame);
+ Assert.Equal("jpg", jpgPreset.TargetFormat);
+
+ // Where a new library has them.
+ Assert.Equal(BuiltInData.CreatePresets().Select(p => p.Id), presets.Select(p => p.Id));
- var split = presets.FindIndex(p => p.Id == "pdf-split");
- Assert.Equal(["extract-frames-png", "extract-frames-jpg"], presets.Skip(split + 1).Take(2).Select(p => p.Id));
++ var slides = presets.FindIndex(p => p.Id == "pdf-slides");
++ Assert.Equal(["extract-frames-png", "extract-frames-jpg"], presets.Skip(slides + 1).Take(2).Select(p => p.Id));
+
+ Assert.DoesNotContain(profiles, p => p.PresetIds.Contains("extract-frames-png"));
+ Assert.DoesNotContain(profiles, p => p.PresetIds.Contains("extract-frames-jpg"));
+ Assert.False(SettingsMigrations.ApplyToLibrary(18, presets, profiles)); // once only
+ }
+
[Fact]
public void Version_13_libraries_get_the_data_donut_msg_files_and_json_for_spreadsheets()
{