Correzioni dopo la revisione del decodificatore H.264, dei lettori FLV e della CI (#58)
- CI: le due prove MVC di FeaturesStillToDo finivano con «da verificare: …», che riepilogo-prove.sh contava come saltate: ogni verifica del ramo sarebbe fallita. Ora cominciano con «da fare: », e lo script esenta solo le inconclusive di FeaturesStillToDo il cui motivo comincia con «da fare: » subito dopo la cornice di MSTest (prima bastava la parola in qualunque punto di qualunque prova). PipelineTests prova lo script su .trx con le cornici inglese e italiana; processo.md, Sviluppo.md e verifica.yml descrivono la categoria. - Partizionamento dei dati: una partizione B o C sperduta (partizione A persa) sovrascriveva il buffer delle partizioni della slice in attesa. Ora slice_id e redundant_pic_cnt si leggono prima di copiare, e contano l'ordine A, B, C. - MVC: le viste tengono insieme al massimo 2 × MaxDpbMbs di immagini, e il decodificatore di una vista nuova si tiene solo dopo il controllo dell'SPS di sottoinsieme; Wanted vale per ogni vista. - FLV: senza durata nei metadati la durata arriva alla fine dell'ultimo fotogramma, come per MPEG; «solo audio» solo con una prova vera nella testa (un onMetaData grande non fa più scartare un video). - Flussi di conformità: tolti i 48 readme e schede di terzi (decisione di Alberto: nel repository solo flussi e MD5). - Prove nuove: partizioni A perse, limite delle viste e Wanted in MVC, unità di estensione troncate, flussi rovinati 4:2:2, 10 bit, 4:0:0, SVC e MVC. - Commenti sulla provenienza che citano i file di ricostruzione ufficiali e §8.7 invece del decodificatore di riferimento; commento di ImportEnvironment.VideoProbe aggiornato; righe nuove in decisioni.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c8b228333
commit
cdc3cc11b9
71 files changed
+668
-2223
No files matched your search
@@ -25,6 +25,9 @@ public static class FlvReader
|
||||
|
||||
private const long HeadBytes = 32L * 1024 * 1024;
|
||||
|
||||
/// <summary>Audio without a single video tag that, at the start of a file, proves it has no video.</summary>
|
||||
public const int AudioProofMilliseconds = 5000;
|
||||
|
||||
/// <summary>Tags looked at back from the end of the file for its last time.</summary>
|
||||
private const int TailTags = 64;
|
||||
|
||||
@@ -37,8 +40,11 @@ public static class FlvReader
|
||||
start.Length >= 9 && start[..3].SequenceEqual("FLV"u8) && start[3] == 1 && BinaryPrimitives.ReadUInt32BigEndian(start[5..]) >= 9;
|
||||
|
||||
/// <summary>
|
||||
/// True only when the first bytes of a file prove an FLV without video: the header says audio and no video, and no
|
||||
/// video tag is among the tags in <paramref name="head"/>.
|
||||
/// True only when the first bytes of a file prove an FLV without video: the header says audio and no video, the tags
|
||||
/// in <paramref name="head"/> hold at least one whole audio tag and no video tag, and they reach far enough to rule
|
||||
/// video out — the exact end of <paramref name="head"/> (it is the whole file), <see cref="AudioProofMilliseconds"/>
|
||||
/// of audio, or <see cref="HeadTags"/> tags. Anything less (a head that ends inside a large onMetaData, a few tags, a
|
||||
/// tag that is not one) proves nothing, and the file stays a video: header flags are often wrong.
|
||||
/// </summary>
|
||||
public static bool IsAudioOnly(ReadOnlySpan<byte> head)
|
||||
{
|
||||
@@ -48,18 +54,41 @@ public static class FlvReader
|
||||
}
|
||||
|
||||
var position = (long)BinaryPrimitives.ReadUInt32BigEndian(head[5..]) + 4;
|
||||
for (var tags = 0; position + 11 <= head.Length && tags < HeadTags; tags++)
|
||||
long? firstAudio = null;
|
||||
long lastAudio = 0;
|
||||
var tags = 0;
|
||||
while (position + 11 <= head.Length && tags < HeadTags)
|
||||
{
|
||||
var type = head[(int)position] & 0x1F;
|
||||
var tag = head.Slice((int)position, 11);
|
||||
var type = tag[0] & 0x1F;
|
||||
if (type == 9)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
position += 11 + ((head[(int)position + 1] << 16) | (head[(int)position + 2] << 8) | head[(int)position + 3]) + 4;
|
||||
if ((tag[0] & 0xC0) != 0 || type is not (8 or 18))
|
||||
{
|
||||
return false; // not a tag: what follows proves nothing
|
||||
}
|
||||
|
||||
var next = position + 11 + ((tag[1] << 16) | (tag[2] << 8) | tag[3]) + 4;
|
||||
if (next > head.Length)
|
||||
{
|
||||
break; // a tag cut by the end of the head is not seen whole
|
||||
}
|
||||
|
||||
if (type == 8)
|
||||
{
|
||||
var time = (long)(int)((uint)(tag[7] << 24) | (uint)(tag[4] << 16) | (uint)(tag[5] << 8) | tag[6]);
|
||||
firstAudio ??= time;
|
||||
lastAudio = time;
|
||||
}
|
||||
|
||||
tags++;
|
||||
position = next;
|
||||
}
|
||||
|
||||
return true;
|
||||
return firstAudio is { } first && (position == head.Length || tags >= HeadTags || lastAudio - first >= AudioProofMilliseconds);
|
||||
}
|
||||
|
||||
/// <summary>Reads a seekable stream from its start.</summary>
|
||||
@@ -137,9 +166,9 @@ public static class FlvReader
|
||||
}
|
||||
}
|
||||
|
||||
if (state.MetadataSeconds is null && state.FirstTime is { } first && LastTime(stream, dataOffset + 4L) is { } last && last > first)
|
||||
if (state.MetadataSeconds is null && state.FirstTime is { } first && EndTime(stream, dataOffset + 4L) is { } end && end > first)
|
||||
{
|
||||
state.LastSeconds = (last - first) / 1000.0;
|
||||
state.LastSeconds = (end - first) / 1000.0;
|
||||
}
|
||||
|
||||
return state.Build();
|
||||
@@ -281,11 +310,18 @@ public static class FlvReader
|
||||
}
|
||||
|
||||
/// <summary>The time of the last audio or video tag, walking back from the end with the PreviousTagSize fields.</summary>
|
||||
private static long? LastTime(Stream stream, long firstTag)
|
||||
/// <summary>
|
||||
/// The time the file ends, in milliseconds, from the tags at its end (walked back through their PreviousTagSize): the
|
||||
/// last video tag plus the interval from the video tag before it, that is one frame, as the MPEG reader adds one
|
||||
/// frame to the last time of its video; the same for audio when the end of the file holds no video tag. Null when
|
||||
/// the end of the file has no tag to trust.
|
||||
/// </summary>
|
||||
private static long? EndTime(Stream stream, long firstTag)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[11];
|
||||
var end = stream.Length;
|
||||
for (var step = 0; step < TailTags && end - 4 >= firstTag; step++)
|
||||
long? lastVideo = null, previousVideo = null, lastAudio = null, previousAudio = null;
|
||||
for (var step = 0; step < TailTags && end - 4 >= firstTag && previousVideo is null; step++)
|
||||
{
|
||||
stream.Position = end - 4;
|
||||
stream.ReadExactly(buffer[..4]);
|
||||
@@ -293,7 +329,7 @@ public static class FlvReader
|
||||
var start = end - 4 - previous;
|
||||
if (previous < 11 || start < firstTag)
|
||||
{
|
||||
return null; // no PreviousTagSize to trust (a file cut short ends inside a tag)
|
||||
break; // no PreviousTagSize to trust (a file cut short ends inside a tag)
|
||||
}
|
||||
|
||||
stream.Position = start;
|
||||
@@ -301,18 +337,40 @@ public static class FlvReader
|
||||
var size = (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
|
||||
if (size + 11 != previous || (buffer[0] & 0xC0) != 0)
|
||||
{
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((buffer[0] & 0x1F) is 8 or 9)
|
||||
var time = (long)(int)((uint)(buffer[7] << 24) | (uint)(buffer[4] << 16) | (uint)(buffer[5] << 8) | buffer[6]);
|
||||
switch (buffer[0] & 0x1F)
|
||||
{
|
||||
return (int)((uint)(buffer[7] << 24) | (uint)(buffer[4] << 16) | (uint)(buffer[5] << 8) | buffer[6]);
|
||||
case 9:
|
||||
Note(ref lastVideo, ref previousVideo, time);
|
||||
break;
|
||||
case 8:
|
||||
Note(ref lastAudio, ref previousAudio, time);
|
||||
break;
|
||||
}
|
||||
|
||||
end = start;
|
||||
}
|
||||
|
||||
return null;
|
||||
return lastVideo is { } video ? video + (video - (previousVideo ?? video))
|
||||
: lastAudio is { } audio ? audio + (audio - (previousAudio ?? audio))
|
||||
: null;
|
||||
|
||||
// The first time seen walking back is the last of the track, the first earlier one the tag before it (a tag at the
|
||||
// same time, such as the end of an AVC sequence, is no frame of its own).
|
||||
static void Note(ref long? last, ref long? before, long time)
|
||||
{
|
||||
if (last is null)
|
||||
{
|
||||
last = time;
|
||||
}
|
||||
else if (before is null && time < last)
|
||||
{
|
||||
before = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] Read(Stream stream, long offset, int count)
|
||||
|
||||
Reference in new issue
Block a user