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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
a197f16f04
commit
c49093c464
9 files changed
+266
-3
No files matched your search
+1
-1
@@ -28,7 +28,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| audio | vorbis | .ogg .oga | yes | yes | streaming: true, seek: true, lossy: true, channels: 255 | `tests/audio/vorbis.luau` |
|
||||
| audio | wav | .wav .wave .rf64 .bw64 | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, rf64: true | `tests/audio/wav.luau` |
|
||||
| video | avi | .avi | yes | yes | streaming: true, video: "mjpeg", "mpeg1", "rawvideo", audio: true, odml: true | `tests/video/avi.luau` |
|
||||
| video | h264 | .h264 .264 .avc .jsv .26l .jvt | yes | yes | streaming: true, video: "h264", depths: 8 | **missing** |
|
||||
| video | h264 | .h264 .264 .avc .jsv .26l .jvt | yes | yes | streaming: true, video: "h264", depths: 8 | `tests/video/h264.luau` |
|
||||
| video | mkv | .mkv .webm .mka .mk3d | yes | yes | streaming: true, remux: true, video: "vp8", "mjpeg", "mpeg1", "rawvideo", audio: true, subtitles: true | `tests/video/mkv.luau` |
|
||||
| video | mp4 | .mp4 .m4v .mov .qt .3gp .3g2 .mj2 | yes | yes | streaming: true, remux: true, video: "mjpeg", "mpeg1", "h264", audio: true, fragments: true | `tests/video/mp4.luau` |
|
||||
| video | mpegps | .mpg .mpeg .vob .m1v .mpv .dat | yes | - | streaming: true, video: "mpeg1", audio: true | `tests/video/mpegps.luau` |
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
| `src/Formats/codecs/SoundFont/` (Synth, the zone merging in Parse) | port of TinySoundFont v0.9 (tsf.h) by Bernhard Schelling, based on SFZero by Steve Folta | MIT: [TinySoundFont-LICENSE.txt](TinySoundFont-LICENSE.txt) |
|
||||
| `src/Formats/codecs/Vp8/` inter frames (Decode: inter headers / modes / motion vectors / references, Predict, the inter tables in Tables) | Luau translations of libvpx 1.17 (WebM Project): vp8/decoder/decodeframe.c, decodemv.c, onyxd_if.c; vp8/common/findnearmv.c, reconinter.c, filter.c, vp8_loopfilter.c, entropymode.c, entropymv.c, modecont.c | BSD-3-Clause + patent grant: [libvpx-LICENSE.txt](libvpx-LICENSE.txt) |
|
||||
| `tests/fixtures/vp8video/vp80-*.ivf` | the VP8 test vectors of the libvpx test data (vp80-00-comprehensive-001..018 and others) | WebM Project, BSD-3-Clause + patent grant: [libvpx-LICENSE.txt](libvpx-LICENSE.txt) |
|
||||
| `src/Formats/codecs/H264/` (Tables: CAVLC / CABAC / deblocking / scaling constant tables of ITU-T H.264, extracted from openh264 sources; the decoder itself is written from the spec) | openh264 2.x (Cisco) | BSD-2-Clause: [openh264-LICENSE.txt](openh264-LICENSE.txt) |
|
||||
| `tests/gen/h264_jvt` (downloaded at fixture time, not committed) | ITU-T H.264.1 / JVT conformance bitstreams (itu.int) | ITU-T test data |
|
||||
|
||||
Ports of third-party code (minimp3, stb_vorbis, libopus, ...) add a row here and their upstream licence text in this
|
||||
folder (see docs/STYLE.md, "Absorbing an existing repo").
|
||||
@@ -199,7 +199,7 @@ end
|
||||
-- ------------------------------------------------------------------------------------------------ video layer
|
||||
-- newVideoDecoder(track, opts?) -> a Types.VideoCodecDecoder (the codecs/Video registry entry for "h264"):
|
||||
-- track.config = avcC (MP4 / Matroska; packets length-prefixed) or nil (Annex B packets: MPEG-TS, AVI, raw .h264).
|
||||
-- Pictures come out in display order with the pts of the packet that carried them; a track with
|
||||
-- Pictures come out in display order with the packet timestamps sorted (display order); a track with
|
||||
-- `ptsInOutputOrder` (raw Annex B, no timestamps) numbers them in output order instead.
|
||||
function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?)
|
||||
local o: Options = { maxPixels = opts and opts.maxPixels, deblock = opts and opts.deblock, lowDelay = opts and opts.lowDelay }
|
||||
@@ -218,6 +218,7 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
|
||||
return nil, err
|
||||
end
|
||||
local queue: { any } = {}
|
||||
local pool: { number } = {}
|
||||
local outIndex: number? = if track.ptsInOutputOrder then 0 else nil
|
||||
local self: any = {}
|
||||
local function push(frames: { Frame })
|
||||
@@ -226,6 +227,10 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
|
||||
if track.ptsInOutputOrder then
|
||||
pts = outIndex or 0
|
||||
outIndex = pts + 1
|
||||
elseif #pool > 0 then
|
||||
-- pictures leave in display order: they take the packet timestamps in increasing order (right for
|
||||
-- MP4 / MKV / TS pts, and for AVI whose packets only carry decode-order times)
|
||||
pts = table.remove(pool, 1)
|
||||
end
|
||||
table.insert(queue, { f.image, pts, f.keyframe })
|
||||
end
|
||||
@@ -237,6 +242,13 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
|
||||
if outIndex == nil and track.ptsInOutputOrder then
|
||||
outIndex = packet.pts
|
||||
end
|
||||
if packet.pts ~= nil and not track.ptsInOutputOrder then
|
||||
local i = #pool
|
||||
while i > 0 and pool[i] > packet.pts do
|
||||
i -= 1
|
||||
end
|
||||
table.insert(pool, i + 1, packet.pts)
|
||||
end
|
||||
local frames, e = (dec :: H264Decoder):decode(packet.data, packet.pts)
|
||||
if not frames then
|
||||
return e
|
||||
@@ -259,6 +271,7 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
|
||||
function self.reset(_: any)
|
||||
dec = make()
|
||||
table.clear(queue)
|
||||
table.clear(pool)
|
||||
if track.ptsInOutputOrder then
|
||||
outIndex = nil
|
||||
end
|
||||
|
||||
@@ -264,10 +264,20 @@ function Mp4.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
if s.kind == "audio" and s.track and s.track.codecDelay and s.copied then
|
||||
skip = math.floor(s.track.codecDelay * scale + 0.5)
|
||||
end
|
||||
-- video: the skipped decode delay is a composition shift, every frame still plays (ffmpeg drops the frames an
|
||||
-- edit cuts); audio: the codec delay samples are not played
|
||||
local playDuration = nil
|
||||
if s.kind == "video" and skip > 0 then
|
||||
playDuration = 0
|
||||
for _, d in durations do
|
||||
playDuration += d
|
||||
end
|
||||
end
|
||||
local t: any = {
|
||||
kind = s.kind,
|
||||
timescale = scale,
|
||||
skip = if skip > 0 then skip else nil,
|
||||
playDuration = playDuration,
|
||||
samples = samples,
|
||||
durations = durations,
|
||||
cts = if anyCts then cts else nil,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
-- samples) and NAL-at-a-time paths; pts propagation; UNSUPPORTED streams (interlaced, 4:2:2, 4:4:4, 10-bit); error
|
||||
-- codes; and the fuzz no-throw pass. Fixtures: tools/fixtures/h264.py.
|
||||
local T = require("@tests/T")
|
||||
require("@formats/host") -- LuaJIT: the trace limits the api sets (host/init.luau)
|
||||
local H264 = require("@formats/codecs/H264")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
-- codecs/H264 conformance: a selection of the ITU-T H.264.1 (JVT) conformance bitstreams (Baseline / Main / Extended
|
||||
-- without SP / High: CAVLC, CABAC, B frames, weighted prediction, multiple slices, MMCO / long-term references,
|
||||
-- frame_num gaps, cropping, PCM, 8x8 transforms, scaling matrices, ...) decoded bit-exact against the reference
|
||||
-- decoder's yuv (JM, shipped in each zip; ffmpeg where there is none), and interlaced / SP / 4:2:2 streams refused
|
||||
-- with UNSUPPORTED. Fixtures: tools/fixtures/h264_jvt.py (downloaded from itu.int; skipped when unreachable).
|
||||
local T = require("@tests/T")
|
||||
require("@formats/host") -- LuaJIT: the trace limits the api sets (host/init.luau)
|
||||
local H264 = require("@formats/codecs/H264")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Base64 = require("@formats/core/Base64")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Cases = require("@tests/gen/h264_jvt")
|
||||
|
||||
local t = T.suite("h264 conformance")
|
||||
local streams, nframes, refused = 0, 0, 0
|
||||
for _, c in Cases do
|
||||
local data = Base64.decode(c.data64) :: buffer
|
||||
local frames, err = H264.decodeAll(data)
|
||||
if c.expect == "UNSUPPORTED" then
|
||||
t:check(frames == nil and err and err.code == Err.UNSUPPORTED, c.name .. ": UNSUPPORTED (" .. tostring(err) .. ")")
|
||||
refused += 1
|
||||
else
|
||||
t:check(frames, c.name .. ": " .. tostring(err))
|
||||
t:eq(#frames, #c.frames, c.name .. ": frame count")
|
||||
local good = 0
|
||||
for i, f in frames do
|
||||
if Crc32.of(f.image.pixels) == c.frames[i] then
|
||||
good += 1
|
||||
end
|
||||
end
|
||||
t:eq(good, #c.frames, c.name .. ": bit-exact with the " .. c.ref .. " reference")
|
||||
streams += 1
|
||||
nframes += good
|
||||
end
|
||||
end
|
||||
t:note("%d conformance streams (%d frames) bit-exact, %d refused as UNSUPPORTED%s", streams, nframes, refused, if #Cases == 0 then " (fixtures unavailable: no download)" else "")
|
||||
t:done()
|
||||
@@ -0,0 +1,100 @@
|
||||
-- video/h264 tests: H.264 through F.video.open end to end: raw Annex B (.h264, the video/h264 format), MP4 and MKV
|
||||
-- (avcC + length-prefixed samples) and MPEG-TS / AVI (Annex B packets) written by ffmpeg / libx264, frames bit-exact
|
||||
-- against ffmpeg's decode of each file; display-order timestamps; the raw writer (MP4 -> .h264) read back; sniffing;
|
||||
-- the fuzz no-throw pass on the raw demuxer. Fixtures: tools/fixtures/h264.py (h264_containers).
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Fmt = require("@formats/video/h264")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Cases = require("@tests/gen/h264_containers")
|
||||
|
||||
local t = T.suite("video/h264")
|
||||
t:eq(Fmt.name, "h264", "name")
|
||||
|
||||
local function frames(v: any): ({ any }, any)
|
||||
local out = {}
|
||||
while true do
|
||||
local f, err = v:nextFrame()
|
||||
if not f then
|
||||
return out, err
|
||||
end
|
||||
table.insert(out, f)
|
||||
end
|
||||
end
|
||||
|
||||
local byName = {}
|
||||
for _, c in Cases do
|
||||
byName[c.name] = c
|
||||
local v, err = F.video.open(c.data)
|
||||
t:check(v ~= nil, c.name .. ": F.video.open " .. tostring(err))
|
||||
if v then
|
||||
t:eq(v.codec, "h264", c.name .. ": codec")
|
||||
local got, ferr = frames(v)
|
||||
t:check(ferr == nil, c.name .. ": no decode error " .. tostring(ferr))
|
||||
t:eq(#got, #c.frames, c.name .. ": frame count")
|
||||
local good, mono = 0, true
|
||||
for i, f in got do
|
||||
if Crc32.of(f.image.pixels) == c.frames[i] then
|
||||
good += 1
|
||||
end
|
||||
if i > 1 and f.pts <= got[i - 1].pts then
|
||||
mono = false
|
||||
end
|
||||
end
|
||||
t:eq(good, #c.frames, c.name .. ": frames bit-exact with ffmpeg")
|
||||
t:check(mono, c.name .. ": display-order timestamps increase")
|
||||
t:check(got[1] and got[1].image.meta.yuv and got[1].image.meta.yuv.range == "limited", c.name .. ": meta.yuv")
|
||||
local rgba = got[1] and v:toRGBA(got[1])
|
||||
t:check(rgba and rgba.format == "rgba8" and rgba.width == c.width, c.name .. ": toRGBA")
|
||||
end
|
||||
end
|
||||
|
||||
-- raw format directly: sniff, demux, 25 fps output order
|
||||
do
|
||||
local c = byName["cabac_b.h264"]
|
||||
local r = Bytes.reader(buffer.fromstring(c.data))
|
||||
t:check(Fmt.sniff(r) >= 0.5, "sniff a raw stream")
|
||||
t:check(Fmt.sniff(Bytes.reader(buffer.fromstring(byName["cabac_b.mp4"].data))) == 0, "sniff rejects MP4")
|
||||
local dmx = Fmt.demux(r)
|
||||
t:check(dmx and dmx:count(1) == #c.frames, "one packet per access unit")
|
||||
local v = Fmt.open(Bytes.reader(buffer.fromstring(c.data)))
|
||||
local got = frames(v)
|
||||
t:check(#got == #c.frames and math.abs(got[2].pts - 1 / 25) < 1e-9, "raw: pts in output order at 25 fps")
|
||||
end
|
||||
|
||||
-- writer: the MP4's H.264 track as a raw Annex B stream, decoded again
|
||||
for _, src in { "cabac_b.mp4", "baseline.mkv", "baseline.ts" } do
|
||||
local c = byName[src]
|
||||
local v = F.video.open(c.data)
|
||||
local out, err = F.save(v, nil, { format = "h264" })
|
||||
t:check(out ~= nil, src .. " -> h264: " .. tostring(err))
|
||||
if out then
|
||||
local v2 = F.video.open(out)
|
||||
t:check(v2 ~= nil and v2.format == "h264", src .. " -> h264: reads back as raw H.264")
|
||||
local got = frames(v2)
|
||||
local good = 0
|
||||
for i, f in got do
|
||||
if Crc32.of(f.image.pixels) == c.frames[i] then
|
||||
good += 1
|
||||
end
|
||||
end
|
||||
t:eq(good, #c.frames, src .. " -> h264: frames bit-exact")
|
||||
end
|
||||
end
|
||||
|
||||
-- fuzz: the raw demuxer + decoder
|
||||
local samples = { byName["baseline.h264"].data, byName["cabac_b.h264"].data }
|
||||
t:fuzz("open + frames", function(b: buffer)
|
||||
local v = Fmt.open(Bytes.reader(b), { maxPixels = 2 ^ 18 })
|
||||
if v then
|
||||
for _ = 1, 40 do
|
||||
if not v:nextFrame() then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return v
|
||||
end, samples, { mutations = 8, keepHeader = 30 })
|
||||
|
||||
t:done()
|
||||
+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