Unione di funzione/decoder-h264 in funzione/decoder-hevc (catena della 0.3.0)
Il ramo HEVC era partito da b23632f; la catena porta qui documenti e regole, S4b, i codec di casa (C1) e il resto dell'H.264 (campi, Extended, alta profondità, MVC, SVC, lettori ASF/FLV/MPEG). Le due serie restano intere: - VideoFrameDecoder sceglie H.264 o HEVC come nel ramo HEVC; dell'H.264 prende la sola vista di base dell'MVC e i piani a 16 bit, passati al convertitore comune YuvToRgb (anche 4:2:2, 4:4:4 e 4:0:0) al posto del suo. - Le foto HEIC passano dalla facciata dei codec di C1: HeifImageDecoder trasforma l'HeifImage in RgbaImage senza copia e irot/imir nell'orientamento, così ImageDecoding, miniature e impronte le trattano come le altre foto; la dimensione di un HEIC grande si legge dai soli box. - decisioni.md tiene tutte le righe dei due lati (prima quelle della catena). - Prove: entrambe le copie dei flussi di conformità H.264 e H.265 e delle immagini di riferimento; nei file rovinati entrano sia HEVC sia WMV/FLV/MPEG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
14920afebf
420 files changed
+39437
-2446
No files matched your search
@@ -402,7 +402,8 @@ public sealed class VideoFrameDecoder
|
||||
}
|
||||
else
|
||||
{
|
||||
avc = new H264Decoder { Wanted = _ => wanted() };
|
||||
// Of an MVC stream only the base view: it is the 2D video, and the other views would add frames.
|
||||
avc = new H264Decoder { Wanted = _ => wanted(), DecodeAllViews = false };
|
||||
avc.FrameDecoded += frame => found(new Frame(frame, null));
|
||||
lengthSize = video.AnnexB ? 0 : avc.ConfigureAvcC(video.AvcConfiguration);
|
||||
}
|
||||
@@ -562,7 +563,8 @@ public sealed class VideoFrameDecoder
|
||||
}
|
||||
|
||||
/// <summary>A coarse grid of mean luma and chroma values, to compare frames without their compression noise.</summary>
|
||||
private static double[] Grid(Frame frame) => frame.Hevc is { } h ? Grid(Planes(h)) : Grid(Planes(frame.Avc!));
|
||||
private static double[] Grid(Frame frame) =>
|
||||
frame.Hevc is { } h ? Grid(Planes(h)) : frame.Avc!.BytesPerSample == 2 ? Grid(WidePlanes(frame.Avc)) : Grid(Planes(frame.Avc));
|
||||
|
||||
/// <summary>
|
||||
/// The grid on an 8-bit scale: luma means in the first half, mean distances of the chroma from its middle in the
|
||||
@@ -619,8 +621,45 @@ public sealed class VideoFrameDecoder
|
||||
return grid;
|
||||
}
|
||||
|
||||
private static YuvPlanes<byte> Planes(H264Frame frame) =>
|
||||
new(frame.Y, frame.Cb, frame.Cr, frame.Width, frame.Height, 1, 1, false, 8, 8);
|
||||
/// <summary>
|
||||
/// The planes of an H.264 frame of 8-bit samples, at any chroma sampling. A monochrome frame comes with grey 4:2:0
|
||||
/// chroma planes (<see cref="H264Frame"/>), which the conversion does not read.
|
||||
/// </summary>
|
||||
private static YuvPlanes<byte> Planes(H264Frame frame)
|
||||
{
|
||||
var (sx, sy) = ChromaShifts(frame.ChromaFormat);
|
||||
return new(frame.Y, frame.Cb, frame.Cr, frame.Width, frame.Height, sx, sy, frame.ChromaFormat == 0, frame.BitDepthLuma, frame.BitDepthChroma);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The planes of an H.264 frame above 8 bits (two bytes a sample, little-endian), as 16-bit values: copied once,
|
||||
/// for the few frames a thumbnail or a stillness check decodes.
|
||||
/// </summary>
|
||||
private static YuvPlanes<ushort> WidePlanes(H264Frame frame)
|
||||
{
|
||||
static ushort[] Wide(byte[] plane)
|
||||
{
|
||||
var values = new ushort[plane.Length / 2];
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
values[i] = BinaryPrimitives.ReadUInt16LittleEndian(plane.AsSpan(2 * i));
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
var (sx, sy) = ChromaShifts(frame.ChromaFormat);
|
||||
return new(Wide(frame.Y), Wide(frame.Cb), Wide(frame.Cr), frame.Width, frame.Height, sx, sy, frame.ChromaFormat == 0,
|
||||
frame.BitDepthLuma, frame.BitDepthChroma);
|
||||
}
|
||||
|
||||
/// <summary>Chroma subsampling of chroma_format_idc (0, monochrome, as 4:2:0: the planes H.264 gives it are that size).</summary>
|
||||
private static (int X, int Y) ChromaShifts(int chromaFormat) => chromaFormat switch
|
||||
{
|
||||
0 or 1 => (1, 1),
|
||||
2 => (1, 0),
|
||||
_ => (0, 0),
|
||||
};
|
||||
|
||||
private static YuvPlanes<ushort> Planes(H265Frame frame)
|
||||
{
|
||||
@@ -641,7 +680,9 @@ public sealed class VideoFrameDecoder
|
||||
/// or full range, reduced by an integer factor to fit <paramref name="maxLongSide"/>, then rotated clockwise.
|
||||
/// </summary>
|
||||
internal static VideoImage ToImage(H264Frame frame, int rotation, int maxLongSide) =>
|
||||
ToImage(Planes(frame), frame.MatrixCoefficients, frame.FullRange, rotation, maxLongSide);
|
||||
frame.BytesPerSample == 2
|
||||
? ToImage(WidePlanes(frame), frame.MatrixCoefficients, frame.FullRange, rotation, maxLongSide)
|
||||
: ToImage(Planes(frame), frame.MatrixCoefficients, frame.FullRange, rotation, maxLongSide);
|
||||
|
||||
/// <summary>
|
||||
/// An HEVC frame in RGB, as <see cref="ToImage(H264Frame, int, int)"/>: any chroma format (4:0:0 in grey) and bit
|
||||
|
||||
Reference in new issue
Block a user