ws-h264: F.video.open end to end on MP4 / MKV / TS / AVI / raw H.264 (bit-exact vs ffmpeg), display-order pts from the sorted packet times; JVT conformance test (48 streams bit-exact vs JM yuv, 4 refused); video/mp4 writer: a video edit list plays every frame (the B-frame delay no longer cut 2 frames off the end); tests tune LuaJIT through host
This commit is contained in:
1 parent
84101d919e
commit
7271e6e3fa
9 files changed
+266
-3
No files matched your search
+19
-1
@@ -80,7 +80,7 @@ def encode(ctx, tmp, name, src, w, h, n, params, extra):
|
||||
with open(out, "rb") as f:
|
||||
data = f.read()
|
||||
ref = os.path.join(tmp, name + ".yuv")
|
||||
ffmpeg(ctx, ["-threads", "1", "-i", out, "-f", "rawvideo", "-pix_fmt", "yuv420p", ref])
|
||||
ffmpeg(ctx, ["-threads", "1", "-i", out, "-fps_mode", "passthrough", "-f", "rawvideo", "-pix_fmt", "yuv420p", ref])
|
||||
with open(ref, "rb") as f:
|
||||
raw = f.read()
|
||||
fs = w * h + 2 * ((w + 1) // 2) * ((h + 1) // 2)
|
||||
@@ -164,6 +164,24 @@ def generate(ctx):
|
||||
"-x264-params", "threads=1", "-f", "h264", out])
|
||||
bad.append({"name": "10bit", "data": open(out, "rb").read(), "code": "UNSUPPORTED"})
|
||||
ctx.emit("h264_bad", bad)
|
||||
# containers: the same encodes written by ffmpeg into MP4 / MKV (avcC) and TS / AVI (Annex B), referenced by ffmpeg's decode of each file
|
||||
cont = []
|
||||
for name, params, n in (("cabac_b", "cabac=1:bframes=3:ref=3:8x8dct=1", 20), ("baseline", "cabac=0:bframes=0:ref=2", 12)):
|
||||
raw = os.path.join(tmp, "c_" + name + ".h264")
|
||||
ffmpeg(ctx, ["-f", "lavfi", "-i", SRC["noise"].format(w=176, h=144), "-frames:v", str(n), "-pix_fmt", "yuv420p",
|
||||
"-c:v", "libx264", "-x264-params", params + ":threads=1", "-f", "h264", raw])
|
||||
for ext in ("h264", "mp4", "mkv", "ts", "avi"):
|
||||
path = raw if ext == "h264" else os.path.join(tmp, "c_%s.%s" % (name, ext))
|
||||
if ext != "h264":
|
||||
ffmpeg(ctx, ["-f", "lavfi", "-i", SRC["noise"].format(w=176, h=144), "-frames:v", str(n), "-pix_fmt", "yuv420p",
|
||||
"-c:v", "libx264", "-x264-params", params + ":threads=1", path])
|
||||
yuv = path + ".yuv"
|
||||
ffmpeg(ctx, ["-threads", "1", "-i", path, "-fps_mode", "passthrough", "-f", "rawvideo", "-pix_fmt", "yuv420p", yuv])
|
||||
rawyuv = open(yuv, "rb").read()
|
||||
fs = 176 * 144 * 3 // 2
|
||||
cont.append({"name": name + "." + ext, "ext": ext, "data": open(path, "rb").read(), "width": 176, "height": 144,
|
||||
"frames": [zlib.crc32(rawyuv[i:i + fs]) for i in range(0, len(rawyuv), fs)]})
|
||||
ctx.emit("h264_containers", cont)
|
||||
bench = []
|
||||
for name, src, w, h, n, params in BENCH:
|
||||
data, frames = encode(ctx, tmp, name, src, w, h, n, params, [])
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# 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)
|
||||
Reference in new issue
Block a user