Decodificatore H.264 per le immagini interlacciate: campi, PAFF e MBAFF (#58)

I video interlacciati (telecamere, registrazioni televisive) davano un'H264Exception e restavano
senza miniatura. Ora il decodificatore li gestisce tutti, scritto in casa sulla specifica:

- campi e coppie di campi (PAFF) e macroblocchi adattivi (MBAFF) su una sola griglia di
  fotogramma, con origine e passo per macroblocco, senza copie in piani separati;
- POC, liste dei riferimenti, riordino e marcatura (MMCO, lungo termine) per campi;
- vicini MBAFF della tabella 6-4, vettori di moto e riferimenti scalati fra campo e
  fotogramma, diretta spaziale e temporale con il colocato di campo, pesi impliciti per parità;
- contesti CABAC e CAVLC di campo, scansioni di campo 4x4 e 8x8;
- deblocking per campi e per coppie MBAFF;
- uscita con i due campi intercalati; un campo rimasto solo esce con l'altro a 128.

I 17 flussi interlacciati della serie ITU-T H.264.1 passano da «da fare» ai flussi verificati e
coincidono fotogramma per fotogramma con la ricostruzione ufficiale; i 12 a immagini intere e lo
strato base SVC coincidono ancora e non sono più lenti. Prove di robustezza e di immagini saltate
anche sui flussi interlacciati; LEGGIMI.md e una riga in decisioni.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 16:05:41 +01:00
1 parent 25a6d9ce1d
commit 9c626f67ec
15 files changed
+1909 -613

No files matched your search

@@ -6,11 +6,12 @@ namespace Febe.Tests.Codecs.H264;
/// <summary>
/// The decoder against streams of the ITU-T H.264.1 conformance suite: every output frame, in output order, must have the
/// MD5 of the corresponding frame of the official reconstruction (see Conformita/LEGGIMI.md). None of the verified streams
/// uses weighted prediction, memory management operations, long-term references, gaps in frame_num, POC type 1, I_PCM or
/// CABAC pictures of several slices: those parts of the decoder have no reference MD5 here (some are reached by
/// <see cref="H264SyntheticStreamTests"/>, without an official reference). The streams of the parts the decoder does not
/// handle yet (interlaced pictures, FMO and ASO, SP slices, 4:2:2, more than 8 bits, 4:0:0, SVC, MVC) are in
/// MD5 of the corresponding frame of the official reconstruction (see Conformita/LEGGIMI.md). The verified streams include
/// interlaced video — field pictures, PAFF, MBAFF, both together — with memory management operations, long-term
/// references and POC type 1 on fields (MR6_BT_B, MR9_BT_B). None of them uses weighted prediction, gaps in frame_num or
/// I_PCM: those parts of the decoder have no reference MD5 here (some are reached by <see cref="H264SyntheticStreamTests"/>,
/// without an official reference). The streams of the parts the decoder does not handle yet (FMO and ASO, SP slices,
/// 4:2:2, more than 8 bits, 4:0:0, SVC, MVC) are in
/// <see cref="FeaturesStillToDo"/>: they are inconclusive until the feature is written, and fail as soon as one of them
/// matches its reference without having been moved among the verified ones.
/// </summary>
@@ -30,6 +31,23 @@ public sealed class H264ConformanceTests
[DataRow("FRExt1_Panasonic_D")]
[DataRow("FRExt3_Panasonic_E")]
[DataRow("HCAFR1_HHI_C")]
[DataRow("CVFI1_SVA_C")]
[DataRow("FI1_Sony_E")]
[DataRow("CAFI1_SVA_C")]
[DataRow("Sharp_MP_PAFF_1r2")]
[DataRow("HCAFF1_HHI_B")]
[DataRow("CVMAQP3_Sony_D")]
[DataRow("FREXT02_JVC_C")]
[DataRow("CAMACI3_Sony_C")]
[DataRow("CAMASL3_Sony_B")]
[DataRow("HCAMFF1_HHI_B")]
[DataRow("FREXT01_JVC_D")]
[DataRow("CAPAMA3_Sand_F")]
[DataRow("cama1_vtc_c")]
[DataRow("FRExt2_Panasonic_C")]
[DataRow("FRExt4_Panasonic_B")]
[DataRow("MR6_BT_B")]
[DataRow("MR9_BT_B")]
public void FramesMatchTheReference(string name) => AssertMatches(name, "riferimento.md5");
[TestMethod]
@@ -44,23 +62,6 @@ public sealed class H264ConformanceTests
}
[TestMethod]
[DataRow("CVFI1_SVA_C", "immagini a campi (CAVLC)")]
[DataRow("FI1_Sony_E", "immagini a campi, solo slice I (CAVLC)")]
[DataRow("CAFI1_SVA_C", "immagini a campi (CABAC)")]
[DataRow("Sharp_MP_PAFF_1r2", "PAFF, fotogrammi e coppie di campi (CAVLC, POC di tipo 1)")]
[DataRow("HCAFF1_HHI_B", "PAFF (CABAC, High)")]
[DataRow("CVMAQP3_Sony_D", "MBAFF (CAVLC)")]
[DataRow("FREXT02_JVC_C", "MBAFF (CAVLC, High)")]
[DataRow("CAMACI3_Sony_C", "MBAFF con predizione intra vincolata (CABAC)")]
[DataRow("CAMASL3_Sony_B", "MBAFF con quattro slice per immagine (CABAC)")]
[DataRow("HCAMFF1_HHI_B", "MBAFF (CABAC, High)")]
[DataRow("FREXT01_JVC_D", "MBAFF (CABAC, High)")]
[DataRow("CAPAMA3_Sand_F", "PAFF e MBAFF insieme (CABAC)")]
[DataRow("cama1_vtc_c", "campi con il campo inferiore per primo e MBAFF (CABAC)")]
[DataRow("FRExt2_Panasonic_C", "campi e MBAFF con MMCO e matrici di quantizzazione (CAVLC, High)")]
[DataRow("FRExt4_Panasonic_B", "campi e MBAFF con matrici di quantizzazione (CABAC, High)")]
[DataRow("MR6_BT_B", "campi con MMCO e riordino dei riferimenti (Extended, POC di tipo 1)")]
[DataRow("MR9_BT_B", "campi e MBAFF con MMCO e riordino dei riferimenti (CABAC, POC di tipo 1)")]
[DataRow("FM2_SVA_C", "FMO (gruppi di slice di tipo 0) e ASO")]
[DataRow("FM1_FT_E", "FMO (gruppi di slice di tipo 1, 2, 3 e 4)")]
[DataRow("FM1_BT_B", "FMO (gruppi di slice di tipo 0-6) e ASO")]
@@ -123,6 +124,12 @@ public sealed class H264ConformanceTests
[DataRow("FRExt1_Panasonic_D")]
[DataRow("FRExt3_Panasonic_E")]
[DataRow("HCAFR1_HHI_C")]
[DataRow("CAFI1_SVA_C")]
[DataRow("Sharp_MP_PAFF_1r2")]
[DataRow("CAPAMA3_Sand_F")]
[DataRow("cama1_vtc_c")]
[DataRow("HCAMFF1_HHI_B")]
[DataRow("MR9_BT_B")]
public void PicturesLeftOutDoNotChangeTheOthers(string name)
{
// Pictures nobody refers to and nobody wants are not reconstructed (only their headers count): every frame