Skip to content

H.264 decoder over avkit container samples, bit-exact against ffmpeg (D1 of avkit#89) - #1

Merged
tannevaled merged 6 commits into
mainfrom
h264-decoder
Nov 8, 2026
Merged

tannevaled merged 6 commits into
mainfrom
h264-decoder

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Wave D1 of go-avkit/avkit#89: H.264 decoder

New module github.com/go-avkit/decode. Input is what avkit's container
hands over (avcC or TrackConfig parameter sets + length-prefixed samples, or
raw Annex B); output is pictures in display order as planar YUV with chroma
format, bit depth and PTS. The decoding is oops1/go.264 v1.12.0 (BSD-2-Clause,
license checked 2026-11-01), software path only, fixed upstream where wrong
(upstream is active: last push 2026-10-09, so patched by PR, not forked).

Measured (single thread, vs ffmpeg -f framemd5 -pix_fmt yuv420p)

Set Result
ITU-T H.264.1 AVCv1, 81 bitstreams 73 match ffmpeg (and the suite yuv where shipped); 69 with go.264 v1.12.0, +4 (MR2..MR5_TANDBERG) with oops1/go.264#2; 5 interlaced and 3 FMO/ASO refused, not claimed
29 go.264 streams (Baseline/Main/High) all match, run in CI
5 real MP4/MKV files, 900 pictures each all match; hashes only in testdata/real-files.txt

Profiles claimed: Constrained Baseline, Baseline without FMO/ASO, Main
progressive, High 4:2:0 8-bit progressive (no JVT FRExt stream measured yet).
Everything else returns ErrUnsupported.

Security

MaxFrameMBs / MaxSampleBytes checked before any stream-sized allocation;
bomb test under a 256 MiB memory limit asserts refusal and < 8 MiB allocated;
three fuzz targets with committed corpus, run 60-90 s each locally (clean) and
in CI; govulncheck in CI; NAL lengths bounds-checked (32-bit lane in CI).

Not done / honest gaps

  • Performance not measured: machine load was 36-50 (limit 8). Issue filed.
  • H.264 PDF could not be fetched whole (10 MB cap): clause numbers are not
    re-read against the text (README says so). ISO/IEC 14496-15 is paywalled.
  • JVT bitstreams are not committed (redistribution terms unstated); the
    manifests and DECODE_JVT_DIR test are.

CI: gofmt, 3 OS with race and exact coverage gate (tools/covergate reads the
profile; the library is at 100% of 152 statements), fuzz, govulncheck, amd64,
arm64, 386, riscv64/loong64/ppc64le/s390x under qemu. Renovate config as the
org's other repos. Not merged, not tagged.

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 7, 2026 22:23
…fmpeg

Package decode takes an avcC record (ISO/IEC 14496-15 5.3.3.1) or an avkit
container.TrackConfig plus length-prefixed samples, and returns pictures in
display order with their PTS, chroma format and bit depth. The decoding itself
is github.com/oops1/go.264 (BSD-2-Clause, pure Go), pinned at v1.12.0 and
forced onto its software path.

Resource bounds: MaxFrameMBs (default 36864) and MaxSampleBytes (default
64 MiB) are enforced before any buffer sized by the stream is allocated; a
bomb SPS is refused under a 256 MiB memory limit.

tools/ holds the oracle harness (jvt: download ITU-T H.264.1 streams, compare
every picture's MD5 with ffmpeg -f framemd5) and covergate, which reads the
cover profile itself instead of trusting a rounded percentage.

Refs go-avkit/avkit#89

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* .github/workflows/ci.yml: gofmt, 3 OS with race + exact coverage gate
  (tools/covergate), fuzz, govulncheck, amd64/arm64, 386, riscv64/loong64/
  ppc64le/s390x under qemu.
* testdata/jvt: ffmpeg framemd5 MD5s for 73 ITU-T H.264.1 AVCv1 streams;
  TestJVTConformance runs them when DECODE_JVT_DIR is set. MR2..MR5_TANDBERG
  are pendingUpstream (oops1/go.264#2).
* testdata/fuzz: seed corpus; Fuzz{ParseAVCC,DecodeSample,DecodeAnnexB}.
* testdata/real-files.txt: hashes of 5 real MP4/MKV files, 900 pictures each.
* tools/jvt: fetch, compare, diff, bits, file, clip, seeds.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
tannevaled and others added 4 commits November 7, 2026 22:57
* Windows checks text files out with CRLF, so every ffmpeg MD5 carried a
  trailing \r and no picture matched. Read the manifests tolerantly and mark
  testdata -text so the bytes are never rewritten.
* govulncheck v1.1.4 panics on Go 1.27.3 (x/tools/go/ssa: unexpected expr
  *ast.KeyValueExpr); use @latest as the org's tooling rule says.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
PowerShell on the Windows runner split `-coverprofile=cover.out` at the dot
("FAIL .out [setup failed]"). The first Windows failure (CRLF) was fixed in the
previous commit; this is the second.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Downloaded ITU-T H.264 (V16, 06/2026) and checked every clause cited against
it: 7.4.3, 8.2.1 (+8.2.1.1..8.2.1.3), 8.2.5.1..8.2.5.4, C.4.4 are right. Table
numbers and sub-clause numbers that were not opened (Table 6-1, Table A-1,
7.3.2.1.1) are dropped. ISO/IEC 14496-15 is paywalled: the avcC comments now
cite mp4ff's reader, which was opened, and the High-profile extension is read
for every profile except 66/77/88 as mp4ff does (it also covers 244).

Coverage was checked per function (`go tool cover -func`: every line 100.0%);
tools/covergate already fails on any statement block that never ran, which is
stricter than per function.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…bases exactly

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 57d26d7 into main Nov 8, 2026
13 checks passed
@tannevaled
tannevaled deleted the h264-decoder branch November 8, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant