fix(gate): an already-playable source gets the 0.990 second tier - 0.995 and the size ceiling are mutually exclusive
Measured on 用超富集植物种植金属 (1280x720@30, 1832 kbps source, 96 s): crf 19 under -maxrate 1832k -> 20.6 MB, SSIM mean 0.99192 REFUSED crf 14 under the SAME ceiling -> 22.9 MB, SSIM mean 0.99195 five steps, +0.00003 crf 19 uncapped -> 40.6 MB, SSIM mean 0.99648 passes at 172% of the source Reaching 0.995 needs >=125% of the source's own bitrate, which SIZE_CEIL=1.0 forbids, so every gear below the ceiling produces the same file. Production: 487 FAIL quality rounds, 106.2 h of encoding; 194 of 202 files with two measured rounds moved < 0.0015. Rule (owner 2026-10-25): a source that already plays everywhere (h264+avc1, aac/mp4a, mp4/m4v/mov) is a space-reclaim job - the same situation SSIM_MEAN_MIN_REDO already rules on - so when 0.995 is missed it is accepted at SSIM_MEAN_MIN_FALLBACK (0.990), and the provably inert quality+2 retry is skipped. Unplayable sources keep 0.995; a frame-share defect is still refused at any tier. Also: numpy is now a declared dependency and its absence is an INSTALL PROBLEM, not a silent fallback - 305 of 418 production run logs were measured with the flat-frame scan skipped.
This commit is contained in:
1 parent
68a2265026
commit
57e950da8f
2 files changed
+67
-6
No files matched your search
+57
-4
@@ -202,6 +202,9 @@ def _flat_frames(raw_path, n, w=480, h=270, thresh=FLAT_LUMA_STD):
|
||||
|
||||
|
||||
SIZE_CEIL = 1.0 # output video bitrate must not exceed the source's
|
||||
CAP_BOUND_SHARE = 0.97 # an encode that spent >= 97% of the ceiling is no longer gear-limited:
|
||||
# below the ceiling a lower CRF buys bits, AT it the encoder is throwing
|
||||
# bits away, so the quality ladder stops being a ladder (owner 2026-10-25)
|
||||
QUALITY_STEPS = 2 # on a quality-gate failure, retry with the quality raised this many
|
||||
# steps (cq -2 / crf -2) before giving up; the retry only fires on a
|
||||
# file the cheaper setting could not carry
|
||||
@@ -764,7 +767,11 @@ def ssim_vs_source(src_local, out_local, info, workdir, tag, dur=SSIM_WINDOW):
|
||||
try:
|
||||
flat = _flat_frames(ref, n)
|
||||
except Exception as e: # numpy missing / unreadable raw: fall back to using every frame
|
||||
log(" ! flat-frame scan skipped: %s" % e)
|
||||
# This used to be one quiet line, and it silently changed what the verdict MEANS (measured
|
||||
# 2026-10-25: 305 of 418 production runs were measured without the exclusion). numpy is a
|
||||
# declared dependency now, so a failure here is a broken install and says so.
|
||||
log(" ! INSTALL PROBLEM: flat-frame scan skipped (%s) - numpy is missing from this install, "
|
||||
"so the picture verdict is measured WITHOUT excluding near-flat frames." % e)
|
||||
if flat and len(flat) < n * 0.5:
|
||||
vals = [v for i, v in enumerate(vals) if i not in flat]
|
||||
log(" %d near-flat source frame(s) excluded from the picture verdict (SSIM is "
|
||||
@@ -1247,6 +1254,20 @@ def dst_path_for(src, container="mp4"):
|
||||
return TR.out_path_for(src, container)
|
||||
|
||||
|
||||
def plays_everywhere(info, src):
|
||||
"""True when the file AS IT STANDS already plays on an iPad and on Android.
|
||||
|
||||
H.264 in an mp4-family container with AAC audio is the one combination both platforms decode
|
||||
natively - which is what decides whether a conversion's only remaining job is to reclaim disk
|
||||
space (`SSIM_MEAN_MIN_REDO`) or whether it is also a playability fix that must not be relaxed.
|
||||
"""
|
||||
if info["vcodec"] not in ("h264", "avc1"):
|
||||
return False
|
||||
if info["acodec"] not in ("aac", "mp4a"):
|
||||
return False
|
||||
return os.path.splitext(src)[1].lower() in (".mp4", ".m4v", ".mov")
|
||||
|
||||
|
||||
def already_hevc(src, info, container="mp4"):
|
||||
"""Self-describing resume test.
|
||||
|
||||
@@ -1444,6 +1465,27 @@ def process(src, args, dest=None, origin=None):
|
||||
mean_min = SSIM_MEAN_MIN_FALLBACK
|
||||
systematic = bad_share > MAX_BAD_SHARE or (
|
||||
mean is not None and mean < mean_min)
|
||||
# Owner decision 2026-10-25 - the SECOND TIER for a source that already plays
|
||||
# everywhere. Basis, measured on 用超富集植物种植金属 (1280x720@30, 1832 kbps source,
|
||||
# 96 s): crf 19 under the "never bigger" ceiling = SSIM 0.99192 at 87% of the source,
|
||||
# crf 14 under the SAME ceiling = 0.99195 (five quality steps moved the mean by
|
||||
# 0.00003, because `-maxrate` throws away every extra bit the lower CRF asks for),
|
||||
# while 0.995 needed 125% of the source's OWN bitrate - which this queue's promise
|
||||
# forbids. So for an H.264+AAC mp4 the conversion's only job is reclaiming disk, which
|
||||
# is the same situation `SSIM_MEAN_MIN_REDO` already rules on; the strict bar stays for
|
||||
# sources whose playability is the thing being fixed. The frame-share test above is
|
||||
# unchanged: a real defect is still refused at any tier.
|
||||
capped = bool(vbps) and obps >= vbps * SIZE_CEIL * CAP_BOUND_SHARE
|
||||
second_tier = False
|
||||
if (systematic and mean is not None and bad_share <= MAX_BAD_SHARE
|
||||
and mean >= SSIM_MEAN_MIN_FALLBACK and plays_everywhere(info, src)):
|
||||
second_tier, systematic = True, False
|
||||
note = ("second tier %.3f: the source already plays everywhere, so this is a "
|
||||
"space-reclaim job (mean %.4f, %s%.0f%% of the source video)"
|
||||
% (SSIM_MEAN_MIN_FALLBACK, mean,
|
||||
"capped " if capped else "", growth))
|
||||
log(" " + note)
|
||||
ssim_note += " ; " + note
|
||||
# Name the criterion that ACTUALLY failed, at the bar that applied to this item.
|
||||
# Both tests used to print the same "mean X < bar Y" template, so a frame-share
|
||||
# refusal was reported as a mean one - and "mean 0.9972 < bar 0.995" was written into
|
||||
@@ -1459,12 +1501,23 @@ def process(src, args, dest=None, origin=None):
|
||||
", " if why else "", 100.0 * bad_share, BAD_FRAME_SSIM,
|
||||
sstat.get("below", 0), nfr)
|
||||
if systematic:
|
||||
if q_off < QUALITY_STEPS and (attempt == 1):
|
||||
if q_off < QUALITY_STEPS and (attempt == 1) and not capped:
|
||||
q_off = QUALITY_STEPS
|
||||
log(" quality gate: %s - retrying at quality+%d" % (why, q_off))
|
||||
continue
|
||||
return ("FAIL quality: %s - systematic: %s%s"
|
||||
% (ssim_note, why,
|
||||
# Name the wall. For an already-playable source the second tier has ALREADY been
|
||||
# offered (the branch above), so a refusal here means even 0.990 was missed - and
|
||||
# the production record says the gear ladder cannot fix it: 194 of 202 files with
|
||||
# two measured rounds moved by < 0.0015, i.e. the ceiling ate the extra bits.
|
||||
tail = ""
|
||||
if plays_everywhere(info, src) and bad_share <= MAX_BAD_SHARE:
|
||||
tail = (" ; the second tier %.3f was not met either%s - no gear change can "
|
||||
"move this class (owner 2026-10-25)"
|
||||
% (SSIM_MEAN_MIN_FALLBACK,
|
||||
" (output already at the ceiling: %s%.0f%% of the source video)"
|
||||
% ("capped " if capped else "", growth)))
|
||||
return ("FAIL quality: %s - systematic: %s%s%s"
|
||||
% (ssim_note, why, tail,
|
||||
" (re-do of an already playable file)" if redo_playable else "")), None
|
||||
if lo is not None and lo < SSIM_TARGET:
|
||||
log(" %d scattered frame(s) below %.2f (%.2f%% of the window) with a healthy "
|
||||
|
||||
Reference in new issue
Block a user