HEVC anche nei flussi di programma MPEG: codec e dimensioni dall'SPS
verifica / controlli (push) Canceled after 0s
verifica / prove (push) Canceled after 0s
verifica / installatore (push) Canceled after 0s
verifica / immagine (push) Canceled after 0s

Il lettore MPEG arrivato con il ramo H.264 prendeva le dimensioni solo
dall'SPS dell'H.264; un flusso con il tipo 0x24 nella mappa restava HEVC
senza dimensioni. H265StreamInfo legge l'SPS di un flusso Annex B (dopo la
finestra di conformità), come H264StreamInfo. Senza mappa un HEVC non si
riconosce; i campioni non si elencano, quindi niente miniatura, come per
l'H.264. Due righe in decisioni.md: questa e le scelte dell'unione (HEIC
nella facciata dei codec, fotogrammi H.264 a 16 bit nel convertitore
comune).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-25 11:39:23 +01:00
1 parent 7e5eccd1ec
commit 281b2e5bc3
6 files changed
+115 -9

No files matched your search

@@ -275,6 +275,24 @@ public sealed class LegacyContainerTests
Assert.IsNull(container.Audio);
}
[TestMethod]
[DataRow("INITQP_A_Sony_1")]
[DataRow("CONFWIN_A_Sony_1")]
public void HevcInAProgramStreamTakesItsSizeFromTheSps(string name)
{
// Stream type 0x24 in the stream map; the size is the picture's after the conformance window.
var es = ElementaryStream.LoadHevc(name);
var container = Read(LegacyTestVideos.MpegPs(new PsOptions { Video = "hevc", Stream = es, StreamMap = true, Audio = null }));
Assert.AreEqual(VideoCodec.Hevc, container.Video!.Codec);
Assert.AreEqual((es.Width, es.Height), (container.Video.Width, container.Video.Height));
Assert.AreEqual("0x24", container.Video.CodecTag);
Assert.IsEmpty(container.Video.Samples, "i campioni di un MPEG non si elencano, nemmeno se HEVC");
// Without a stream map an HEVC stream is not told from other video: no size, but no error either.
var unmapped = Read(LegacyTestVideos.MpegPs(new PsOptions { Video = "hevc", Stream = es, Audio = null }));
Assert.AreEqual((0, 0), (unmapped.Video!.Width, unmapped.Video.Height));
}
[TestMethod]
public void TheEndOfALongProgramStreamGivesItsDuration()
{
@@ -25,7 +25,7 @@ internal sealed record AsfOptions
/// <summary>What a test MPEG program stream holds.</summary>
internal sealed record PsOptions
{
/// <summary>«mpeg2», «mpeg1» or «h264» (then <see cref="Stream"/> gives the pictures).</summary>
/// <summary>«mpeg2», «mpeg1», «h264» or «hevc» (for these two <see cref="Stream"/> gives the pictures).</summary>
public string Video { get; init; } = "mpeg2";
public int Width { get; init; } = 720;
public int Height { get; init; } = 576;
@@ -358,13 +358,14 @@ internal static class LegacyTestVideos
/// An MPEG program stream: a pack header before each picture, a system header, optionally a program stream map, the
/// pictures as PES packets of at most 2,000 bytes (the first with its presentation time), and audio frames between.
/// MPEG-1 and MPEG-2 pictures are a sequence header (with its extension in MPEG-2), a GOP header, a picture header
/// and filler slice bytes; H.264 pictures are the access units of <see cref="PsOptions.Stream"/>.
/// and filler slice bytes; H.264 and HEVC pictures are the access units of <see cref="PsOptions.Stream"/>.
/// </summary>
public static byte[] MpegPs(PsOptions o)
{
var random = new Random(o.Seed);
var frameTicks = o.Video == "h264" ? 3000 : 3600; // 30 or 25 pictures a second
var frames = o.Video == "h264" ? o.Stream!.Count : o.Frames;
var coded = o.Video is "h264" or "hevc";
var frameTicks = coded ? 3000 : 3600; // 30 or 25 pictures a second
var frames = coded ? o.Stream!.Count : o.Frames;
using var output = new MemoryStream();
var audioTime = o.FirstPts;
for (var i = 0; i < frames; i++)
@@ -376,14 +377,14 @@ internal static class LegacyTestVideos
output.Write([0, 0, 1, 0xBB, 0, 12, 0x80, 0x00, 0x01, 0x04, 0xE1, 0xFF, 0xE0, 0xE0, 0xE8, 0xC0, 0xC0, 0x20]);
if (o.StreamMap)
{
var videoType = o.Video switch { "h264" => (byte)0x1B, "mpeg1" => (byte)0x01, _ => (byte)0x02 };
var videoType = o.Video switch { "h264" => (byte)0x1B, "hevc" => (byte)0x24, "mpeg1" => (byte)0x01, _ => (byte)0x02 };
byte[] map = [videoType, 0xE0, 0, 0, 0x04, 0xC0, 0, 0];
byte[] body = [0x80, 0x01, 0, 0, .. U16((ushort)map.Length), .. map, 0, 0, 0, 0];
output.Write([0, 0, 1, 0xBC, .. U16((ushort)body.Length), .. body]);
}
}
var picture = o.Video == "h264" ? o.Stream!.WithStartCodes(i) : MpegPicture(o, i, random);
var picture = coded ? o.Stream!.WithStartCodes(i) : MpegPicture(o, i, random);
for (var offset = 0; offset < picture.Length; offset += 2000)
{
var chunk = picture.AsSpan(offset, Math.Min(2000, picture.Length - offset)).ToArray();