E4: analizzatore dei video fermi scritto in casa (algoritmo 1)

StillVideoAnalyzer sostituisce VideoFrameDecoder.AnalyseStillness, che
confrontava solo con il primo fotogramma (una dissolvenza dal nero
risultava in movimento) e diluiva un adesivo nella media.

- Sette fotogrammi esatti, uno per settimo del video, spostati sul
  fotogramma chiave vicino (VideoFrameReader.LocateNearKey, nuovo).
- Griglia 32x32 di blocchi; dissolvenze annullate quando i rapporti dei
  blocchi concordano; fotogrammi neri messi da parte solo all'inizio o
  alla fine.
- Fermo se ogni fotogramma differisce dall'immagine ferma mediana per una
  media di al massimo 3 e per non più del 5 % dei blocchi (risposta 47:
  un piccolo adesivo o una scritta che si muove restano fermi; nota
  SmallMotion).
- Tutto nero o di un solo colore: Non analizzabile (risposta 42); anche
  codec non decodificato, file illeggibile, tempo oltre il limite.
- Il fotogramma scelto è il più nitido (varianza del laplaciano), mai
  uno scuro, con l'istante in millisecondi come le copie dei fotogrammi.

Prove su video costruiti dalle prove (PcmVideos) e sui flussi di
conformità; le prove della vecchia analisi sono spostate qui.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-29 14:44:32 +01:00
1 parent 0cd842a518
commit e61da9be23
10 files changed
+1231 -227

No files matched your search

@@ -7,7 +7,7 @@ using Febe.Tests.Support;
namespace Febe.Tests.Codecs.Containers;
/// <summary>The in-house frame decoder for thumbnails, and the recognition of videos of a still picture.</summary>
/// <summary>The in-house frame decoder for thumbnails (still videos: <see cref="StillVideoAnalyzerTests"/>).</summary>
[TestClass]
public sealed class VideoFrameDecoderTests
{
@@ -144,32 +144,6 @@ public sealed class VideoFrameDecoderTests
CollectionAssert.AreEqual(rgb[..3], rgb[3..6], "la riga in alto è uniforme");
}
[TestMethod]
public async Task AVideoOfAStillPictureIsRecognised()
{
var es = ElementaryStream.Load("BA1_Sony_D");
using var temp = new TempFolder("fermo");
var still = TestVideos.Write(temp, "fermo.mp4", TestVideos.Mp4(es.FirstPictureRepeated(90)));
var result = await VideoFrameDecoder.Instance.AnalyseStillnessAsync(still);
Assert.IsNotNull(result);
Assert.IsTrue(result.IsStill);
Assert.IsTrue(result.SampledFrames >= 2);
Assert.AreEqual(0, result.Difference);
}
[TestMethod]
[DataRow("CABA3_SVA_B")]
[DataRow("FRExt1_Panasonic_D")]
public async Task AVideoThatMovesIsNotStill(string name)
{
var es = ElementaryStream.Load(name);
using var temp = new TempFolder("movimento");
var path = TestVideos.Write(temp, "video.mp4", TestVideos.Mp4(es));
var result = await VideoFrameDecoder.Instance.AnalyseStillnessAsync(path);
Assert.IsNotNull(result);
Assert.IsFalse(result.IsStill, $"differenza {result.Difference}");
}
[TestMethod]
public async Task AFrameFarFromWhereDecodingCanStartGivesWayToTheFrameThere()
{
@@ -182,7 +156,6 @@ public sealed class VideoFrameDecoderTests
var decoder = new VideoFrameDecoder(VideoFrameDecoder.DefaultBudget, maxRun: 5);
var image = await decoder.DecodeFrameAsync(path, TimeSpan.FromSeconds(1));
CollectionAssert.AreEqual(VideoFrameDecoder.ToImage(DecodedFrame(es, 0), 0, 0).Rgb, image!.Rgb);
Assert.IsNotNull(await decoder.AnalyseStillnessAsync(path), "anche l'analisi resta limitata e risponde");
}
[TestMethod]
@@ -193,7 +166,6 @@ public sealed class VideoFrameDecoderTests
var path = TestVideos.Write(temp, "video.mp4", TestVideos.Mp4(es));
var late = new VideoFrameDecoder(TimeSpan.Zero, maxRun: 300);
Assert.IsNull(await late.DecodeFrameAsync(path, TimeSpan.FromSeconds(1)), "oltre il tempo concesso: nessun fotogramma");
Assert.IsNull(await late.AnalyseStillnessAsync(path));
// A cancellation asked by the caller is not a missing frame: it stays a cancellation.
using var cancelled = new CancellationTokenSource();
@@ -242,7 +214,6 @@ public sealed class VideoFrameDecoderTests
using var temp = new TempFolder("illeggibile");
var junk = TestVideos.Write(temp, "rotto.mp4", [0, 0, 0, 16, .. "ftypisom"u8, 0, 0, 0, 0, 0, 0, 0, 9, .. "mdat"u8, 1]);
Assert.IsNull(await VideoFrameDecoder.Instance.ExtractImageAsync(junk));
Assert.IsNull(await VideoFrameDecoder.Instance.AnalyseStillnessAsync(junk));
Assert.IsNull(await VideoFrameDecoder.Instance.ExtractImageAsync(temp.Combine("non-esiste.mkv")));
}