E4: prove dei video fermi e dimostrazione a ogni ora
Completa l'elenco di prove del progetto: analizzatore (grana, luce che pulsa, foto notturna, contenitori, durata sconosciuta, flussi rovinati), servizio (lavori lunghi, file spariti o cambiati, errori, «Interrompi», chiusura), copie del fotogramma (pausa e ripresa, validazione, video sempre intero), API (selezioni, stesso file, eventi) e l'interfaccia vera nel browser: visualizzatore, «Salva il fotogramma», «Cerca i video fermi», Dashboard e filtro «Video fermi». Le prove hanno trovato che la dimostrazione dipendeva dall'ora: la storia ferma poteva avere la copertina del video fermo di marta (un file solo invece di due) e il video «Non analizzabile» poteva mancare. Ora la storia è su un'altra immagine e, se le immagini senza copie non bastano, si usano quelle di foto copiate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eea4394a0f
commit
066addbc84
10 files changed
+1100
-18
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Febe.Core.Codecs.Containers;
|
||||
using Febe.Core.Codecs.H264;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Export;
|
||||
@@ -328,6 +329,154 @@ public sealed class StillVideoAnalyzerTests
|
||||
Assert.ThrowsExactly<OperationCanceledException>(() => StillVideoAnalyzer.Analyse(again, TimeSpan.FromSeconds(30), cancelled.Token));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(2)]
|
||||
[DataRow(3)]
|
||||
public void AClipOfAFewEqualPicturesIsStill(int pictures)
|
||||
{
|
||||
// 0,07 and 0,1 seconds: every picture is looked at.
|
||||
var photo = PcmVideos.Photo(20);
|
||||
var result = Analyse(PcmVideos.Mp4(pictures, _ => photo, audio: true));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, result.Outcome, Describe(result));
|
||||
Assert.AreEqual(pictures, result.Sampled);
|
||||
Assert.AreEqual(0L, result.FrameAtMs, "the first of equally sharp ones");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StrongGrainAndAPulsingLightAreNotMotion()
|
||||
{
|
||||
var photo = PcmVideos.Photo(21);
|
||||
var grain = Analyse(PcmVideos.Mp4(30, i => PcmVideos.Noise(photo, 8, 500 + i)));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, grain.Outcome, Describe(grain));
|
||||
Assert.IsNull(grain.Note);
|
||||
|
||||
// The light goes from full to 60 % and back, twice: the frame chosen is one at (nearly) full light.
|
||||
double Light(long i) => 0.8 + (0.2 * Math.Cos(i * 4 * Math.PI / 30));
|
||||
var pulsing = Analyse(PcmVideos.Mp4(30, i => PcmVideos.Fade(photo, Light(i))));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, pulsing.Outcome, Describe(pulsing));
|
||||
Assert.IsGreaterThan(0.85, Light(pulsing.FrameAtMs!.Value * PcmVideos.Fps / 1000), Describe(pulsing));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ANightPhotoIsStillNotAllDark()
|
||||
{
|
||||
// Black all over but a lit sign of 16 × 16 pixels: a picture, not a black video (answer 42).
|
||||
var night = PcmVideos.Sticker(PcmVideos.Black(), 60, 100, 16, 16);
|
||||
var result = Analyse(PcmVideos.Mp4(30, _ => night));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, result.Outcome, Describe(result));
|
||||
Assert.IsNull(result.Note);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ADarkFrameIsNeverChosenEvenWhenItsGrainIsSharper()
|
||||
{
|
||||
// Nine nearly black pictures full of grain (a camera that starts in the dark), then a soft gradient with no
|
||||
// detail: the Laplacian of the grain is larger, yet «Salva il fotogramma» must never save black (answer 45).
|
||||
var soft = PcmVideos.Flat(120);
|
||||
for (var y = 0; y < PcmVideos.Height; y++)
|
||||
{
|
||||
for (var x = 0; x < PcmVideos.Width; x++)
|
||||
{
|
||||
soft.Y[(y * PcmVideos.Width) + x] = (byte)(60 + ((x + y) / 4));
|
||||
}
|
||||
}
|
||||
|
||||
H264PcmPicture Dark(int i) => PcmVideos.Noise(PcmVideos.Black(), 12, 900 + i);
|
||||
var result = Analyse(PcmVideos.Mp4(30, i => i < 9 ? Dark(i) : soft));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, result.Outcome, Describe(result));
|
||||
Assert.IsGreaterThanOrEqualTo(Ms(9), result.FrameAtMs!.Value, Describe(result));
|
||||
|
||||
// The grain is a real trap (the same grain on a grey that is not dark is far sharper than the gradient), and a
|
||||
// video of it alone is all dark: no frame to save.
|
||||
var lit = Analyse(PcmVideos.Mp4(9, i => PcmVideos.Noise(PcmVideos.Sticker(PcmVideos.Flat(60), 60, 100, 16, 16), 6, 900 + i)));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, lit.Outcome, Describe(lit));
|
||||
Assert.IsGreaterThan(result.Sharpness, lit.Sharpness);
|
||||
var dark = Analyse(PcmVideos.Mp4(9, Dark));
|
||||
Assert.AreEqual(VideoAnalysisNotes.AllDark, dark.Note, Describe(dark));
|
||||
Assert.IsNull(dark.FrameAt);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AVideoHalfTurnedIsUprightToo()
|
||||
{
|
||||
var photo = PcmVideos.Photo(22);
|
||||
var result = Analyse(PcmVideos.Mp4(12, _ => photo, rotation: 180));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, result.Outcome, Describe(result));
|
||||
Assert.AreEqual(180, result.Rotation);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheContainerDoesNotChangeTheOutcome()
|
||||
{
|
||||
var photo = PcmVideos.Photo(23);
|
||||
var still = PcmVideos.Stream("pcm", 30, _ => photo);
|
||||
var pan = PcmVideos.Stream("pcm", 30, i => PcmVideos.Shift(photo, 3 * i));
|
||||
foreach (var (name, build) in new (string, Func<ElementaryStream, byte[]>)[]
|
||||
{
|
||||
("MOV", es => TestVideos.Mov(es)),
|
||||
("MP4 a frammenti", es => TestVideos.FragmentedMp4(es)),
|
||||
("Matroska", es => TestVideos.Matroska(es)),
|
||||
("AVI (i parametri in ogni fotogramma chiave, come si scrive un AVI)", es => TestVideos.Avi(es.WithParameterSetsEverywhere())),
|
||||
})
|
||||
{
|
||||
var fixedPicture = Analyse(build(still));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, fixedPicture.Outcome, $"{name}: {Describe(fixedPicture)}");
|
||||
Assert.IsNotNull(fixedPicture.FrameAt, name);
|
||||
var moving = Analyse(build(pan));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, moving.Outcome, $"{name}: {Describe(moving)}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AVideoWithNoDurationIsNotAnalysable()
|
||||
{
|
||||
// Two samples at the same time, and headers that say zero: nothing tells how long the video is.
|
||||
var es = PcmVideos.Stream("pcm", 2, i => PcmVideos.Photo(24 + i));
|
||||
var track = new Mp4OutputTrack
|
||||
{
|
||||
IsVideo = true,
|
||||
Timescale = TestVideos.Timescale,
|
||||
Samples = [.. Enumerable.Range(0, 2).Select(i => new Mp4OutputSample(es.LengthPrefixed(i).Length, 0, 0, true))],
|
||||
WriteSample = (i, s) => s.Write(es.LengthPrefixed(i)),
|
||||
Width = es.Width,
|
||||
Height = es.Height,
|
||||
AvcConfiguration = es.AvcC,
|
||||
};
|
||||
using var output = new MemoryStream();
|
||||
Mp4Writer.Write(output, [track]);
|
||||
|
||||
var result = Analyse(output.ToArray());
|
||||
Assert.AreEqual(VideoAnalysisOutcome.NotAnalyzable, result.Outcome, Describe(result));
|
||||
Assert.AreEqual(VideoAnalysisNotes.DurationUnknown, result.Note);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ADamagedStreamIsUnreadableNeverStillFromOneFrame()
|
||||
{
|
||||
// The headers are whole, the pictures are cut to a few bytes, all but the first: one frame alone says nothing of
|
||||
// the video.
|
||||
var es = PcmVideos.Stream("pcm", 30, _ => PcmVideos.Photo(26));
|
||||
for (var i = 3; i < es.Count; i++)
|
||||
{
|
||||
es.Units[i] = [.. es.Units[i].Select(n => n[..Math.Min(n.Length, 6)])];
|
||||
}
|
||||
|
||||
var result = Analyse(TestVideos.Mp4(es));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.NotAnalyzable, result.Outcome, Describe(result));
|
||||
Assert.AreEqual(VideoAnalysisNotes.Unreadable, result.Note);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EveryThresholdIsTheOneAgreed()
|
||||
{
|
||||
// Answer 44 of Alberto (29 November 2026) and docs/decisioni.md: a change raises Algorithm, so that the videos
|
||||
// already analysed are known as of the older rule.
|
||||
Assert.AreEqual(
|
||||
(1, 7, 32, 32.0, 2.0, 12.0, 3.0, 0.05),
|
||||
(StillVideoAnalyzer.Algorithm, StillVideoAnalyzer.Samples, StillVideoAnalyzer.GridSize, StillVideoAnalyzer.DarkLevel,
|
||||
StillVideoAnalyzer.UniformSpread, StillVideoAnalyzer.BlockThreshold, StillVideoAnalyzer.MeanThreshold, StillVideoAnalyzer.AreaThreshold));
|
||||
}
|
||||
|
||||
private static StillVideoResult Analyse(byte[] video)
|
||||
{
|
||||
using var stream = new MemoryStream(video);
|
||||
|
||||
Reference in new issue
Block a user