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:
1 parent
eb79b05fda
commit
958cb71cd6
38 files changed
+1276
-222
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Codecs.Containers;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Export;
|
||||
using Febe.Core.Library;
|
||||
@@ -234,6 +235,101 @@ public sealed class ExportFramesTests
|
||||
Assert.IsEmpty(Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task NInAllOnAVideoShorterThanNMillisecondsNamesEachFrameByItsPosition()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var still = TestVideos.Mp4(Stream.FirstPictureRepeated(18)); // 0,6 s: 1.000 instants cannot all be a millisecond apart
|
||||
var video = (await SaveVideoAsync(bed, bed.Marta, "993", still, ".mp4")).Media[0];
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
const int N = 1000;
|
||||
|
||||
// The instants are whole milliseconds (the item, the preview and the download locate the same one); the first of
|
||||
// those on one millisecond is the item, the others are counted as already there.
|
||||
var instants = ExportFrames.Spread(Duration(still), N);
|
||||
Assert.IsTrue(instants.All(t => t.Ticks % TimeSpan.TicksPerMillisecond == 0));
|
||||
var firsts = instants.Select((t, i) => (Ms: (long)t.TotalMilliseconds, Index: i)).GroupBy(x => x.Ms).Select(g => g.First()).ToList();
|
||||
Assert.IsLessThan(N, firsts.Count);
|
||||
|
||||
var start = await bed.CopyAsync(Frames(video, new ExportFramesRequest(FrameMode.Count, null, null, N, ExportFormat.Png)), ct);
|
||||
|
||||
Assert.AreEqual((firsts.Count, N - firsts.Count), (start.Plan.Frames, start.Plan.AlreadyCopied), "the plan says what is recorded");
|
||||
var items = await bed.ItemsAsync(start.Runs.Single().Id, ct);
|
||||
CollectionAssert.AreEqual(firsts.Select(f => (TimeSpan?)TimeSpan.FromMilliseconds(f.Ms)).ToArray(), items.Select(i => i.FrameAt).ToArray());
|
||||
|
||||
// Each frame written is named by its position among the N instants, as «Scarica» names it, not by its row.
|
||||
var targets = Locate(still, [.. firsts.Select(f => TimeSpan.FromMilliseconds(f.Ms))]);
|
||||
var stem = Path.ChangeExtension(video.RelativePath!, null);
|
||||
var leaders = targets.Select((t, k) => (t.Sample, k)).GroupBy(x => x.Sample).Select(g => g.First().k).ToList();
|
||||
Assert.HasCount(leaders.Count, Fingerprint.Of(bed.Usb));
|
||||
foreach (var k in leaders)
|
||||
{
|
||||
Assert.AreEqual(ExportItemState.Copied, items[k].State);
|
||||
Assert.AreEqual("marta.demo/" + stem + ExportFrames.Suffix(FrameMode.Count, targets[k].Actual, firsts[k].Index, N) + ".png", items[k].RelativePath, $"frame {k}");
|
||||
}
|
||||
|
||||
Assert.AreNotEqual(leaders.Count - 1, firsts[leaders[^1]].Index, "the positions skip the instants on one millisecond");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task VideosOfUnknownLengthCountAgainstTheCapsBeforeAnythingIsRecorded()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
|
||||
// One video of 200 s the library has no length for, one every 0,1 s: 2.000 frames, refused before any run.
|
||||
var long200 = (await SaveVideoAsync(bed, bed.Marta, "980", LongStill(200), ".mp4")).Media[0];
|
||||
var every = Frames(long200, new ExportFramesRequest(FrameMode.Every, null, TimeSpan.FromMilliseconds(100), null, ExportFormat.Png));
|
||||
var overCap = await Assert.ThrowsExactlyAsync<ArgumentException>(() => bed.Service.StartAsync(every, ct));
|
||||
StringAssert.StartsWith(overCap.Message, ExportFrames.OverCapMessage);
|
||||
Assert.IsEmpty(await bed.Db.Exports.ListRunsAsync(ct));
|
||||
|
||||
// 21 videos of a second without a length, 1.000 each: 21.000 frames, over the 20.000 of a request.
|
||||
var still = Stream.FirstPictureRepeated(30);
|
||||
var ids = new List<long>();
|
||||
for (var i = 0; i < 21; i++)
|
||||
{
|
||||
ids.Add((await SaveVideoAsync(bed, bed.Marta, $"96{i:D2}", TestVideos.Mp4(still, Make.T0.AddDays(-i)), ".mp4")).Media[0].Id);
|
||||
}
|
||||
|
||||
var many = new ExportJobRequest(new ExportSelection.Media(ids), Frames: new ExportFramesRequest(FrameMode.Count, null, null, 1000, ExportFormat.Png));
|
||||
var tooMany = await Assert.ThrowsExactlyAsync<ArgumentException>(() => bed.Service.StartAsync(many, ct));
|
||||
StringAssert.StartsWith(tooMany.Message, ExportService.TooManyFramesText);
|
||||
Assert.IsEmpty(await bed.Db.Exports.ListRunsAsync(ct));
|
||||
Assert.IsEmpty(Fingerprint.Of(bed.Usb));
|
||||
|
||||
Assert.AreEqual(21, (await bed.Service.PlanAsync(many, ct)).Frames, "the dialog does not read the files: «circa» one a video");
|
||||
|
||||
// Two of them, 3 each: measured when the job is recorded, the plan of the start says what was recorded.
|
||||
var two = new ExportJobRequest(new ExportSelection.Media(ids.Take(2).ToList()), Frames: new ExportFramesRequest(FrameMode.Count, null, null, 3, ExportFormat.Png));
|
||||
var started = await bed.CopyAsync(two, ct);
|
||||
Assert.AreEqual((2, 6), (started.Plan.Videos, started.Plan.Frames));
|
||||
Assert.HasCount(6, await bed.ItemsAsync(started.Runs.Single().Id, ct));
|
||||
}
|
||||
|
||||
/// <summary>A video of one still picture shown for <paramref name="seconds"/>.</summary>
|
||||
private static byte[] LongStill(int seconds)
|
||||
{
|
||||
var es = Stream.FirstPictureRepeated(1);
|
||||
var bytes = es.LengthPrefixed(0);
|
||||
var track = new Mp4OutputTrack
|
||||
{
|
||||
IsVideo = true,
|
||||
Timescale = TestVideos.Timescale,
|
||||
Samples = [new Mp4OutputSample(bytes.Length, 0, 0, true)],
|
||||
WriteSample = (_, s) => s.Write(bytes),
|
||||
Width = es.Width,
|
||||
Height = es.Height,
|
||||
AvcConfiguration = es.AvcC,
|
||||
LastSampleDuration = (long)seconds * TestVideos.Timescale,
|
||||
};
|
||||
using var output = new MemoryStream();
|
||||
Mp4Writer.Write(output, [track]);
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
private static ExportJobRequest Frames(Media video, ExportFramesRequest frames) => new(new ExportSelection.Media([video.Id]), Frames: frames);
|
||||
|
||||
/// <summary>A video whose length the library does not know (it is read when the job is recorded).</summary>
|
||||
|
||||
Reference in new issue
Block a user