WIP: contenitori, sonda dei metadati, fotogrammi e scrittore MP4 in casa; via ffmpeg e ffprobe (#58)

Lettori ISO BMFF (anche frammentato), Matroska/WebM e AVI; ContainerVideoMetadataProbe è la sonda predefinita; VideoFrameDecoder (H.264 in casa, BMP ruotato, riconoscimento dei video fermi) sostituisce VideoFrameExtractor; Mp4Writer con moov in testa. Tolti ffmpeg e ffprobe da Dockerfile, CI, script e prove. WIP perché la corsa completa di tests/Febe.Tests non era finita al momento del commit e l'ultima correzione (data qualsiasi nella lettura dei campioni) non è stata ricompilata né riprovata: la compilazione durante la corsa fallisce per DLL bloccate dalle prove in esecuzione.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 12:32:33 +01:00
1 parent 697de97ec3
commit 6ffcb1bb18
39 files changed
+4235 -469

No files matched your search

+19 -33
View File
@@ -121,55 +121,41 @@ public sealed class MediaReaderTests
}
[TestMethod]
public void AnMp4MadeByFfmpegCarriesItsCreationTime()
public void ARealMp4CarriesItsCreationTime()
{
using var temp = new TempFolder("mp4");
var path = temp.Combine("prova.mp4");
var created = new DateTimeOffset(2021, 3, 4, 5, 6, 7, TimeSpan.Zero);
if (!ImportTestFiles.TryMakeMp4WithFfmpeg(path, created))
{
Assert.Inconclusive("ffmpeg non è installato: la prova sulle intestazioni sintetiche copre il lettore.");
}
File.WriteAllBytes(path, ImportTestFiles.RealMp4(created));
Assert.AreEqual("video/mp4", MediaSniffer.DetectFile(path)?.ContentType);
var info = Mp4Reader.ReadFile(path, Now);
Assert.AreEqual(created, info?.CreatedAt);
Assert.AreEqual(64, info?.Width);
Assert.AreEqual(48, info?.Height);
Assert.IsTrue(info?.Duration > TimeSpan.FromMilliseconds(500));
Assert.AreEqual(ImportTestFiles.RealVideoSize, (info!.Width!.Value, info.Height!.Value));
Assert.IsTrue(info.Duration > TimeSpan.FromMilliseconds(500));
}
[TestMethod]
public async Task FfprobeIsAnOptionalExtra()
public async Task TheContainerProbeReadsWhatTheMp4ReaderDoesNot()
{
var parsed = FfprobeVideoMetadataProbe.Parse("""
{"streams":[{"codec_type":"audio"},{"codec_type":"video","width":1920,"height":1080,"tags":{"rotate":"90"}}],
"format":{"duration":"12.500000","tags":{"creation_time":"2020-08-09T10:11:12.000000Z"}}}
""");
Assert.AreEqual(new DateTimeOffset(2020, 8, 9, 10, 11, 12, TimeSpan.Zero), parsed?.CreatedAt);
Assert.AreEqual(TimeSpan.FromSeconds(12.5), parsed?.Duration);
Assert.AreEqual((1080, 1920), (parsed?.Width, parsed?.Height));
Assert.IsNull(FfprobeVideoMetadataProbe.Parse("non json"));
Assert.AreEqual(640, FfprobeVideoMetadataProbe.Parse("""{"streams":[{"codec_type":"video","width":640,"height":480,"tags":{"rotate":0}}],"format":{"tags":{"creation_time":5}}}""")?.Width, "Valori di tipo inatteso non fanno fallire la lettura.");
var probe = FfprobeVideoMetadataProbe.TryCreate();
if (probe is null)
{
Assert.Inconclusive("ffprobe non è installato.");
return;
}
using var temp = new TempFolder("ffprobe");
var path = temp.Combine("prova.mp4");
using var temp = new TempFolder("sonda");
var webm = temp.Combine("prova.webm");
var mp4 = temp.Combine("prova.mp4");
var created = new DateTimeOffset(2021, 3, 4, 5, 6, 7, TimeSpan.Zero);
if (!ImportTestFiles.TryMakeMp4WithFfmpeg(path, created))
File.WriteAllBytes(webm, ImportTestFiles.RealWebm(created));
File.WriteAllBytes(mp4, ImportTestFiles.RealMp4(created));
Assert.AreEqual("video/webm", MediaSniffer.DetectFile(webm)?.ContentType);
var probe = new ContainerVideoMetadataProbe();
foreach (var path in new[] { webm, mp4 })
{
Assert.Inconclusive("ffmpeg non è installato.");
var metadata = await probe.ProbeAsync(path);
Assert.AreEqual(created, metadata?.CreatedAt, path);
Assert.AreEqual(ImportTestFiles.RealVideoSize, (metadata!.Width!.Value, metadata.Height!.Value), path);
Assert.IsTrue(metadata.Duration > TimeSpan.FromMilliseconds(500), path);
}
var metadata = await probe.ProbeAsync(path);
Assert.AreEqual(created, metadata?.CreatedAt);
Assert.AreEqual(64, metadata?.Width);
Assert.IsNull(await probe.ProbeAsync(temp.Combine("non-esiste.webm")));
}
[TestMethod]