# H.264 conformance fixtures (tools/fixtures.py): a selection of the ITU-T H.264.1 / JVT conformance bitstreams # (freely downloadable from https://www.itu.int/wftp3/av-arch/jvt-site/draft_conformance/), downloaded once into # tests/gen/jvt_cache/. Reference frames: the decoded .yuv shipped in each zip (the JM reference decoder's output) when # it has the expected size, else ffmpeg's decode (-fps_mode passthrough). Per-frame CRC-32 of yuv420p. # tests/gen/h264_jvt.luau { name, data64 (the bitstream, base64), width, height, frames = { crc ... }, ref = "jm" | "ffmpeg", expect = "ok" | # "UNSUPPORTED" } (empty when the site cannot be reached) import base64, json, os, subprocess, urllib.request, zipfile, zlib INPUTS = [] BASE = "https://www.itu.int/wftp3/av-arch/jvt-site/draft_conformance/" OK = [ "AVCv1/BA1_Sony_D", "AVCv1/BA2_Sony_F", "AVCv1/BA3_SVA_C", "AVCv1/BA_MW_D", "AVCv1/BANM_MW_D", "AVCv1/BAMQ2_JVC_C", "AVCv1/BASQP1_Sony_C", "AVCv1/CABA1_SVA_B", "AVCv1/CABA2_Sony_E", "AVCv1/CABA3_SVA_B", "AVCv1/CABA3_TOSHIBA_E", "AVCv1/CABACI3_Sony_B", "AVCv1/CABAST3_Sony_E", "AVCv1/CACQP3_Sony_D", "AVCv1/CANL2_Sony_E", "AVCv1/CANL3_SVA_B", "AVCv1/CANL4_SVA_B", "AVCv1/CAQP1_Sony_B", "AVCv1/CI_MW_D", "AVCv1/CVBS3_Sony_C", "AVCv1/CVFC1_Sony_C", "AVCv1/CVSE2_Sony_B", "AVCv1/CVSEFDFT3_Sony_E", "AVCv1/CVWP3_TOSHIBA_E", "AVCv1/MIDR_MW_D", "AVCv1/MPS_MW_A", "AVCv1/MR1_BT_A", "AVCv1/MR1_MW_A", "AVCv1/MR2_TANDBERG_E", "AVCv1/MR4_TANDBERG_C", "AVCv1/NL2_Sony_H", "AVCv1/NLMQ2_JVC_C", "AVCv1/NRF_MW_E", "AVCv1/SL1_SVA_B", "AVCv1/SVA_BA2_D", "AVCv1/SVA_CL1_E", "AVCv1/SVA_FM1_E", "AVCv1/SVA_NL2_E", "AVCv1/cavlc_mot_frm0_full_B", "AVCv1/cabac_mot_frm0_full", "FRExt/FRExt1_Panasonic_D", "FRExt/FRExt3_Panasonic_E", "FRExt/HCAFR1_HHI_C", "FRExt/HCAFR2_HHI_A", "FRExt/HCBP2_HHI_A", "FRExt/HCMP1_HHI_A", "FRExt/brcm_freh3", "FRExt/freh12_b", ] UNSUPPORTED = ["FRExt/HCAFF1_HHI_B", "FRExt/HCAMFF1_HHI_B", "AVCv1/SP1_BT_A", "FRExt/Hi422FR1_SONY_A"] EXT = (".jsv", ".264", ".h264", ".avc", ".26l", ".jvt") def fetch(ctx, item): cache = os.path.join(ctx.gen, "jvt_cache") os.makedirs(cache, exist_ok=True) path = os.path.join(cache, item.split("/")[1] + ".zip") if not os.path.exists(path): try: with urllib.request.urlopen(BASE + item + ".zip", timeout=120) as r: data = r.read() except Exception as e: print("h264_jvt: cannot download %s: %s" % (item, e)) return None with open(path, "wb") as f: f.write(data) return path def generate(ctx): ff = ctx.nix("ffmpeg", ["sh", "-c", "command -v ffmpeg"]).decode().strip() fp = os.path.join(os.path.dirname(ff), "ffprobe") out = [] for item in OK + UNSUPPORTED: z = fetch(ctx, item) if not z: continue zf = zipfile.ZipFile(z) names = zf.namelist() bs = [n for n in names if n.lower().endswith(EXT)] if not bs: continue data = zf.read(bs[0]) name = item.split("/")[1] tmp = os.path.join(ctx.gen, "jvt_cache", name + ".bit") with open(tmp, "wb") as f: f.write(data) if item in UNSUPPORTED: out.append({"name": name, "data64": base64.b64encode(data).decode(), "width": 0, "height": 0, "frames": [], "ref": "none", "expect": "UNSUPPORTED"}) continue st = json.loads(subprocess.run([fp, "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", "json", tmp], capture_output=True, text=True).stdout)["streams"][0] w, h = st["width"], st["height"] fs = w * h * 3 // 2 raw = subprocess.run([ff, "-v", "error", "-threads", "1", "-i", tmp, "-fps_mode", "passthrough", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-"], capture_output=True).stdout frames = [zlib.crc32(raw[i:i + fs]) for i in range(0, len(raw), fs)] ref = "ffmpeg" yuvs = [n for n in names if n.lower().endswith(".yuv")] if yuvs: jm = zf.read(yuvs[0]) if len(jm) == len(frames) * fs: jmf = [zlib.crc32(jm[i:i + fs]) for i in range(0, len(jm), fs)] if jmf != frames: print("h264_jvt: %s: JM and ffmpeg references differ, using JM" % name) frames, ref = jmf, "jm" out.append({"name": name, "data64": base64.b64encode(data).decode(), "width": w, "height": h, "frames": frames, "ref": ref, "expect": "ok"}) ctx.emit("h264_jvt", out)