E4: API dei video fermi e «Salva il fotogramma»
«È un video fermo?» dal visualizzatore (POST /api/media/{id}/still, con
400/404/409/503 e niente salvato negli errori) e l'esito su ogni video
dell'elemento (media[].still), perché l'interfaccia di WP6 lo mostri.
«Salva il fotogramma» salva il fotogramma scelto dall'analisi (il più
nitido, mai uno scuro, risposta 45): «Scarica» da
/api/media/{id}/still/frame con il nome …_fotogramma.png, e «Nella
cartella delle copie» con frames.mode "fermo" attraverso pianificatore,
impostazioni del lavoro e copiatore (FrameMode.Still, suffisso
_fotogramma, stessa identità delle copie dei fotogrammi di E3). Vale per
un video solo (risposta 46); un video non fermo o mai analizzato si
conta come notStill e non si copia.
«Cerca i video fermi» per una selezione: conferma con i conteggi,
avvio, avanzamento e «Interrompi» (/api/still-videos/*). Tutti i DTO nel
FebeJsonContext; i comandi passano dal controllo dell'Origin. Il servizio
registra con ILogger e FebeApp lo chiude all'arresto prima dell'archivio.
LEGGIMI di Febe.Web aggiornato; prove dell'API su video costruiti.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f238f2c9f
commit
51150fb611
17 files changed
+695
-18
No files matched your search
@@ -32,7 +32,7 @@ public static class ExportFrames
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
return request.Mode switch
|
||||
{
|
||||
FrameMode.At => 1,
|
||||
FrameMode.At or FrameMode.Still => 1,
|
||||
FrameMode.Every => EveryCount(duration, request.Every ?? throw new ArgumentException("Manca l'intervallo dei fotogrammi.", nameof(request))),
|
||||
FrameMode.Count => request.Count ?? throw new ArgumentException("Manca il numero dei fotogrammi.", nameof(request)),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(request)),
|
||||
@@ -48,7 +48,8 @@ public static class ExportFrames
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
return request.Mode switch
|
||||
{
|
||||
FrameMode.At => [request.At is { } at && at > TimeSpan.Zero ? at : TimeSpan.Zero],
|
||||
// «Salva il fotogramma»: the caller puts the analysis' instant in At (the planner reads it per video).
|
||||
FrameMode.At or FrameMode.Still => [request.At is { } at && at > TimeSpan.Zero ? at : TimeSpan.Zero],
|
||||
FrameMode.Every => Every(duration, request.Every ?? throw new ArgumentException("Manca l'intervallo dei fotogrammi.", nameof(request))),
|
||||
FrameMode.Count => Spread(duration, request.Count ?? throw new ArgumentException("Manca il numero dei fotogrammi.", nameof(request))),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(request)),
|
||||
@@ -102,11 +103,17 @@ public static class ExportFrames
|
||||
/// <summary>
|
||||
/// The suffix of a frame file, appended to the stem: <c>_t0m12s340</c> (the actual instant: minutes, seconds on two
|
||||
/// digits, milliseconds on three) for «Questo istante» and «Uno ogni k secondi»; <c>_f001</c> (the position among
|
||||
/// the <paramref name="count"/> instants, at least three digits) for «N in tutto».
|
||||
/// the <paramref name="count"/> instants, at least three digits) for «N in tutto»; <c>_fotogramma</c>
|
||||
/// (<see cref="SingleSuffix"/>) for «Salva il fotogramma» of a still video.
|
||||
/// </summary>
|
||||
/// <param name="index">0-based position of the instant in the request.</param>
|
||||
public static string Suffix(FrameMode mode, TimeSpan actual, int index, int count)
|
||||
{
|
||||
if (mode == FrameMode.Still)
|
||||
{
|
||||
return SingleSuffix;
|
||||
}
|
||||
|
||||
if (mode == FrameMode.Count)
|
||||
{
|
||||
var digits = Math.Max(3, Math.Max(1, count).ToString(CultureInfo.InvariantCulture).Length);
|
||||
|
||||
@@ -34,6 +34,13 @@ public enum FrameMode
|
||||
|
||||
/// <summary>«N in tutto»: N frames spread over the video, each in the middle of its share.</summary>
|
||||
Count,
|
||||
|
||||
/// <summary>
|
||||
/// «Salva il fotogramma» of a still video (tappa E4, answer 45): the one frame the analysis chose (the sharpest
|
||||
/// looked at, never a dark one), at the instant <c>video_analysis</c> keeps; named <c>…_fotogramma</c>. One video
|
||||
/// only (answer 46).
|
||||
/// </summary>
|
||||
Still,
|
||||
}
|
||||
|
||||
/// <summary>A request of frames of videos, in a photo format (Jpg, Png or WebpLossless).</summary>
|
||||
@@ -114,6 +121,12 @@ public sealed record ExportPlan(
|
||||
|
||||
/// <summary>Frames job: videos that would give more than <see cref="ExportFrames.MaxPerVideo"/> frames (the job is refused).</summary>
|
||||
public int OverCap { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// «Salva il fotogramma» (tappa E4): due videos whose analysis is not «Fermo», or that were never analysed (skipped:
|
||||
/// «Non è un video fermo, o non è stato analizzato»).
|
||||
/// </summary>
|
||||
public int NotStill { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Files of a plan copied as they are, of one kind («HEIC», «AVIF», «raw», «GIF», «WebM»).</summary>
|
||||
|
||||
@@ -99,7 +99,12 @@ public sealed class ExportPlanner(ExportEnvironment env)
|
||||
throw new ArgumentException("L'intervallo minimo è 0,1 secondi.", nameof(request));
|
||||
case FrameMode.Count when frames.Count is not ({ } count and >= 1 and <= ExportFrames.MaxCount):
|
||||
throw new ArgumentException("Da 1 a 1.000 fotogrammi.", nameof(request));
|
||||
case FrameMode.At or FrameMode.Every or FrameMode.Count:
|
||||
case FrameMode.Still when frames.At is not null || frames.Every is not null || frames.Count is not null:
|
||||
throw new ArgumentException("«Salva il fotogramma» prende il fotogramma scelto dall'analisi: niente istante, intervallo o numero.", nameof(request));
|
||||
case FrameMode.Still when request.Selection is not ExportSelection.Media { MediaIds.Count: 1 }:
|
||||
// Answer 46 of Alberto (29 November 2026): only from the viewer, one video.
|
||||
throw new ArgumentException("«Salva il fotogramma» vale per un video solo, dal visualizzatore.", nameof(request));
|
||||
case FrameMode.At or FrameMode.Every or FrameMode.Count or FrameMode.Still:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Modo dei fotogrammi sconosciuto.", nameof(request));
|
||||
@@ -294,6 +299,24 @@ public sealed class ExportPlanner(ExportEnvironment env)
|
||||
Prediction = ExportPrediction.Converted,
|
||||
FirstOfVideo = true,
|
||||
};
|
||||
if (frames.Mode == FrameMode.Still)
|
||||
{
|
||||
// «Salva il fotogramma» (tappa E4): the instant the analysis chose, by SHA-256 of the file; a video
|
||||
// that is not «Fermo» (or was never analysed) gives nothing.
|
||||
var analysis = await _env.Storage.VideoAnalyses.GetAsync(c.Sha256!, ct).ConfigureAwait(false);
|
||||
if (analysis is not { Outcome: VideoAnalysisOutcome.Still, FrameAt: { } still })
|
||||
{
|
||||
yield return frame with { Action = PlannedCopy.NotStill };
|
||||
continue;
|
||||
}
|
||||
|
||||
var chosen = frame with { FrameAt = still };
|
||||
yield return seen.Add((destination, c.AccountId, c.Sha256!, (long)still.TotalMilliseconds, frames.Format))
|
||||
? chosen
|
||||
: chosen with { Action = PlannedCopy.AlreadyCopied };
|
||||
continue;
|
||||
}
|
||||
|
||||
var duration = c.Duration ?? TimeSpan.Zero;
|
||||
if (frames.Mode != FrameMode.At && c.Duration is null)
|
||||
{
|
||||
@@ -409,6 +432,9 @@ internal enum PlannedCopy
|
||||
|
||||
/// <summary>Frames job: a video over <see cref="ExportFrames.MaxPerVideo"/> frames.</summary>
|
||||
OverCap,
|
||||
|
||||
/// <summary>«Salva il fotogramma» (tappa E4): a video whose analysis is not «Fermo», or that was never analysed.</summary>
|
||||
NotStill,
|
||||
}
|
||||
|
||||
/// <summary>Counts of a plan while its files go by.</summary>
|
||||
@@ -441,15 +467,20 @@ internal sealed class PlanTally
|
||||
|
||||
public int OverCap { get; private set; }
|
||||
|
||||
public int NotStill { get; private set; }
|
||||
|
||||
public void Add(PlannedFile file)
|
||||
{
|
||||
if (file.FirstOfVideo && file.Action is not (PlannedCopy.OverCap or PlannedCopy.NotExported or PlannedCopy.Missing))
|
||||
if (file.FirstOfVideo && file.Action is not (PlannedCopy.OverCap or PlannedCopy.NotExported or PlannedCopy.Missing or PlannedCopy.NotStill))
|
||||
{
|
||||
Videos++;
|
||||
}
|
||||
|
||||
switch (file.Action)
|
||||
{
|
||||
case PlannedCopy.NotStill:
|
||||
NotStill++;
|
||||
return;
|
||||
case PlannedCopy.Missing:
|
||||
Missing++;
|
||||
return;
|
||||
@@ -545,6 +576,7 @@ internal sealed class PlanTally
|
||||
PhotosSkipped = PhotosSkipped,
|
||||
Frames = Frames,
|
||||
OverCap = OverCap,
|
||||
NotStill = NotStill,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,10 @@ internal static class ExportRunSettings
|
||||
{
|
||||
public static string CopyAgainKey(long runId) => string.Create(CultureInfo.InvariantCulture, $"esportazione.lavoro.{runId}.copia-di-nuovo");
|
||||
|
||||
/// <summary>How the frames of a frames job were asked (tappa E3): <c>Istante</c>, <c>Ogni</c> or <c>Numero:N</c>.</summary>
|
||||
/// <summary>
|
||||
/// How the frames of a frames job were asked (tappa E3): <c>Istante</c>, <c>Ogni</c> or <c>Numero:N</c>; <c>Fermo</c>
|
||||
/// for «Salva il fotogramma» of a still video (tappa E4).
|
||||
/// </summary>
|
||||
public static string FramesKey(long runId) => string.Create(CultureInfo.InvariantCulture, $"esportazione.lavoro.{runId}.fotogrammi");
|
||||
|
||||
/// <summary>«Copia di nuovo» of one copy row: only its exact identity is looked up (decision D11 of tappa E3).</summary>
|
||||
@@ -36,6 +39,11 @@ internal static class ExportRunSettings
|
||||
return (FrameMode.Every, 0);
|
||||
}
|
||||
|
||||
if (string.Equals(text, "Fermo", StringComparison.Ordinal))
|
||||
{
|
||||
return (FrameMode.Still, 1);
|
||||
}
|
||||
|
||||
return text.StartsWith("Numero:", StringComparison.Ordinal)
|
||||
&& int.TryParse(text.AsSpan("Numero:".Length), NumberStyles.None, CultureInfo.InvariantCulture, out var count) && count > 0
|
||||
? (FrameMode.Count, count)
|
||||
@@ -49,6 +57,7 @@ internal static class ExportRunSettings
|
||||
{
|
||||
FrameMode.At => "Istante",
|
||||
FrameMode.Every => "Ogni",
|
||||
FrameMode.Still => "Fermo",
|
||||
_ => string.Create(CultureInfo.InvariantCulture, $"Numero:{count}"),
|
||||
},
|
||||
ct);
|
||||
|
||||
@@ -208,7 +208,7 @@ public sealed class ExportService : IAsyncDisposable
|
||||
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)
|
||||
if (file.DestinationId is not { } destination || file.Action is PlannedCopy.Missing or PlannedCopy.NotExported or PlannedCopy.PhotoSkipped or PlannedCopy.OverCap or PlannedCopy.NotStill)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,15 @@ public static class StillVideoText
|
||||
/// <summary>The bytes on disk are not the ones recorded (the same words as the copies).</summary>
|
||||
public const string SourceChanged = "Il file della libreria non corrisponde a quello registrato.";
|
||||
|
||||
/// <summary>«Salva il fotogramma» of a video whose analysis is not «Fermo», or that was never analysed.</summary>
|
||||
public const string NotStill = "Non è un video fermo, o non è stato analizzato";
|
||||
|
||||
/// <summary>A selection of «Cerca i video fermi» that names nothing.</summary>
|
||||
public const string NoSelection = "Scegli quali video analizzare: dei file, degli elementi, i risultati del filtro o un account.";
|
||||
|
||||
/// <summary>The frame of a still video is saved from the viewer only (answer 46).</summary>
|
||||
public const string FromViewerOnly = "Il fotogramma di un video fermo si salva dal visualizzatore, con «Salva il fotogramma».";
|
||||
|
||||
/// <summary>The job waits for the end of an engine session.</summary>
|
||||
public const string InSession = "Il motore è in sessione: la ricerca dei video fermi riprende dopo";
|
||||
|
||||
|
||||
Reference in new issue
Block a user