E3: seconda revisione di rimuxaggio, spazio, impostazioni e zip
Le quattro osservazioni confermate della seconda revisione, ognuna con la sua prova (ciascuna cade sul codice di prima): - Rimuxaggio con fotogrammi B: l'MP4 misura la fine della presentazione in tempo di composizione, non con la somma delle durate di decodifica. Prima nascondeva gli ultimi fotogrammi mostrati (2 in un iPhone) e durava altrettanto meno in elst, tkhd e mvhd. Per le tracce senza scarti di composizione i byte restano gli stessi. - Conversione della libreria: il lavoro ricorda il file che l'ha messo in pausa per spazio e quanto serve al suo convertito. Finché il disco non ha posto anche per quello, non rilegge l'originale a ogni risveglio (anche quando lo spazio libero sta appena sopra la soglia). - Impostazioni dell'esportazione: formati, chiavi «dal» e coda del formato sostituito si salvano in una transazione sola; «Anche i N» dopo il salvataggio non dipende più dalla richiesta. Il gancio della libreria legge formati e chiavi «dal» in una lettura. Una scheda chiusa o un arresto non lasciano più un formato senza la sua chiave né «Non riuscito» che «Riprova» non tocca. - Zip dei fotogrammi: i tempi del blocco passano da un TimeProvider della BCL, e la prova del lettore lento non dipende più dal carico della macchina. Decisioni in docs/decisioni.md (28/11). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
958cb71cd6
commit
2efb408957
13 files changed
+459
-49
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Security.Cryptography;
|
||||
using Febe.Core.Codecs.Containers;
|
||||
|
||||
@@ -97,6 +98,62 @@ public sealed class Mp4RemuxerTests
|
||||
Assert.AreEqual(ShownFrames - 1, last.Sample);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheLastReorderedFramesStayShownInTheMp4()
|
||||
{
|
||||
// B frames, as iPhones and High profile encoders write them: the edit starts at the first composition offset
|
||||
// and shows the whole presentation (N frames). The MP4 must show as much, never 2 frames less.
|
||||
var es = ElementaryStream.Load("CABA3_SVA_B");
|
||||
var n = es.Count;
|
||||
Assert.IsTrue(Enumerable.Range(0, n).Any(i => es.Rank[i] < i), "the stream has reordered frames");
|
||||
var presentation = (long)n * TestVideos.FrameTicks;
|
||||
var mov = TestVideos.Mov(es, new MovOptions(VideoTrim: presentation));
|
||||
using var source = new MemoryStream(mov);
|
||||
var before = Read(source);
|
||||
Assert.IsGreaterThan(0L, before.Video!.EditMediaTime ?? 0, "the edit starts at the first composition offset");
|
||||
AssertAbout(presentation, before.Video.EditSegmentDuration, "the source shows all N frames");
|
||||
|
||||
Assert.AreEqual(RemuxRefusal.None, Mp4Remuxer.Check(source, "clip.mov", out var plan, CancellationToken.None));
|
||||
var mp4 = Remux(plan!, source);
|
||||
using var output = new MemoryStream(mp4);
|
||||
var after = Read(output);
|
||||
|
||||
Assert.AreEqual(before.Video.EditMediaTime, after.Video!.EditMediaTime);
|
||||
Assert.AreEqual(before.Video.EditSegmentDuration, after.Video.EditSegmentDuration, "the segment is the source's");
|
||||
AssertAbout(presentation, after.Video.EditSegmentDuration, "the MP4 shows all N frames");
|
||||
Assert.AreEqual(before.Duration, after.Duration);
|
||||
var shownMs = (long)Math.Ceiling(n * 1000.0 / 30);
|
||||
Assert.AreEqual((shownMs, shownMs), (HeaderDuration(mp4, "mvhd"u8), HeaderDuration(mp4, "tkhd"u8)), "mvhd and tkhd last N frames");
|
||||
Assert.AreEqual((HeaderDuration(mov, "mvhd"u8), HeaderDuration(mov, "tkhd"u8)), (HeaderDuration(mp4, "mvhd"u8), HeaderDuration(mp4, "tkhd"u8)));
|
||||
AssertSameSamples(before.Video, source, after.Video, output, "video");
|
||||
|
||||
// A frame «oltre la fine» is the one presented last, not one that decodes last.
|
||||
var lastShown = Enumerable.Range(0, n).MaxBy(i => es.Rank[i]);
|
||||
using var reader = Febe.Core.Library.VideoFrameReader.Open(output, out var info);
|
||||
Assert.IsTrue(info.Available);
|
||||
Assert.AreEqual(lastShown, reader.Locate([TimeSpan.FromHours(1)]).Single().Sample);
|
||||
}
|
||||
|
||||
/// <summary>A segment read back from the movie timescale (milliseconds, rounded up) is within a millisecond.</summary>
|
||||
private static void AssertAbout(long expected, long? actual, string what)
|
||||
{
|
||||
Assert.IsNotNull(actual, what);
|
||||
Assert.IsLessThanOrEqualTo(TestVideos.Timescale / 1000, Math.Abs(actual.Value - expected), $"{what}: {actual} for {expected}");
|
||||
}
|
||||
|
||||
/// <summary>The duration of the first <c>mvhd</c> or <c>tkhd</c> of a file (movie units), of either version.</summary>
|
||||
private static long HeaderDuration(byte[] file, ReadOnlySpan<byte> type)
|
||||
{
|
||||
var at = file.AsSpan().IndexOf(type);
|
||||
Assert.IsGreaterThan(0, at);
|
||||
var body = file.AsSpan(at + 4);
|
||||
var wide = body[0] == 1;
|
||||
var isTrack = type[0] == (byte)'t';
|
||||
// version and flags, the dates, then the timescale (mvhd) or the track id and a reserved word (tkhd).
|
||||
var offset = 4 + (wide ? 16 : 8) + (isTrack ? 8 : 4);
|
||||
return wide ? (long)BinaryPrimitives.ReadUInt64BigEndian(body[offset..]) : BinaryPrimitives.ReadUInt32BigEndian(body[offset..]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(44100, 0x6B)]
|
||||
[DataRow(32000, 0x6B)]
|
||||
|
||||
Reference in new issue
Block a user