Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ its series' file in [changelog/](changelog/) when a newer one ships.

## [Unreleased]

## [0.71.1] - 2026-11-20
## [0.71.2] - 2026-11-20

### Fixed

- Under `WithInBandColourFallback` (`-in-band`, `mp4.Options.InBandColour`),
three video tracks whose header names no colour now get it from their first
sample, where they kept none or the wrong "determined": a VP9 track whose
CodecPrivate holds the Matroska feature records, or whose Colour element
states the range alone (the keyframe header was read only when the profile
was missing); an AV1 track whose `av1C` holds no sequence header (a PQ
video read as having no colour); an HEVC track whose `hvcC` holds arrays
but no SPS. A VP9 Matroska file with no colour anywhere costs one more
- Under `WithInBandColourFallback` (`-in-band`, `mp4.Options.InBandColour`):
an HEVC track declared bt2020-10 is read as HLG (`arib-std-b67`) when an
Alternative Transfer Characteristics SEI of its first sample says so - the
header alone made an HLG video an SDR one; an H.264 record with no SPS
(`avc3`) gets its profile, level, pixel format and colour from the SPS its
samples carry; an MPEG-2 track with no CodecPrivate gets its profile, level
and pixel format from its first sample. Each such track costs one more
bounded read under the option.
- A VP9 keyframe header that says its colour is unknown sets
`ColourDetermined`, as an H.264, HEVC or AV1 stream stating "unspecified"
does: the colour was read, there is none to find elsewhere.
- A fragmented MP4 read head-only gets the first-sample fallback too
(`mp4.Options.InBandColour`): its sample tables are empty, so nothing was
read and an `avc3` or `hev1` track kept no profile, level or colour. The
first `moof` is read for where the first samples are.
- An MPEG-2 CodecPrivate gives the profile, level and pixel format head-only,
and a VP8 track its pixel format: they were empty.
- Bitmap subtitles: a DVB block fills and draws a full-size region and one
picture of it, not four planes (254 bytes of block allocated 208 MiB); a
block asking for more is passed over as damaged.
- A keyframe walk (`WithKeyframeIndex`, `keyframes -walk`) cancelled on its
way returns the cancellation: it returned the keyframes met so far with no
error.
- `concat-hls`, `concat-segment` and `PlanConcat` apply `--sub-offset`
(`Options.SubtitleOffsetMs`): the option was accepted and ignored.
17 changes: 17 additions & 0 deletions changelog/0.70-0.79.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

Archived entries of mkvgo 0.70.x to 0.79.x, as they were published; a version moves here once a newer one ships. The current versions are in [CHANGELOG.md](../CHANGELOG.md).

## [0.71.1] - 2026-11-20

### Fixed

- Under `WithInBandColourFallback` (`-in-band`, `mp4.Options.InBandColour`),
three video tracks whose header names no colour now get it from their first
sample, where they kept none or the wrong "determined": a VP9 track whose
CodecPrivate holds the Matroska feature records, or whose Colour element
states the range alone (the keyframe header was read only when the profile
was missing); an AV1 track whose `av1C` holds no sequence header (a PQ
video read as having no colour); an HEVC track whose `hvcC` holds arrays
but no SPS. A VP9 Matroska file with no colour anywhere costs one more
bounded read under the option.
- A VP9 keyframe header that says its colour is unknown sets
`ColourDetermined`, as an H.264, HEVC or AV1 stream stating "unspecified"
does: the colour was read, there is none to find elsewhere.

## [0.71.0] - 2026-11-20

### Fixed
Expand Down
29 changes: 29 additions & 0 deletions cmd/mkvgo/commands/tell_resynced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,50 @@ import (
"strings"
"testing"

"github.com/gravity-zero/mkvgo/ebml"
"github.com/gravity-zero/mkvgo/internal/livefixture"
)

// growSegment adds n to the size a sized Segment declares, in place.
func growSegment(t *testing.T, data []byte, n int64) {
t.Helper()
r := bytes.NewReader(data)
h, hdr, err := ebml.ReadElementHeader(r)
if err != nil {
t.Fatal(err)
}
segAt := int64(hdr) + h.Size
if _, err := r.Seek(segAt, io.SeekStart); err != nil {
t.Fatal(err)
}
seg, segHdr, err := ebml.ReadElementHeader(r)
if err != nil || seg.Size < 0 {
t.Fatalf("no sized Segment: %v", err)
}
var size bytes.Buffer
if _, err := ebml.WriteDataSizeWidth(&size, seg.Size+n, segHdr-4); err != nil {
t.Fatal(err)
}
copy(data[segAt+4:], size.Bytes())
}

// TestWritingCommandsTellWhatTheSourceWasReadPast: a command that wrote from a source read past stray bytes said
// nothing, and exited 0 under --exit-damaged. It warns, names the rewrite, and counts as damage; a sound source
// stays silent.
func TestWritingCommandsTellWhatTheSourceWasReadPast(t *testing.T) {
sound := livefixture.Build(livefixture.Options{})
cluster := bytes.Index(sound, []byte{0x1F, 0x43, 0xB6, 0x75})
junk := append(append(append([]byte(nil), sound[:cluster]...), []byte("0000\x00\x00")...), sound[cluster:]...)
tailed := livefixture.Build(livefixture.Options{SizedClusters: true, TailTags: true})
tags := bytes.LastIndex(tailed, []byte{0x12, 0x54, 0xC3, 0x67})
tail := append(append(append([]byte(nil), tailed[:tags]...), []byte("0000\x00\x00")...), tailed[tags:]...)
growSegment(t, tail, 6)
for name, tc := range map[string]struct {
data []byte
want string
}{
"stray bytes ahead of the first Cluster": {junk, "6 undecodable byte(s)"},
"stray bytes ahead of the closing Tags": {tail, "6 undecodable byte(s)"},
"sound": {sound, ""},
} {
t.Run(name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mkvgo <command> [options]

Global flags:
- `-json`, `--json` -- the command's report as JSON on stdout (info, tracks, chapters, attachments, tags, probe, keyframes, validate, compare, analyze, fingerprint, verify, playability, ladder, ingest, track-ends, cue-health, diagnose, salvage, reindex, reindex-inplace, retime; ignored by commands without a report). An empty list is `[]`, an empty map `{}`, never `null`; an optional section is left out. An error goes to stderr as `{"error":"...","exit":N}`.
- `-in-band` -- the inspection commands (`info`, `tracks`, `probe`) complete a video track's description from its first sample where the header leaves it short: colour behind an `hvcC` with no SPS or an `av1C` with no sequence header, a VP9 profile or colour the header does not state, HDR10 static metadata (MaxCLL/MaxFALL, mastering display) kept only in the HEVC SEI / AV1 metadata OBUs. It also reads the channel count each AC-3, E-AC-3 and AAC stream states (`stream_channels` in JSON, `channels_mismatch` when the container's `channels` says otherwise; Matroska). One bounded read, only for such a track; the container wins per field. The library's `WithInBandColourFallback` / `mp4.Options.InBandColour`. Ignored on stdin (`-`) and by the writing commands, which always apply it
- `-in-band` -- the inspection commands (`info`, `tracks`, `probe`) complete a video track's description from its first sample where the header leaves it short: colour behind an `hvcC` with no SPS or an `av1C` with no sequence header, HLG named by a SEI under a `bt2020-10` header, the profile of an `avc3` or MPEG-2 track with none in its header, a VP9 profile or colour the header does not state, HDR10 static metadata (MaxCLL/MaxFALL, mastering display) kept only in the HEVC SEI / AV1 metadata OBUs. It also reads the channel count each AC-3, E-AC-3 and AAC stream states (`stream_channels` in JSON, `channels_mismatch` when the container's `channels` says otherwise; Matroska). One bounded read, only for such a track; the container wins per field. The library's `WithInBandColourFallback` / `mp4.Options.InBandColour`. Ignored on stdin (`-`) and by the writing commands, which always apply it
- `-fps-reads` -- the inspection commands (`info`, `tracks`, `probe`) let the frame-rate estimate of a Matroska track without DefaultDuration read the block headers it needs in the first 512 KiB, one exact 32-byte read each; off by default, when the estimate uses only the bytes the head read already holds and the statistics tags. The library's `WithFrameRateReads`. On 63 real files without DefaultDuration (local ext4 disk, page cache dropped per file): 12 estimated by default, 63 with the flag, about 126 more reads per file and a median probe of 7.8 ms instead of 5.0 ms (no difference once cached)
- `-f`, `--force` -- overwrite an existing output file. Without it, every command that writes a new file refuses to clobber an existing one (`out.mkv already exists`); with it, an output that is one of the command's inputs is still refused. `edit-inplace` modifies its input file by design, and `split` overwrites existing parts (but never its source).
- `--sync` -- a command writing a new Matroska file flushes it to disk before renaming it into place, so a completed output survives a power loss; without it the output is still written to `<output>.mkvgo.tmp` and renamed, so a failure keeps the file already there, but a power loss soon after the command ends can leave an empty file under the output's name, the file it replaced gone (the rename can reach the disk before the data). The replace commands always flush.
Expand Down
2 changes: 1 addition & 1 deletion docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ A few cases are genuinely not readable head-only (the data lives only in the med

**HDR10 static metadata.** `Track.HDR` (`*HDRStaticMetadata`) carries the Content Light Level (`MaxCLL`/`MaxFALL`, cd/m²) and the SMPTE ST 2086 Mastering Display colour volume (`MasteringDisplay`: R/G/B + white-point CIE 1931 chromaticities and the luminance range) - the side data probers report for HDR10. Read head-only from the Matroska Colour element (`MaxCLL`/`MaxFALL` + `MasteringMetadata`) or the MP4 `clli`/`mdcv` boxes (whose fixed-point, G,B,R-ordered values are normalised to the Matroska units), nil when absent. Independent of `IsHDR()` (transfer-based detection) and `DolbyVision`.

**In-band fallback (opt-in).** Some streaming-style HEVC muxes keep the SPS in-band (a bare hvcC with no parameter sets) and write no container colour, so a head-only probe sees no colour at all. Passing the in-band option makes the probe - only for such a track - read its first sample, parse the SPS VUI, and apply an Alternative Transfer Characteristics SEI override (HLG's `bt2020-10` → `arib-std-b67` compatibility signal). An hvcC whose arrays hold no SPS is read the same way, and so is an **AV1** track whose container names no colour and whose `av1C` holds no sequence header: the first temporal unit's gives the colour, bit depth and level. The same option covers **VP9 whose container names no colour** - no `vpcC` (how WebM is normally muxed), or the Matroska feature records, which state a profile but no colour: the keyframe's uncompressed header is the only place the stream says them, so the probe reads that one sample and fills `Profile` (`"Profile 0"`..`"Profile 3"`, the prober spelling), `VideoBitDepth`, `PixelFormat`, `ColorRange`, and the colour its `color_space` names where the named standard fixes the code points beyond doubt: BT.709, SMPTE 170M/240M and sRGB fill primaries, transfer and matrix; BT.601 fills matrix and transfer (its primaries differ between the 525- and 625-line variants); **BT.2020 fills primaries and matrix but never the transfer** - a VP9 HDR stream is BT.2020 with PQ or HLG, which the header cannot express and only the container states, so `ColorTransfer` stays nil there unless the container says. `unknown` fills nothing, and counts as read (`ColourDetermined`): the stream has no colour to state. The container Colour element wins per field as always. The same option completes the **HDR10 static metadata** of a PQ or HLG HEVC/AV1 track whose container carries no MasteringMetadata or no MaxCLL/MaxFALL - how most HDR10 muxes write it, keeping only the in-band copy: the first sample's SEI messages (HEVC `mastering_display_colour_volume` 137 / `content_light_level_info` 144) or metadata OBUs (AV1 `HDR_MDCV` / `HDR_CLL`) fill `Track.HDR`, each part only where the container said nothing. It also settles the **scan type of an H.264 track** whose SPS allows field coding (`frame_mbs_only_flag` 0) and whose container states no `FlagInterlaced`, from the first 16 samples of the track - on Matroska whatever the other tracks interleave between them, a track giving up after 128 blocks of other tracks in a row; on MP4 located through the sample table, contiguous samples read in one run, 16 KiB of each and 1 MiB in all. A record with no SPS (`avc3`) is read with the SPS the samples carry, and one that codes frames only makes the track `progressive`, as it would in the header. An **HEVC** track the header leaves open is read the same way: an in-band SPS with `field_seq_flag`, or a picture timing SEI that says a picture is interlaced (`source_scan_type` 0) or a field (`pic_struct` 1, 2, 9-12), makes it `interlaced` - never a picture whose `source_scan_type` says progressive - and `pic_struct` 3-6 and 9-12 give the order. An **MPEG-2** track the container leaves open is read from the sequence header its first sample carries (muxers often write no CodecPrivate): `progressive_sequence` 1 makes it `progressive`; a field picture, or a frame with `progressive_frame` 0, makes it `interlaced`, with the order from `top_field_first` or the first field of a pair; a progressive frame repeating a field (soft telecine) proves nothing. `ScanType` becomes `interlaced` on proof: a field-coded slice (`field_pic_flag` 1); a frame whose two fields have different picture order counts (`delta_pic_order_cnt_bottom`, or `offset_for_top_to_bottom_field` with pic_order_cnt_type 1); a picture timing SEI that shows a field alone (`pic_struct` 1/2) or says `ct_type` interlaced; or `pic_struct` top-bottom/bottom-top (3/4) on an MBAFF stream, unless a sample shows soft telecine (`pic_struct` 5/6) or `ct_type` progressive. `FieldOrder` gets `tt`/`bb` when every sample that states an order agrees: the field picture order counts (the decoding order with pic_order_cnt_type 2), the frame's bottom-field offset, or `pic_struct`. Without proof both stay `""` - a frame whose two fields share an instant proves nothing, MBAFF included. It is off by default on the probe; tracks that already carry the description in the header read no frame. The remux and plan entry points (`RemuxToMP4`, `RemuxToHLS`, `PlanHLS`, `PlanGrowingHLS`, and their MP4-source counterparts) always apply it, so the `colr`/`mdcv`/`clli` they write describe the stream whichever copy the source muxer kept.
**In-band fallback (opt-in).** Some streaming-style HEVC muxes keep the SPS in-band (a bare hvcC with no parameter sets) and write no container colour, so a head-only probe sees no colour at all. Passing the in-band option makes the probe - only for such a track - read its first sample, parse the SPS VUI, and apply an Alternative Transfer Characteristics SEI override (HLG's `bt2020-10` → `arib-std-b67` compatibility signal). An HEVC track the header declares `bt2020-10` is read for that SEI alone, since it is how HLG travels. An hvcC whose arrays hold no SPS is read the same way, and so is an **AV1** track whose container names no colour and whose `av1C` holds no sequence header: the first temporal unit's gives the colour, bit depth and level. The same option covers **VP9 whose container names no colour** - no `vpcC` (how WebM is normally muxed), or the Matroska feature records, which state a profile but no colour: the keyframe's uncompressed header is the only place the stream says them, so the probe reads that one sample and fills `Profile` (`"Profile 0"`..`"Profile 3"`, the prober spelling), `VideoBitDepth`, `PixelFormat`, `ColorRange`, and the colour its `color_space` names where the named standard fixes the code points beyond doubt: BT.709, SMPTE 170M/240M and sRGB fill primaries, transfer and matrix; BT.601 fills matrix and transfer (its primaries differ between the 525- and 625-line variants); **BT.2020 fills primaries and matrix but never the transfer** - a VP9 HDR stream is BT.2020 with PQ or HLG, which the header cannot express and only the container states, so `ColorTransfer` stays nil there unless the container says. `unknown` fills nothing, and counts as read (`ColourDetermined`): the stream has no colour to state. The container Colour element wins per field as always. The same option completes the **HDR10 static metadata** of a PQ or HLG HEVC/AV1 track whose container carries no MasteringMetadata or no MaxCLL/MaxFALL - how most HDR10 muxes write it, keeping only the in-band copy: the first sample's SEI messages (HEVC `mastering_display_colour_volume` 137 / `content_light_level_info` 144) or metadata OBUs (AV1 `HDR_MDCV` / `HDR_CLL`) fill `Track.HDR`, each part only where the container said nothing. It also settles the **scan type of an H.264 track** whose SPS allows field coding (`frame_mbs_only_flag` 0) and whose container states no `FlagInterlaced`, from the first 16 samples of the track - on Matroska whatever the other tracks interleave between them, a track giving up after 128 blocks of other tracks in a row; on MP4 located through the sample table, contiguous samples read in one run, 16 KiB of each and 1 MiB in all. A record with no SPS (`avc3`) is read with the SPS the samples carry, and one that codes frames only makes the track `progressive`, as it would in the header. An **HEVC** track the header leaves open is read the same way: an in-band SPS with `field_seq_flag`, or a picture timing SEI that says a picture is interlaced (`source_scan_type` 0) or a field (`pic_struct` 1, 2, 9-12), makes it `interlaced` - never a picture whose `source_scan_type` says progressive - and `pic_struct` 3-6 and 9-12 give the order. An **MPEG-2** track the container leaves open is read from the sequence header its first sample carries (muxers often write no CodecPrivate): `progressive_sequence` 1 makes it `progressive`; a field picture, or a frame with `progressive_frame` 0, makes it `interlaced`, with the order from `top_field_first` or the first field of a pair; a progressive frame repeating a field (soft telecine) proves nothing. `ScanType` becomes `interlaced` on proof: a field-coded slice (`field_pic_flag` 1); a frame whose two fields have different picture order counts (`delta_pic_order_cnt_bottom`, or `offset_for_top_to_bottom_field` with pic_order_cnt_type 1); a picture timing SEI that shows a field alone (`pic_struct` 1/2) or says `ct_type` interlaced; or `pic_struct` top-bottom/bottom-top (3/4) on an MBAFF stream, unless a sample shows soft telecine (`pic_struct` 5/6) or `ct_type` progressive. `FieldOrder` gets `tt`/`bb` when every sample that states an order agrees: the field picture order counts (the decoding order with pic_order_cnt_type 2), the frame's bottom-field offset, or `pic_struct`. Without proof both stay `""` - a frame whose two fields share an instant proves nothing, MBAFF included. It is off by default on the probe; tracks that already carry the description in the header read no frame. The remux and plan entry points (`RemuxToMP4`, `RemuxToHLS`, `PlanHLS`, `PlanGrowingHLS`, and their MP4-source counterparts) always apply it, so the `colr`/`mdcv`/`clli` they write describe the stream whichever copy the source muxer kept.

```go
// MKV (Open and Read take the same options as OpenMeta)
Expand Down
3 changes: 2 additions & 1 deletion mkv/reader/block_overrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reader

import (
"bytes"
"context"
"errors"
"io"
"testing"
Expand Down Expand Up @@ -91,7 +92,7 @@ func TestKeyframeIndexResyncsPastAnOverrunningBlock(t *testing.T) {
data, _ := overrunClusters(false)
segStart := int64(bytes.Index(data, []byte{0x1F, 0x43, 0xB6, 0x75}))
p := &parser{r: bytes.NewReader(data), segStart: segStart, segEnd: -1}
times := p.buildKeyframeIndex(0, 1000000)
times := p.buildKeyframeIndex(context.Background(), 0, 1000000)
found := false
for _, ms := range times {
found = found || ms == 1000
Expand Down
Loading
Loading