open-standards/wai/pack-conformance/supplied_cmaf.py
Transaction Science 836d0255df wai packaging stack: #426, #438 and #452's GPU tier, squashed onto main
One squashed history of three stacked PRs, onto main at b16816671:

- #426 (wai/pack-efficiency): a title's whole AV1 ladder in one package over one
  integer base; several floor rungs (packaging §7.1), a re-pack from a parent
  (§11.5), a floor that is the ladder's own CMAF (§7.7), a floor-only profile
  (§7.8), a streaming pack (§11.4), and the independent verifier at scale (§9.4).
- #438 (wai/cross-fabric): each pack and verify step on the fabric with the least
  measured energy (§11.6); the `fabrics` member of measurement claims
  (jwp-receipts §2.4.8, energy-measurement §6.3); the wai-pack-gpu crate;
  `wai-pack fabric`; `wai-pack floor-decode`.
- #452 (wai/gpu-int-tier), its GPU-tier part only: claiming decode-equivalence on a
  GPU (determinism-tiers §5), the WGSL integer semantics suite, the rules check on
  naga's IR, and the kernels' shift masks and min(max()) clamps.

Left out, by the review's split (EN-C takes it over): #452's platform decode in
dispatch, its commits 6ad92e2e8, 8695bc75f and fed8694f4 and its CHANGELOG entry:
extensions/platform-decode.md, platform-decode-conformance/, wai::platform_decode,
wai-web's platform_decode bundle and demo, and its two SPEC.md sentences.

#438's research note is not carried as written: it is rewritten as
wai/research/cross-fabric.md, with hardware named by architecture, PCI id and OS
version, and every table marked as one run. floor_decode.rs and a wai_pack.rs
comment name the platform's media engine and a full-length film the same way.

wai/CHANGELOG.md is the union of both sides' entries, the stack's first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 20:31:28 -04:00

64 lines
3 KiB
Python

#!/usr/bin/env python3
"""Write a golden's supplied floor in the CMAF form (extensions/packaging.md §7.7) from
another golden's supplied floor in the OBU form (§7.3).
A CMAF floor is a ladder's own initialization segment and media segments, as a media
muxer wrote them, so this golden's are written by one: each `<name>.obu` of the source
golden's floor is muxed, without re-encoding (`-c copy`), by ffmpeg's HLS muxer into fMP4
segments, cutting at every key frame (`-hls_time` of one frame), so each media segment
holds one piece of the plan; its `init.mp4` and `seg_<k>.m4s` files, `<k>` four digits, are
`floor/<name>/`. The policy's `floor.supplied_listing` is set to the SHA-256 of the floor
directory's listing (SPEC §3.1), which `wai-pack listing` prints.
A muxer is not a pure function of its input across versions, so the files are committed
and pinned by the listing: a packer reads them and checks them against the plan, and
never writes them. This script is how the committed files were written, not a step of
verification.
python3 supplied_cmaf.py <ffmpeg> <wai-pack binary> <packs/<from>> <packs/<to>> <fps num/den>
"""
import hashlib
import os
import re
import shutil
import subprocess
import sys
import tempfile
def main(argv):
if len(argv) != 6:
print(__doc__)
return 2
ffmpeg, wai_pack, src, dst, rate = argv[1:]
num, den = (int(x) for x in rate.split("/"))
floor_in, floor_out = os.path.join(src, "floor"), os.path.join(dst, "floor")
if os.path.isdir(floor_out):
shutil.rmtree(floor_out)
os.makedirs(floor_out)
for f in sorted(os.listdir(floor_in)):
if not f.endswith(".obu"):
continue
name = f[:-len(".obu")]
with tempfile.TemporaryDirectory() as tmp:
subprocess.run([ffmpeg, "-nostdin", "-v", "error", "-f", "obu", "-framerate", f"{num}/{den}",
"-i", os.path.join(floor_in, f), "-c", "copy", "-f", "hls", "-hls_time", f"{den / num:.6f}",
"-hls_segment_type", "fmp4", "-hls_fmp4_init_filename", "init.mp4",
"-hls_segment_filename", os.path.join(tmp, "seg_%04d.m4s"), "-hls_playlist_type", "vod",
os.path.join(tmp, "index.m3u8")], check=True)
out = os.path.join(floor_out, name)
os.makedirs(out)
for g in sorted(os.listdir(tmp)):
if g == "init.mp4" or g.endswith(".m4s"):
shutil.copyfile(os.path.join(tmp, g), os.path.join(out, g))
print(f"{out}: {sorted(os.listdir(out))}")
listing = hashlib.sha256(subprocess.run([wai_pack, "listing", floor_out], check=True, capture_output=True).stdout).hexdigest()
p = os.path.join(dst, "policy.toml")
policy = open(p, encoding="utf-8").read()
open(p, "w", encoding="utf-8").write(re.sub(r'supplied_listing = "[0-9a-f]{64}"', f'supplied_listing = "{listing}"', policy))
print(f"listing {listing}")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))