fix(imaging): record only what decoding proves and find GPR JPEGs across sequences

- Preview sizes come from probes and unscaled decodes: a size-limited decode
  picks the smallest preview that reaches its edge (CR3 PRVW 1620x1080), so
  renders and deep passes record its tier without a size and the output cap
  keeps the largest preview's.
- A read error is not an undecodable file: ImageDecoder.Decode throws the
  IOException when a provider could not read the file and none produced
  pixels. Deep passes never flag frames they could not read or that
  vanished, and frames only an interrupted earlier run found undecodable
  are decoded again before they are flagged.
- Renders resolve stand-ins only for frames the pipeline asks for; frames
  the read-ahead meets on the way (skipped by speed-ups) are left alone.
- A GoPro GPR finds its JPEG in the index when an import or upload kept it
  in a sequence of its own (same original stem and capture time), for
  probes, deep analysis, renders, thumbnails, proxies and the editor;
  GPRs whose JPEG is indexed later are probed again.
- Thumbnails judge an embedded preview by its own JPEG header.
- PostgreSQL writes tier fields 1000 frames per statement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 11:17:49 +00:00
1 parent 366dd9f303
commit 5599e4de89
19 files changed
+689 -111

No files matched your search

+32 -15
View File
@@ -30,6 +30,9 @@ internal sealed record AnalysisOutcome(Sequence Sequence, int Frames, int Warnin
/// </summary>
internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions options, SequenceWriter writer, ArchiveIndexer indexer, ProjectStore projects)
{
/// <summary>Long edge of the decode that confirms a frame an interrupted earlier run found undecodable.</summary>
private const int ConfirmLongEdge = 64;
private readonly FrameTiers _tiers = new(db, writer, indexer);
/// <summary>Analyses one sequence; null when it is no longer in the index.</summary>
@@ -43,15 +46,15 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
var folder = paths.Sequence(sequence.Folder);
var frames = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, cancellationToken).ConfigureAwait(false);
// Format tiers (BRIEF §10.1): frames indexed since the last analysis are probed with this host's decoders.
var probed = _tiers.ProbeUnknown(folder, ManifestStore.ReadSequence(folder.ManifestPath), cancellationToken);
var probed = await _tiers.ProbeUnknownAsync(archive, folder, ManifestStore.ReadSequence(folder.ManifestPath), cancellationToken).ConfigureAwait(false);
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, cancellationToken).ConfigureAwait(false));
var metadata = frames.LightFrames();
DeepAnalysisReport? report;
if (deep)
{
(report, var observed) = await AnalyseDeepAsync(frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, Decoded(frames, report, observed), cancellationToken).ConfigureAwait(false));
(report, var decoded) = await AnalyseDeepAsync(archive, frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, decoded, cancellationToken).ConfigureAwait(false));
metadata = [.. metadata.Select((m, i) => m with { Flags = frames.Frames[i].Flags })];
}
else
@@ -128,35 +131,49 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
}
/// <summary>
/// What the deep pass learnt about each frame's tier: the tier this run decoded it at, else (for frames analysed by
/// an interrupted earlier run) unavailable when the report says it did not decode. Missing and corrupt frames are not
/// decoded at all, so they say nothing.
/// What the deep pass learnt about each frame's tier, by frame id: the tier this run decoded it at. A frame this run
/// tried to read and recorded nothing for vanished or could not be read, which says nothing about its content. A frame
/// only an interrupted earlier run analysed and found undecodable is decoded again (small) to confirm it: that run's
/// failure may have been a read error too. Missing and corrupt frames are not decoded at all.
/// </summary>
private static Dictionary<Guid, FileTier> Decoded(SequenceFrames frames, DeepAnalysisReport report, IReadOnlyDictionary<int, FileTier> observed)
private Dictionary<Guid, FileTier> Decoded(SequenceFrames frames, DeepAnalysisReport report, SequenceFrameSource source,
IReadOnlyDictionary<Guid, string> companions, CancellationToken cancellationToken)
{
var tiers = new Dictionary<Guid, FileTier>();
foreach (var (index, tier) in observed) tiers[frames.Frames[index].Id] = tier;
foreach (var (index, tier) in source.Observed) tiers[frames.Frames[index].Id] = tier;
var read = source.Read.ToHashSet();
foreach (var index in report.Issues.Undecodable)
{
if (index >= frames.Count || observed.ContainsKey(index) || frames.Files[index] is null
if (index >= frames.Count || read.Contains(index) || frames.Files[index] is not { } path
|| (frames.Frames[index].Flags & SequenceFrames.NotAnalysed) != 0) continue;
var frame = frames.Frames[index];
tiers[frame.Id] = new FileTier(frame.Format, DecodeTier.Unavailable, null, "no decoder produced pixels", 0, 0);
try
{
using var decoded = options.Archive.Decoder.Decode(
new DecodeRequest(path, ConfirmLongEdge, DecodePurpose.Analysis, Companion: companions.GetValueOrDefault(frame.Id)), cancellationToken);
if (decoded is not null) tiers[frame.Id] = new FileTier(frame.Format, decoded.Tier, decoded.Decoder, null, 0, 0);
else if (File.Exists(path)) tiers[frame.Id] = new FileTier(frame.Format, DecodeTier.Unavailable, null, "no decoder produced pixels", 0, 0);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Core.Diagnostics.Log.Warning("processing", $"Frame {path} could not be read", ex);
}
}
return tiers;
}
private async Task<(DeepAnalysisReport Report, IReadOnlyDictionary<int, FileTier> Observed)> AnalyseDeepAsync(SequenceFrames frames,
private async Task<(DeepAnalysisReport Report, Dictionary<Guid, FileTier> Decoded)> AnalyseDeepAsync(Archive archive, SequenceFrames frames,
IReadOnlyList<LightFrame> metadata, SequencePaths folder, IProgress<AnalysisProgress>? progress, CancellationToken cancellationToken)
{
var file = new DeepAnalysisCheckpointFile(Path.Combine(folder.MetaDirectory, DeepAnalysisCheckpointFile.FileName));
var companions = await GprCompanions.FindAsync(db, archive, frames.Frames, cancellationToken).ConfigureAwait(false);
DeepAnalysisReport report;
IReadOnlyDictionary<int, FileTier> observed;
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder) { Originals = true })
Dictionary<Guid, FileTier> decoded;
await using (var source = new SequenceFrameSource(frames, metadata, options.Archive.Decoder) { Originals = true, Companions = companions })
{
report = await DeepAnalyzer.AnalyzeAsync(source, options.DeepAnalysis, new FramesCheckpoint(file, ContentKey(frames)), progress, cancellationToken)
.ConfigureAwait(false);
observed = source.Observed.ToDictionary();
decoded = Decoded(frames, report, source, companions, cancellationToken);
}
report.Save(folder.AnalysisPath);
file.Delete();
@@ -166,7 +183,7 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
for (var i = 0; i < stats.Length; i++)
stats[i] = new FrameLightStats(frames.Frames[i].Id, columns.LogLuminance[i], columns.ClipLow[i], columns.ClipHigh[i]);
await db.Frames.UpdateLightStatsAsync(stats, cancellationToken).ConfigureAwait(false);
return (report, observed);
return (report, decoded);
}
/// <summary>Identity of the analysed content: frames replaced or renumbered since a checkpoint was written (with the