E3: prove di codec, rimuxaggio, fotogrammi, copie e conversione
Le prove del nucleo della tappa E3 (WP6a), con i media costruiti dalle prove: il controllo delle foto (stesso formato, HEIC/AVIF/raw, animate, CMYK e oltre 8 bit, budget di pixel), metadati nei blocchi giusti e perdite annotate, pixel identici in WEBP senza perdita; il rimuxaggio da MOV (nuovo TestVideos.Mov) e Matroska a MP4 con campioni, date, rotazione, lingua ed edit; i fotogrammi H.264 e H.265 all'istante, ogni k secondi e N in tutto; i suffissi protetti dal taglio a 240; le copie convertite, com'è con nota, adozione, «già copiato» in ogni forma, «Copia di nuovo» esatta, spazio sul convertito, fotogrammi nella cartella delle copie (FrameOnly, una copia per campione, lotti su più pagine, tetto); la conversione della libreria (perdite, rimuxaggio, doppioni, importazione delle copie convertite). Servono a fissare il comportamento di E3 prima dell'unione. Nessun codice del prodotto cambia; un limite trovato (istanti a meno di 1 ms in «N in tutto») è annotato per Alberto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d06b587806
commit
f5e12c5d74
9 files changed
+1408
-4
No files matched your search
@@ -140,6 +140,103 @@ public sealed class VideoFramesTests
|
||||
Assert.AreEqual(RemuxRefusal.AlreadyMp4, Mp4Remuxer.Check(mp4, "video.mp4", out _, CancellationToken.None));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HevcFramesWork()
|
||||
{
|
||||
var es = ElementaryStream.LoadHevc("INITQP_A_Sony_1");
|
||||
using var stream = new MemoryStream(TestVideos.Mp4(es));
|
||||
using var reader = VideoFrameReader.Open(stream, out var info);
|
||||
Assert.IsTrue(info.Available);
|
||||
|
||||
var target = reader.Locate([TimeSpan.FromMilliseconds(1010)]).Single();
|
||||
Assert.AreEqual(TimeSpan.FromSeconds(1), target.Actual);
|
||||
using var frame = reader.Decode([target], CancellationToken.None).Single();
|
||||
|
||||
var shown = new List<Febe.Core.Codecs.H265.H265Frame>();
|
||||
var decoder = new Febe.Core.Codecs.H265.H265Decoder();
|
||||
decoder.FrameOutput += shown.Add;
|
||||
decoder.DecodeAnnexB(File.ReadAllBytes(Codecs.H265.H265ConformanceStream.Load(es.Name).BitstreamPath));
|
||||
var expected = VideoFrameDecoder.ToImage(shown[30], 0, 0);
|
||||
var pixels = frame.Image.ToArray();
|
||||
for (var i = 0; i < expected.Width * expected.Height; i++)
|
||||
{
|
||||
Assert.AreEqual((expected.Rgb[i * 3], expected.Rgb[(i * 3) + 1], expected.Rgb[(i * 3) + 2]), (pixels[i * 4], pixels[(i * 4) + 1], pixels[(i * 4) + 2]), $"pixel {i}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheInstantFollowsTheEditList()
|
||||
{
|
||||
// The video starts half a second into the presentation (an empty edit): the browser shows nothing of it before.
|
||||
var es = ElementaryStream.Load("BA1_Sony_D");
|
||||
using var stream = new MemoryStream(TestVideos.Mov(es, new MovOptions(VideoEmptyEdit: TestVideos.Timescale / 2)));
|
||||
using var reader = VideoFrameReader.Open(stream, out var info);
|
||||
Assert.IsTrue(info.Available);
|
||||
|
||||
var targets = reader.Locate([TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(510), TimeSpan.FromMilliseconds(1010)]);
|
||||
|
||||
Assert.AreEqual((Array.IndexOf(es.Rank, 0), TimeSpan.FromMilliseconds(500)), (targets[0].Sample, targets[0].Actual), "before the start: the first frame");
|
||||
Assert.AreEqual(TimeSpan.FromMilliseconds(500), targets[1].Actual);
|
||||
Assert.AreEqual((Array.IndexOf(es.Rank, 15), TimeSpan.FromSeconds(1)), (targets[2].Sample, targets[2].Actual), "frame 15 is shown at 0.5 + 0.5 s");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EveryKSecondsAndNInAllFindTheFramesShown()
|
||||
{
|
||||
var es = ElementaryStream.Load("BA1_Sony_D");
|
||||
using var stream = new MemoryStream(TestVideos.Mp4(es));
|
||||
using var reader = VideoFrameReader.Open(stream, out var info);
|
||||
|
||||
var every = reader.Locate(ExportFrames.Every(info.Duration, TimeSpan.FromMilliseconds(250)));
|
||||
Assert.AreEqual(TimeSpan.Zero, every[0].Actual);
|
||||
foreach (var t in every)
|
||||
{
|
||||
Assert.IsLessThanOrEqualTo(t.Requested, t.Actual, "the frame shown at an instant started at or before it");
|
||||
Assert.IsLessThan(TimeSpan.FromMilliseconds(34), t.Requested - t.Actual, "and less than a frame before");
|
||||
}
|
||||
|
||||
var spread = reader.Locate(ExportFrames.Spread(info.Duration, 4));
|
||||
Assert.HasCount(4, spread.Select(t => t.Sample).Distinct().ToList(), "four different frames");
|
||||
var frames = reader.Decode(spread, CancellationToken.None).ToList();
|
||||
try
|
||||
{
|
||||
CollectionAssert.AreEquivalent(new[] { 0, 1, 2, 3 }, frames.Select(f => f.Index).ToArray(), "one picture per target");
|
||||
}
|
||||
finally
|
||||
{
|
||||
frames.ForEach(f => f.Dispose());
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AnUnsupportedCodecSaysNotAvailable()
|
||||
{
|
||||
var es = ElementaryStream.Load("BA1_Sony_D");
|
||||
using var stream = new MemoryStream(TestVideos.Matroska(es, webm: true, codecId: "V_VP9"));
|
||||
using var reader = VideoFrameReader.Open(stream, out var info);
|
||||
|
||||
Assert.IsFalse(info.Available);
|
||||
Assert.AreEqual(VideoFrameReader.NotAvailableMessage, info.Unavailable);
|
||||
Assert.IsEmpty(reader.Locate([TimeSpan.Zero]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ADamagedStreamGivesNoPicture()
|
||||
{
|
||||
// The container is fine, the pictures are noise: no frame comes out, nothing throws.
|
||||
var es = ElementaryStream.Load("BA1_Sony_D");
|
||||
var mp4 = TestVideos.Mp4(es);
|
||||
var mdat = mp4.AsSpan().IndexOf("mdat"u8) + 4;
|
||||
new Random(5).NextBytes(mp4.AsSpan(mdat + 64));
|
||||
using var stream = new MemoryStream(mp4);
|
||||
using var reader = VideoFrameReader.Open(stream, out var info);
|
||||
Assert.IsTrue(info.Available, "the tables are readable");
|
||||
|
||||
var frames = reader.Decode(reader.Locate([TimeSpan.FromMilliseconds(900)]), CancellationToken.None).ToList();
|
||||
frames.ForEach(f => f.Dispose());
|
||||
Assert.IsEmpty(frames);
|
||||
}
|
||||
|
||||
/// <summary>The frame shown at position <paramref name="rank"/>, decoded straight from the stream.</summary>
|
||||
private static H264Frame ShownFrame(ElementaryStream es, int rank)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user