E3: correzioni della revisione di formati e fotogrammi

Le 16 osservazioni confermate della revisione, ognuna con la sua prova:

- JPEG: il controllo stima la memoria di lavoro del decodificatore
  (progressivo), così un file che non si decodifica esce «troppo
  grande» e non «illeggibile».
- Un EXIF che non si tiene lascia un EXIF minimo con l'orientamento,
  perché la foto convertita non esca girata.
- Fotogrammi: istanti in millisecondi interi; la copia trova l'indice
  del nome dall'istante, non dall'ordine delle righe.
- Video di durata sconosciuta misurati prima di registrare: contano
  nei limiti di 500 per richiesta e 5000 per video.
- Rimuxaggio: la durata del segmento di elst passa nell'MP4, la fine
  tagliata resta nascosta (anche nei fotogrammi).
- H.264: il punto di recupero vale come IDR solo con exact_match_flag.
- MP3 in MP4: objectTypeIndication 0x69 fino a 24 kHz, 0x6B oltre.
- Conversione della libreria: il lavoro toglie le righe di un formato
  spento o cambiato; spegnere toglie anche i «Non riuscito»; «Riprova»
  solo i formati di adesso; pausa per spazio prima di rileggere
  l'originale.
- «Anche i N» conta e mette in coda solo il tipo che si cambia; le
  impostazioni dell'esportazione si salvano una per volta.
- Eliminazione e «Tieni il più grande» scelgono i convertiti nella
  stessa transazione: nessun convertito orfano.
- Un file arrivato tardi in un elemento vecchio mette in coda solo sé
  (file nuovo = salvato da quando il formato è scelto).
- Zip dei fotogrammi a pezzi di 64 KB: un browser lento che legge non
  si interrompe, uno fermo sì.

Decisioni in docs/decisioni.md (28/11), §4.10 della specifica precisato.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-28 13:30:33 +01:00
1 parent eb79b05fda
commit 958cb71cd6
38 files changed
+1276 -222

No files matched your search

+48 -44
View File
@@ -167,11 +167,26 @@ public sealed class ExportService : IAsyncDisposable
var runs = new Dictionary<long, ExportRun>();
var pending = new List<ExportItem>();
var exports = _env.Storage.Exports;
// Frames job: the videos whose length the library does not know are measured once, in the first pass, so that
// their frames count against the caps; the recording pass reuses the lengths (they cannot disagree).
var lengths = new Dictionary<long, TimeSpan?>();
Func<ExportCandidate, CancellationToken, Task<TimeSpan?>>? lengthOf = request.Frames is null
? null
: async (candidate, token) =>
{
if (!lengths.TryGetValue(candidate.MediaId, out var length))
{
length = await ProbeLengthAsync(candidate, token).ConfigureAwait(false);
lengths[candidate.MediaId] = length;
}
return length;
};
if (request.Frames is not null)
{
// Refused before anything is recorded (D12 of tappa E3): a video over 1.000 frames, more than 20.000 in all.
var count = new PlanTally();
await foreach (var file in Planner.EnumerateAsync(request, effective, settings, ct).ConfigureAwait(false))
await foreach (var file in Planner.EnumerateAsync(request, effective, settings, ct, lengthOf).ConfigureAwait(false))
{
count.Add(file);
}
@@ -187,9 +202,10 @@ public sealed class ExportService : IAsyncDisposable
}
}
var frameItems = 0;
try
{
await foreach (var file in Planner.EnumerateAsync(request, effective, settings, ct).ConfigureAwait(false))
await foreach (var file in Planner.EnumerateAsync(request, effective, settings, ct, lengthOf).ConfigureAwait(false))
{
tally.Add(file);
if (file.DestinationId is not { } destination || file.Action is PlannedCopy.Missing or PlannedCopy.NotExported or PlannedCopy.PhotoSkipped or PlannedCopy.OverCap)
@@ -207,24 +223,24 @@ public sealed class ExportService : IAsyncDisposable
}
// Frame items of one video are added together, in instant order (the copy takes them as one batch).
IReadOnlyList<TimeSpan?> instants = file.UnknownDuration && request.Frames is { } frames
? await FrameInstantsAsync(file.Candidate, frames, ct).ConfigureAwait(false)
: [file.FrameAt];
foreach (var at in instants)
// The first pass already refused more than 20.000: this only guards that it saw the same files.
if (file.Variant == ExportVariant.Frame && file.Action == PlannedCopy.Write && ++frameItems > ExportFrames.MaxPerRequest)
{
pending.Add(new ExportItem
{
RunId = run.Id,
MediaId = file.Candidate.MediaId,
AccountId = file.Candidate.AccountId,
SourceSha256 = file.Candidate.Sha256,
Variant = file.Variant,
Format = file.Format,
FrameAt = at,
State = ExportItemState.Pending,
});
throw new ArgumentException(TooManyFramesText, nameof(request));
}
pending.Add(new ExportItem
{
RunId = run.Id,
MediaId = file.Candidate.MediaId,
AccountId = file.Candidate.AccountId,
SourceSha256 = file.Candidate.Sha256,
Variant = file.Variant,
Format = file.Format,
FrameAt = file.FrameAt,
State = ExportItemState.Pending,
});
if (pending.Count >= ItemBatch)
{
await exports.AddItemsAsync(pending, CancellationToken.None).ConfigureAwait(false);
@@ -299,44 +315,32 @@ public sealed class ExportService : IAsyncDisposable
}
/// <summary>
/// The instants of a video whose length the library does not know: its headers are read now (only the library
/// file, never the destination). A video that cannot be read gets one instant, and the copy says «Fotogramma non
/// disponibile per questo video».
/// The length of a video the library does not know, from its headers (only the library file, never the
/// destination); null when it cannot be read now (the job then gives it one instant, and the copy tells).
/// </summary>
private async Task<IReadOnlyList<TimeSpan?>> FrameInstantsAsync(ExportCandidate candidate, ExportFramesRequest frames, CancellationToken ct)
private async Task<TimeSpan?> ProbeLengthAsync(ExportCandidate candidate, CancellationToken ct)
{
TimeSpan? duration = null;
var media = await _env.Storage.Media.GetAsync(candidate.MediaId, ct).ConfigureAwait(false);
var account = await _env.Storage.Accounts.GetAsync(candidate.AccountId, ct).ConfigureAwait(false);
if (media is not null && account is not null && _env.ResolveSourcePath(account, media) is { } path)
if (media is null || account is null || _env.ResolveSourcePath(account, media) is not { } path)
{
try
{
duration = await Task.Run(
() =>
{
using var stream = _env.FileSystem.OpenRandomAccess(path);
return VideoFrameReader.ProbeDuration(stream);
},
ct).ConfigureAwait(false);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
// Not readable now: one instant, the copy tells.
}
return null;
}
if (duration is not { } d || d <= TimeSpan.Zero)
try
{
return [TimeSpan.Zero];
return await Task.Run(
() =>
{
using var stream = _env.FileSystem.OpenRandomAccess(path);
return VideoFrameReader.ProbeDuration(stream);
},
ct).ConfigureAwait(false);
}
if (ExportFrames.FrameCount(d, frames) > ExportFrames.MaxPerVideo)
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
throw new ArgumentException(ExportFrames.OverCapMessage, nameof(frames));
return null; // not readable now: one instant, the copy tells
}
return [.. ExportFrames.Instants(d, frames).Select(at => (TimeSpan?)at)];
}
/// <summary>