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
@@ -308,6 +308,66 @@ internal static class TestVideos
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A QuickTime file (major brand <c>qt </c>, as phones write MOV) of the stream and, with <see cref="MovOptions.Audio"/>,
|
||||
/// an AAC track (or MP3) of fixed frames; with the options of a camera: track languages, rotation, both dates, the
|
||||
/// AAC priming hidden by an edit, a delayed start (an empty edit) and a second audio track that the MP4 drops.
|
||||
/// </summary>
|
||||
public static byte[] Mov(ElementaryStream es, MovOptions? options = null)
|
||||
{
|
||||
var o = options ?? new MovOptions();
|
||||
var samples = new List<Mp4OutputSample>();
|
||||
var data = new List<byte[]>();
|
||||
for (var i = 0; i < es.Count; i++)
|
||||
{
|
||||
var bytes = es.LengthPrefixed(i);
|
||||
data.Add(bytes);
|
||||
samples.Add(new Mp4OutputSample(bytes.Length, (long)i * FrameTicks, (long)es.Rank[i] * FrameTicks, es.Key[i]));
|
||||
}
|
||||
|
||||
var tracks = new List<Mp4OutputTrack>
|
||||
{
|
||||
new()
|
||||
{
|
||||
IsVideo = true,
|
||||
Timescale = Timescale,
|
||||
Samples = samples,
|
||||
WriteSample = (i, s) => s.Write(data[i]),
|
||||
Width = es.Width,
|
||||
Height = es.Height,
|
||||
Rotation = o.Rotation,
|
||||
AvcConfiguration = es.Hevc ? null : es.AvcC,
|
||||
HevcConfiguration = es.Hevc ? es.AvcC : null,
|
||||
Language = o.Language,
|
||||
EmptyEditDuration = o.VideoEmptyEdit,
|
||||
},
|
||||
};
|
||||
for (var track = 0; track < (o.Audio ? 1 : 0) + o.ExtraAudioTracks; track++)
|
||||
{
|
||||
var frames = (int)Math.Ceiling(es.Count / 30.0 * 44100 / 1024) + (o.AudioPriming > 0 ? 1 : 0);
|
||||
var payload = new byte[] { 0x21, 0x10, 0x04, 0x60, 0x8C, 0x1C, (byte)track };
|
||||
tracks.Add(new Mp4OutputTrack
|
||||
{
|
||||
IsVideo = false,
|
||||
Timescale = 44100,
|
||||
Samples = [.. Enumerable.Range(0, frames).Select(i => new Mp4OutputSample(payload.Length, i * 1024L, i * 1024L, true))],
|
||||
WriteSample = (_, s) => s.Write(payload),
|
||||
AacConfiguration = o.Mp3 ? null : [0x12, 0x10], // AAC LC, 44.1 kHz, stereo
|
||||
IsMp3 = o.Mp3,
|
||||
SampleRate = 44100,
|
||||
Channels = 2,
|
||||
Language = o.Language,
|
||||
EditMediaTime = o.AudioPriming > 0 ? o.AudioPriming : null,
|
||||
});
|
||||
}
|
||||
|
||||
using var output = new MemoryStream();
|
||||
Mp4Writer.Prepare(tracks, new Mp4MovieInfo(o.Created, o.Modified)).WriteTo(output);
|
||||
var file = output.ToArray();
|
||||
"qt "u8.CopyTo(file.AsSpan(8)); // the major brand of ftyp
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A fragmented MP4 (empty sample tables in moov, then moof+mdat pairs of <paramref name="perFragment"/> frames).
|
||||
/// With <paramref name="defaults"/> the sample durations come from <c>trex</c>, each fragment has two runs that
|
||||
@@ -400,7 +460,7 @@ internal static class TestVideos
|
||||
/// A Matroska file with one video track of SimpleBlocks, in a single cluster; block times are in ticks of
|
||||
/// <paramref name="timecodeScale"/> nanoseconds (milliseconds by default).
|
||||
/// </summary>
|
||||
public static byte[] Matroska(ElementaryStream es, DateTimeOffset? created = null, bool webm = false, uint timecodeScale = 1_000_000)
|
||||
public static byte[] Matroska(ElementaryStream es, DateTimeOffset? created = null, bool webm = false, uint timecodeScale = 1_000_000, string? codecId = null)
|
||||
{
|
||||
var shift = 0;
|
||||
for (var i = 0; i < es.Count; i++)
|
||||
@@ -422,7 +482,7 @@ internal static class TestVideos
|
||||
|
||||
var video = Element(0xE0, Element(0xB0, U16((ushort)es.Width)), Element(0xBA, U16((ushort)es.Height)));
|
||||
var track = Element(0xAE, Element(0xD7, [1]), Element(0x73C5, [7]), Element(0x83, [1]),
|
||||
Element(0x86, es.Hevc ? "V_MPEGH/ISO/HEVC"u8.ToArray() : "V_MPEG4/ISO/AVC"u8.ToArray()), Element(0x63A2, es.AvcC), video);
|
||||
Element(0x86, codecId is not null ? Encoding.ASCII.GetBytes(codecId) : es.Hevc ? "V_MPEGH/ISO/HEVC"u8.ToArray() : "V_MPEG4/ISO/AVC"u8.ToArray()), Element(0x63A2, es.AvcC), video);
|
||||
var blocks = new List<byte[]> { Element(0xE7, [0]) };
|
||||
for (var i = 0; i < es.Count; i++)
|
||||
{
|
||||
@@ -558,3 +618,19 @@ internal static class TestVideos
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>What <see cref="TestVideos.Mov"/> puts in a QuickTime file.</summary>
|
||||
/// <param name="Audio">One audio track (AAC unless <paramref name="Mp3"/>).</param>
|
||||
/// <param name="ExtraAudioTracks">Further audio tracks (an MP4 of Febe keeps one).</param>
|
||||
/// <param name="AudioPriming">Samples of AAC priming hidden by the audio edit (media time of the edit); 0: no edit.</param>
|
||||
/// <param name="VideoEmptyEdit">Ticks (of 30000 a second) before the video starts: an empty edit.</param>
|
||||
internal sealed record MovOptions(
|
||||
bool Audio = false,
|
||||
bool Mp3 = false,
|
||||
int ExtraAudioTracks = 0,
|
||||
string? Language = null,
|
||||
int Rotation = 0,
|
||||
DateTimeOffset? Created = null,
|
||||
DateTimeOffset? Modified = null,
|
||||
long AudioPriming = 0,
|
||||
long VideoEmptyEdit = 0);
|
||||
Reference in new issue
Block a user