Decodificatore HEVC, seconda parte: predizione inter, tutti i flussi Main e Main 10 coincidono (#58)

La predizione inter scritta dalla norma ITU-T H.265 (§8.3.4, §8.5.3): liste di
riferimento con le modifiche, merge con candidati spaziali, temporale,
bi-predittivi combinati e nulli e livello di merge parallelo, AMVP con la scala
per distanza di POC, TMVP sull'immagine co-locata, interpolazione a 8 prese per
la luma e 4 per il croma, predizione pesata di base ed esplicita. Il deblocking
prende l'intensità 1 anche dal moto; ogni immagine conserva il moto dei blocchi
4x4, la slice di ogni CTB e le liste delle sue slice per chi la usa come
co-locata. Un riferimento mancante diventa un'immagine grigia fuori dal DPB.
I filtri d'interpolazione usano i vettori della BCL (Vector128).

Perché: senza inter nessun video HEVC reale si decodifica. Ora i 136 flussi
Main, Main 10 e Main Still Picture della serie ITU-T H.265.1 danno esattamente
il YUV ufficiale e ogni immagine il suo hash SEI; questo conferma anche il
numero di fotogrammi e gli MD5 scelti per i flussi senza YUV. Restano
inconcludenti solo i 10 flussi RExt, in attesa della decisione di Alberto.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 16:18:32 +01:00
1 parent f77b5e4db6
commit d5e1282261
10 files changed
+1219 -125

No files matched your search

@@ -1,9 +1,10 @@
# Flussi di conformità H.265 (HEVC)
Questi flussi proveranno il decodificatore HEVC scritto in casa, che serve per i video HEVC e per le foto HEIC (profilo
Main Still Picture). Il decodificatore **non c'è ancora**: le prove `H265ConformanceTests.FramesMatchTheReference`
sono tutte inconcludenti finché non c'è, e lo restano per i flussi RExt finché Alberto non decide se servono. Già oggi
si controllano i dati di riferimento e il lettore degli hash delle immagini decodificate (vedi sotto).
Questi flussi provano il decodificatore HEVC scritto in casa (`src/Febe.Core/Codecs/H265`), che serve per i video HEVC
e per le foto HEIC (profilo Main Still Picture). Tutti i 136 flussi Main, Main 10 e Main Still Picture danno esattamente
i fotogrammi del YUV ufficiale (`H265ConformanceTests.FramesMatchTheReference`), e ogni immagine decodificata coincide
con l'hash SEI del suo codificatore dove il flusso lo porta (`H265DecoderTests.EveryPictureMatchesItsHash`). Le prove
dei flussi RExt restano inconcludenti finché Alberto non decide se servono.
## Provenienza
@@ -72,7 +73,8 @@ C.5.2.3 (riordino, latenza, buffer pieno, `pic_output_flag`, RASL saltati dopo u
sequenza, `no_output_of_prior_pics_flag`). Il conto coincide con i 15 YUV ufficiali e con il `readme` di
`BUMPING_A_ericsson_1`, che elenca le 17 immagini che non escono. Per `NoOutPrior_A_Qualcomm_1` (40),
`NoOutPrior_B_Qualcomm_1` (47) e `RAP_B_Bossen_2` (80), dove un IRAP scarta 3 immagini non ancora uscite, il numero è
solo calcolato: lo confermerà il decodificatore. Anche `tutto` per i flussi senza YUV sarà verificato solo allora.
stato prima calcolato; il decodificatore l'ha poi confermato, come `tutto` di ogni flusso senza YUV: i fotogrammi
decodificati hanno esattamente quell'MD5.
## Che cosa copre ciascun flusso (Main, Main 10, Main Still Picture)
@@ -290,9 +292,7 @@ Le estensioni multistrato e 3D (MV-HEVC, SHVC, SCC) non sono nemmeno state guard
## Che cosa non è verificato
- Il numero di fotogrammi e `tutto` dei flussi senza YUV ufficiale: vengono dalla simulazione dell'uscita e dal file
MD5 dello zip, e li confermerà solo il decodificatore. In particolare `NoOutPrior_A_Qualcomm_1`,
`NoOutPrior_B_Qualcomm_1` e `RAP_B_Bossen_2`.
- Quale dei due MD5 di uno zip sia quello del YUV, per i flussi senza YUV (la regola sopra).
- La disposizione a 16 bit di `TSUNEQBD_A_MAIN10_Technicolor_2` (10 e 9 bit): è la stessa di ogni flusso oltre gli 8 bit,
ma non c'è un YUV ufficiale per controllarla.
- Il numero di fotogrammi e `tutto` dei flussi senza YUV ufficiale, quale dei due MD5 di uno zip sia quello del YUV e
la disposizione a 16 bit di `TSUNEQBD_A_MAIN10_Technicolor_2` (10 e 9 bit) erano scelte nostre: il decodificatore le
ha confermate tutte: i suoi fotogrammi, in quel numero e in quella disposizione, hanno esattamente l'MD5 ufficiale
dello zip, che non può coincidere per caso.
@@ -4,21 +4,14 @@ using Febe.Core.Codecs.H265;
namespace Febe.Tests.Codecs.H265;
/// <summary>
/// The streams of the ITU-T H.265.1 conformance set in Media/H265/Conformita (see LEGGIMI.md there). The decoder has no
/// inter prediction yet: the streams with only I slices must match their YUV exactly, the others are inconclusive (their
/// intra pictures are checked in <see cref="H265DecoderTests"/>), and the range extension streams (4:0:0, 4:2:2,
/// 4:4:4, 12 bits, RExt tools) stay inconclusive until Alberto says whether «HEVC» covers them.
/// The streams of the ITU-T H.265.1 conformance set in Media/H265/Conformita (see LEGGIMI.md there). Every Main, Main 10
/// and Main Still Picture stream must give exactly the frames of its official YUV (the MD5 of each frame where the YUV
/// came with the stream, of the whole YUV for all); the range extension streams (4:0:0, 4:2:2, 4:4:4, 12 bits, RExt
/// tools) stay inconclusive until Alberto says whether «HEVC» covers them.
/// </summary>
[TestClass]
public sealed class H265ConformanceTests
{
/// <summary>Streams the decoder is expected to reproduce exactly: those of Main, Main 10 and Main Still Picture made only of I slices.</summary>
private static readonly HashSet<string> s_supported =
[
"IPRED_A_docomo_2", "IPRED_B_Nokia_3", "IPRED_C_Mitsubishi_3", "ipcm_A_NEC_3", "ipcm_B_NEC_3", "ipcm_C_NEC_3",
"ipcm_D_NEC_3", "ipcm_E_NEC_2", "MAXBINS_A_TI_5", "POC_A_Bossen_3", "SAO_H_Parabola_1", "VPSSPSPPS_A_MainConcept_1",
];
public static IEnumerable<object[]> Streams => H265ConformanceStream.Names().Select(n => new object[] { n });
[TestMethod]
@@ -31,11 +24,6 @@ public sealed class H265ConformanceTests
Assert.Inconclusive($"{name}: estensione di formato (RExt, {stream.Chroma} a {stream.LumaBitDepth} bit), da decodificare solo se Alberto la vuole.");
}
if (!s_supported.Contains(name))
{
Assert.Inconclusive($"{name}: ha slice P o B, e la predizione inter HEVC non è ancora scritta.");
}
var frames = new List<byte[]>();
var decoder = new H265Decoder();
decoder.FrameOutput += frame => frames.Add(frame.ToYuvFile());
+31 -27
View File
@@ -4,9 +4,9 @@ using Febe.Core.Codecs.H265;
namespace Febe.Tests.Codecs.H265;
/// <summary>
/// The HEVC decoder beyond the intra-only streams of <see cref="H265ConformanceTests"/>: every picture made only of I
/// slices, in every Main and Main 10 stream, against the MD5 its encoder wrote in the bitstream; the syntax of the P and
/// B slices read to the end of every slice; length-prefixed samples; damaged streams.
/// The HEVC decoder beyond the whole frames of <see cref="H265ConformanceTests"/>: every decoded picture of every Main and
/// Main 10 stream, in decoding order and before cropping, against the hash its encoder wrote in the bitstream (so a wrong
/// picture is found where it first goes wrong, also when it is never output); length-prefixed samples; damaged streams.
/// </summary>
[TestClass]
public sealed class H265DecoderTests
@@ -17,17 +17,14 @@ public sealed class H265DecoderTests
[TestMethod]
[DynamicData(nameof(MainStreams))]
public void IntraPicturesMatchTheirHashAndEverySliceIsReadToItsEnd(string name)
public void EveryPictureMatchesItsHash(string name)
{
var stream = H265ConformanceStream.Load(name);
var data = File.ReadAllBytes(stream.BitstreamPath);
var hashes = H265PictureHashes.Read(data).ToDictionary(h => h.Picture);
// Inter prediction is not written: P and B slices are read with their prediction units mid-grey, so only the
// pictures of I slices alone can be checked; reading every slice to its end_of_slice_segment_flag without an
// error checks the inter syntax.
var decoder = new H265Decoder { ParseInterSlices = true };
int decoded = 0, hashed = 0, intra = 0;
var decoder = new H265Decoder();
int decoded = 0, hashed = 0;
var wrong = new List<string>();
decoder.PictureDecoded += picture =>
{
@@ -38,12 +35,6 @@ public sealed class H265DecoderTests
}
hashed++;
if (!picture.IntraOnly)
{
return;
}
intra++;
for (var c = 0; c < hash.Planes.Length; c++)
{
var width = c == 0 ? picture.Width : picture.ChromaWidth;
@@ -69,21 +60,30 @@ public sealed class H265DecoderTests
}
Assert.AreEqual(stream.FrameCount, frames, $"{name}: fotogrammi in uscita");
if (hashes.Count > 0)
{
Assert.IsGreaterThan(0, intra, $"{name}: nessuna immagine intra controllata");
}
}
[TestMethod]
public void InterSlicesAreRefusedByDefault()
public void TheHashesCoverInterPictures()
{
// BUMPING_A begins with an IDR picture and goes on with P and B slices: the IDR comes out, then the refusal.
var data = File.ReadAllBytes(H265ConformanceStream.Load("BUMPING_A_ericsson_1").BitstreamPath);
var decoder = new H265Decoder();
var error = Assert.ThrowsExactly<H265Exception>(() => decoder.DecodeAnnexB(data));
StringAssert.Contains(error.Message, "inter");
Assert.IsGreaterThanOrEqualTo(1, decoder.PicturesDecoded);
// The check above is worth something for inter prediction only if the hashes cover P and B pictures: count
// them in the streams that carry hashes, decoding a few streams whose names say they are about inter tools.
string[] names = ["MERGE_A_TI_3", "TMVP_A_MS_3", "WP_A_Toshiba_3", "WP_B_Toshiba_3", "PMERGE_A_TI_3", "MVCLIP_A_qualcomm_3", "MVEDGE_A_qualcomm_3", "SAO_A_MediaTek_4", "RAP_B_Bossen_2"];
var none = new List<string>();
foreach (var name in names)
{
var data = File.ReadAllBytes(H265ConformanceStream.Load(name).BitstreamPath);
var hashes = H265PictureHashes.Read(data).Select(h => h.Picture).ToHashSet();
var inter = 0;
var decoder = new H265Decoder();
decoder.PictureDecoded += picture => inter += !picture.IntraOnly && hashes.Contains((int)picture.DecodeIndex) ? 1 : 0;
decoder.DecodeAnnexB(data);
if (inter == 0)
{
none.Add(name);
}
}
Assert.IsEmpty(none, $"nessuna immagine inter con hash: {string.Join(", ", none)}");
}
[TestMethod]
@@ -155,6 +155,10 @@ public sealed class H265DecoderTests
[DataRow("WPP_C_ericsson_MAIN_2", 2708)]
[DataRow("TILES_B_Cisco_1", 2709)]
[DataRow("DSLICE_A_HHI_5", 2710)]
[DataRow("MVEDGE_A_qualcomm_3", 2711)]
[DataRow("WP_B_Toshiba_3", 2712)]
[DataRow("TMVP_A_MS_3", 2713)]
[DataRow("PMERGE_B_TI_3", 2714)]
public void DamagedStreamsGiveFramesOrAnH265Exception(string name, int seed)
{
var data = File.ReadAllBytes(H265ConformanceStream.Load(name).BitstreamPath);
@@ -186,7 +190,7 @@ public sealed class H265DecoderTests
try
{
var decoder = new H265Decoder { ParseInterSlices = true };
var decoder = new H265Decoder();
decoder.FrameOutput += _ => { };
decoder.DecodeAnnexB(copy);
}