Commit Graph
60 Commits
Author SHA1 Message Date
hoelee 005b824e4f fix(verify): AAC 从 TS 换封装到 MP4 不是掉包,别再判 payload differs
MPEG-TS 里的 AAC 是 ADTS 帧(每帧 7 字节头),MP4 存同样的帧但不带头、配置进
AudioSpecificConfig。`-f data` 直接把包负载吐出来,于是同一条音轨、同一个包数
(实测 157137 / 157137)却被判 `a 0: payload differs (src .../342d39a4, out .../38f9b7e6)`,
一份好片被记成 infra 失败、退避三次后进 #block-infra。

实测(KODV-0081.ts / 20 s 窗口):
  raw    src=87f3e5b6  out=955905a0   不一致 -> 假阳性
  bsf    src=955905a0  out=955905a0   一致
  pcm    src=d86dbbed  out=d86dbbed   一致
故两边都过 `-bsf:a aac_adtstoasc`(TS 侧剥 ADTS 头,MP4 侧无操作)。编解码器从
ffprobe 现读(`plan_` 里的 codec 是「copy」动作名,不是流的真实编码)。
截断的副本仍然被拒,测试里两条都钉住了。
2026-10-30 02:58:56 +08:00
hoelee 0e5c74e5b5 fix(install): 抽样函数改成三返回值后,安装段还在按两值解包 —— 每一件过门禁的好片都在安装前一秒崩
`_sha_sample()` 为了支持五窗口抽样改成返回 (指纹, size, 实读字节),安装段
`smp_loc, smp_n = _sha_sample(...)` 没跟着改,于是抛
`ValueError: too many values to unpack (expected 2, got 3)`,
被队列判成 `infra: 引擎跑完了,但一个闸门数字都没产出`,退避三次后转 failed:
队列看起来什么都没完成,而日志里 SSIM 明明是过的。

实测三例:gpu 2169 KODV-0081.ts(4 infra -> failed)、cpu 3297 GOD-076.avi、
cpu3 3405。`_sha_remote_sample` 仍是两值(指纹, 实读字节),四个调用点都对得上。
2026-10-30 02:13:23 +08:00
hoelee 94350f18b3 fix(mux): -disposition 只对 MP4 写;hev1 源原地降级为 copy 重封装
顾问 Q-16 / Q-17(轮次 3 裁定):

- tracks.py::ffmpeg_args 的 -disposition 回写整块包进 container=="mp4"。
  不传时 matroska muxer 会从输入流继承整条 disposition 掩码(original/comment/
  hearing_impaired…),而 plan() 只提取 default/forced —— 显式传就是用单一标志
  覆盖整条掩码,抹掉 MKV 保真标记
- library_run.py::encode 在 tier_for_bpp 之后加一个分支:mp4 + hevc + tag!=hvc1 +
  yuv420p + 时间轴健康 → 直接 tier="copy"。走 -c:v copy -tag:v hvc1 无损重封装
  (copy 档本就跳过 SSIM),不再为一颗标签重编整片
2026-10-30 02:00:34 +08:00
hoelee 8b3d979eb3 fix(io): 共享盘读不再无超时 —— 准备阶段流式哈希、回读改三段抽样
8 小时的车道挂死发生在 copy_remote_to_local() 之后的整文件网络重读校验上
(暂存档 9 秒就拷满 842,854,400 B,进程 8 小时 CPU 只有 2.52 s,线程停在
Wait/Executive)。同一个文件在几秒内被 SMB 读第二遍,对 RaiDrive/Dokan 是纯风险。

- copy_remote_to_local(): 边读边喂 sha256,拷完与本地暂存档比对,
  删掉准备阶段的 _sha_remote(src) 整文件重读。证据强度不降(仍证明本地副本
  == 共享盘服务的字节),远程读流量减半。
- 上传/安装回读: _sha_remote() → _sha_remote_sample(),严格 size + 首/中/尾
  各 8 MB(24 MB 证据)。三类真实损坏(截断、moov/cues 未刷、零填充)都会
  改变抽样窗口。
- copy 档补 -tag:v hvc1: 原来 tag 挂在 color_metadata_args 里,被
  `if tier != "copy"` 整段跳过,HEVC 源 remux 成 mp4 会写成 hev1 ——
  iPad 拒播,而且下次扫描的「已达标跳过」判据命不中。
- tracks: disposition 回写(default/forced),没有标记也显式写 0。
- transcode.probe(): 从 side_data_list 读出 Dolby Vision profile /
  mastering display / max-CLL,新增 dv/mdm/cll 三个键。
- DV 源一律 SKIP 拦截(Profile 5 的 IPT-PQ-C2 不被 libx265 识别,裸编会
  偏绿/偏紫,而安装成功会删源 = 不可逆);HDR10 静态元数据能读到就透传。
- 位图字幕(PGS/VOBSUB)进不了 MP4 时整项拦下,不再静默丢弃。
2026-10-30 01:20:22 +08:00
hoelee fc3d1ff022 fix(tracks): ffprobe / ffmpeg 子进程统一 CREATE_NO_WINDOW
Windows 上每次探测轨道、取流摘要都会闪一个黑窗(命令行窗口),
批量扫描几百个文件时尤其明显。ffprobe 的 subprocess.run 与
_stream_digest 的 ffmpeg Popen/run 全部加 creationflags=NOWIN,
与 library_run.py / transcode.py 的既有做法保持一致。

scripts.test_tracks 55/55。
2026-10-29 08:03:18 +08:00
hoelee e66551200f fix(install): rename 到幽灵名失败时改用「直写最终名 + 回读 sha256」
实测(2026-10-28, Z:\Temporary\短视频\_io-test):.mov → .mp4 装不进去,三次都死在
os.replace('…new.mp4','…hevc-pcm.mp4') 的 WinError 32,而同一目录手搓 os.replace 全成功 ——
是幽灵条目:os.path.exists 说存在、ls 同一目录看不到,服务端已忘记该名字,任何 rename 都失败。

- 先按「短暂占用」重试 5 次退避(实测无效,5 秒内全失败)
- 最终处理:还剩本地已验证产物,就直接写到最终名并回读 sha256 比对,再清 staged 名
实测:19 MB -> 18 MB (93%) | copy,audio=aac、video md5 与源逐位相同。

同时把这条 .mov 样本的 io 链路跑通(前两轮分别是 win32 占用与幽灵名),
三条样本现在全部 hevc hvc1 + aac mp4a。
2026-10-28 22:24:29 +08:00
hoelee 6950f75d26 fix(copy): --overwrite 现在真的生效 —— 已是 HEVC hvc1 但音轨非 AAC 时重封音轨而不是 SKIP
--overwrite 从加进 argparse 起就没被读过(只在 help 里)。控制面换了规则之后需要一个
「视频没问题、这条仍要跑」的开关:kind="audio" 的行(hevc + ac3/mp3/pcm)在 copy 挡位
只能被 SKIP,结果是控制面把行标成 done 而音轨一条没动。

audio_only_remux = args.overwrite and acodec not in (aac, mp4a, "") → 不吃 already_hevc 的
SKIP,走正常 copy 流程;实测输出 video md5 与源逐位相同、audio 转成 aac。
2026-10-28 22:02:07 +08:00
hoelee 64a80d2234 fix(gate): the space-reclaim class is about the PICTURES, not the audio codec
An h264 mp4 with an mp3 track was excluded from the 0.990 second tier, but encode() already
re-encodes non-AAC audio to AAC in the same pass (-c:a aac -b:a <source kbps>), so that track is
fixed whichever picture bar applies. Holding the PICTURE to 0.995 because of it is exactly the
rule that the size ceiling makes unreachable. Renamed plays_everywhere -> space_reclaim_source
to say what it actually decides (owner 2026-10-25: 「把音轨转 AAC 后也按二档跑」).
2026-10-25 04:32:18 +08:00
hoelee 57e950da8f 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.
2026-10-25 03:58:02 +08:00
hoelee 68a2265026 fix(tracks): honour TRANSCODE_FFPROBE instead of the bare name
packaged builds ship ffmpeg inside their own tree; tracks.py called `ffprobe` by
bare name, which only resolved because this host has ffmpeg on PATH. The bundle
acceptance strips PATH on purpose, so probe() raised FileNotFoundError [WinError 2]
two seconds into the item and the queue logged it as a quality refusal.
Mirror transcode.py:36-37 (TRANSCODE_*/RT_* with a bare fallback).
2026-10-24 08:53:39 +08:00
Hermes Agent f088ae78e3 feat(tracks): carry every audio track, subtitle and font attachment
MP4 (default) keeps the 'opens anywhere' promise: all audio tracks become AAC at the
source's own channel layout (5.1 stays 5.1), text subtitles become mov_text, bitmap
subtitles are skipped with a logged note, font attachments are not carried.
container=mkv is the explicit fidelity mode: every audio/subtitle/attachment stream is
copied bit-for-bit, chapters and tags ride along.

New scripts/tracks.py holds the pure plan + the container-aware gate; library_run.py
uses it for mapping, per-track codecs, container extension, install-path names and the
hvc1 check (Matroska has no codec tag). Capability report gains container/audio_downmix/
subs and 'containers' (contract 3, version 1.2.0).

Verified: scripts/test_tracks.py 55/55 (both containers end to end, per-packet md5),
plus two real library_run.py runs (MP4 3x AAC incl. 6ch + 2x mov_text; MKV bit-exact).
2026-10-24 03:56:30 +08:00
hoelee 72a8971d3f chore: ignore .codegraph/ index directory 2026-10-23 02:05:48 +08:00
hoelee 9c0e8b1eb1 feat(color): 10-bit 色深透传与 Rec.709/HDR 色彩空间元数据保持 (Q-20 B项) 2026-10-18 17:06:28 +08:00
hoelee b36681bda2 文档:队列仓计划档已归档到 docs/archive/,STATE.md 的路径同步 2026-10-14 13:44:50 +08:00
hoelee 83f9cbc48f Batch 4b-1:引擎新增 tier qsv(自己的锁 + -global_quality + 整数 preset + nv12)
- 新 tier `qsv`:--tier/--force-tier 的 choices 加 qsv,锁是 run-qsv.lock(两个不同 ASIC 不共用一把
  硬件规则锁),命令 -c:v hevc_qsv -preset <本 build 整数 7..1> -global_quality <q> -pix_fmt nv12;
  不加 -maxrate(ICQ 模式下 MaxKbps 是否生效取决于 MFX 版本,本机无法验证;编码后的「不得超源码率」
  断言仍在)。
- QSV_PRESET_ENUM + qsv_preset_value():三个 tier 收同一批 preset 词,引擎翻译成本 build 的整数。
- BACKEND_INIT_PATTERNS + backend_failure():ffmpeg 非 0 退出时把「后端没起来」认出来,状态写成
  FAIL backend qsv unavailable: …(不是 FAIL ffmpeg rc=、不是 FAIL quality)。
- main() 守卫:--tier qsv 缺 --qsv-quality/--qsv-preset 就在任何运行准备之前退出非 0(两个旋钮故意
  无默认值:本机没有 Intel 硬件,写死的数字就是编的)。
- capabilities:CAPABILITIES_VERSION 1→2、__version__ 1.1.0;quality_knobs 取值改从 QUALITY_KNOB_OPTIONS
  派生(5a 手写的键名正好漏了 qsv_preset)。
- scripts/test_qsv_tier.py 25 例(含 x265/nvenc 整条 argv 的逐字回归);test_capabilities.py 42/42。
2026-10-14 11:40:29 +08:00
hoelee b69c52135e Batch 5a: library_run.py 自报能力(--capabilities --json)
- 新增 --capabilities(人读)/ --capabilities --json(一行 ASCII JSON),在任何运行准备之前返回:
  不做 stage 清道夫、不 mkdir、不加锁、不写台账。
- 契约字段全部从真的 argparse parser 与真的常量读出来(新增 build_parser(),main() 改为调用它):
  tiers 取自 --tier 的 choices、defaults.crf/cq 取自 parser default、locks.template 取自 main() 真正
  使用的 LOCK_TEMPLATE(新常量,两处共用)。加/删参数,自报自动跟随。
- 形状:entry / version / contract / tiers / flags{work_dir,stage_dir,dest,keep_source,lock_tag} /
  quality_knobs{crf,cq,qsv_quality,x265_preset,nvenc_preset} / defaults{work,root,crf,cq,x265_preset,
  nvenc_preset} / locks{template,tags};CAPABILITIES_VERSION=1,__version__=1.0.0。
- 纯加法:不带该参数时行为一字未差(同源 --dry-run 输出与 HEAD 逐字相同)。
- scripts/test_capabilities.py:38/38 PASS(含「自报为真的参数必须真被 argparse 接受」)。
2026-10-14 11:07:52 +08:00
hoelee 6126ad5c2c Batch 3a: library_run.py 支持 --work-dir(工作根可指定,默认常量不变)
_apply_work_dir() 在 argv 解析后重绑 WORK/STAGE/LEDGER/LOCKF/POLICY;--stage-dir 仍只覆盖暂存。
不传 --work-dir 时行为与以前逐位一致(控制面 docs/DESIGN.md §18 是规则出处)。
STATE.md 记录本轮。验收:控制面 scripts/acceptance_work_dir.py 真跑 copy 档 PASS 8/8,
控制面 124 用例 OK。回滚点 tag pre-batch3a。
2026-10-13 22:06:16 +08:00
hoelee d5b430f275 docs: 控制面路径改名 -> D:\dev\hevc-transcode 2026-10-13 21:58:41 +08:00
hoelee 26661391b3 docs(STATE): 表头日期更新 + 「现在在跑什么」改为以控制面为准(并标注 cpu 组暂停态) 2026-10-13 00:37:18 +08:00
hoelee 0a1f108090 docs(STATE): 2026-10-13 交接(闸门配对修复 / preset 实测 / 子进程亲和真相 / run_pinned 事故) 2026-10-13 00:36:39 +08:00
hoelee 5e27edef16 改: NVENC 默认 preset p6 -> p7(业主决定)
GPU ASIC 有余量,同一 cq 下每升一档体积更小;x265 保持 medium(三个 worker 并行时 CPU 是瓶颈)。
两个 preset 都可由控制面用 --x265-preset / --nvenc-preset 覆盖,常量只是手跑时的回落值。
2026-10-12 23:32:00 +08:00
hoelee 767fa3ac08 修: 对齐修好了配对,判决却用旧配对的帧占比(0912 洞见 假拒绝)
洞见在 crf 24 上被判 'mean 0.9974 但 20/1199 帧低于 0.85' → 拒。实测: 0.9974/0.9936 是对齐后的数字,
而 20 帧是直配的旧计数 —— 两个数字来自不同配对。三向对照测试(本地,同一 60 s 窗口):
  健康对     min 0.9940 mean 0.9971 0 坏帧 → 走快路径(无对齐搜索),通过 ✓
  错位对     'alignment repaired the pairing: 20 frame(s) below 0.85 before, 0 after'
             min 0.9940 mean 0.9972 1199 帧 0 坏帧 → 通过 ✓ ← 与洞见判决书 20/1199 逐项吻合
  真缺陷对   mean 0.9612 151 帧(10.07%) → 仍被拒 ✓(没变橡皮章)
改动:
  - 触发条件补上帧占比: 原来只看 min<0.985 / mean<0.995,帧占比超标不触发搜索;
  - _paired_ssim / _perframe_best 现在返回 below 计数,并同样剔除近平坦帧(之前对齐后的数字
    含黑场帧,会让对齐看起来比直配还差);
  - 采用对齐结果时同步更新 stats['below'](判决用的就是它),并打印 'X frames below before, Y after'。
2026-10-12 21:44:57 +08:00
hoelee eb4b0bd26f 修: run_pinned 把 capture_output 传给 Popen 导致 TypeError
subprocess.run 的 capture_output 是它的语法糖,Popen 不认这个参数 → run()/_sh 这三个
ffmpeg 调用点全炸,三个 lane 在 2.5 分钟内秒失败 64 项(每项 attempts 用光变 failed)。
补上展开: capture_output=True → stdout/stderr=PIPE。本地与生产均已复验 rc=0。
2026-10-12 18:51:02 +08:00
hoelee 61d41707e9 修: 子进程重钉 + 认识 Windows 不继承 affinity 的事实
pin_child()/run_pinned() 在每次 spawn 后尽力钉住子进程(含 SSIM/VMAF 闸门解码),
但实测 ffmpeg/x265 会拒绝外部 SetProcessAffinityMask(ACCESS_DENIED),真正生效的是控制面
给引擎所在 Job Object 设的亲和限(后代在创建时继承 job)。注释写明这条事实,别再指望继承。
2026-10-12 18:42:02 +08:00
hoelee c45cdda983 engine: 新增 --lock-tag,允许同一 tier 的第二个 runner 拿自己的锁并行
锁本来是按 tier 的(run-x265.lock),这是防两个编码器抢同一单元的正确默认值;
但当单进程吃不满机器时(720p x265 = wpp(12 rows),pools=22 实测 165 fps、整机 73%),
控制面要拆核并行两个 x265:第二个 runner 必须有自己的锁名,否则永远退避在 engine lock busy。
--lock-tag x265-w2 → run-x265-w2.lock,留空 = 旧行为。references/pitfalls.md 补第 13 条。
2026-10-12 17:17:50 +08:00
hoelee 0287dcd2f6 library_run: fix the affinity pin (it never applied), parametrise mask/pools/stage, name the real refusal
Three changes, each from a measured failure on 2026-10-12:

  * pin_to_e_cores(mask) - the old code called ctypes' GetCurrentProcess() without declaring a
    restype, so the pseudo-handle -1 was truncated to 32 bits and SetProcessAffinityMask failed with
    ERROR_INVALID_HANDLE; since the call's return value was never inspected it logged
    "E-core pinning: on" while the process kept every CPU (read back: 0x3FFFFFF = all 26 CPUs).
    Now the prototype is declared, the mask is a parameter (--affinity-mask, default unchanged) and
    the log prints the mask READ BACK from the kernel.
  * --stage-dir: scratch can live on another drive; the ledger, the locks and gate_policy.json stay in
    WORK (records, not cache).
  * the quality gate now says WHICH criterion failed. Both tests shared one "mean X < bar Y" template,
    so a frame-share refusal was filed as a mean one - ledger example: "ssim min 0.9917 mean 0.9972
    (1199 frames) ... systematic: mean 0.9972 < bar 0.995, 1.67% of frames below 0.85" (0912 洞见),
    a healthy mean refused by the share test. The distinction decides the fix: a mean shortfall
    answers to a higher CRF, a frame-share defect does not.

Engine defaults are unchanged: a standalone run behaves exactly as before.
2026-10-12 11:23:47 +08:00
hoelee 7038c54a33 STATE: 2026-10-12 handoff - D-07 open (crf29 fails on the bpp>0.05 band), mech-universe is a source defect not a quality one, stage cleanup in place 2026-10-12 10:17:59 +08:00
hoelee 243d406df0 stage cleanup: purge each item's gate artefacts, sweep dead leftovers, state bug 13
Every item left its SSIM windows (291 MB each), per-offset pairs, VMAF pairs and stats logs behind;
anything killed mid-item left them for ever. Measured 2026-10-12: 6 windows + 123 gate logs, work
drive at 3.9 GB, both lanes idle on the guard. process() now purges its own tag/pid artefacts in the
finally, and sweep_stage() clears leftovers older than STAGE_MAX_AGE_H while skipping any tag that has
a fresh <tag>_out.mp4.err (i.e. is encoding right now). Regression: scripts/test_stage_cleanup.py.
2026-10-12 09:25:14 +08:00
hoelee 2bf48ee8ec STATE: bugs 11 (pythonw console popup per ffmpeg child) and 12 (a running engine reverted an owner's park release); the queue is the only place that starts encodes now 2026-10-11 14:32:27 +08:00
hoelee eaad2828fa gate_policy: read-modify-write the park counters (an owner edit must survive a running engine)
Measured 2026-10-11: an item parked at 2 rounds was released by the owner (park entry deleted) so it
could be retried at a lower crf - and the very next failure of ANOTHER item restored the entry, from
the stale in-memory snapshot of the engine that had loaded the file before the edit. The released
item was then SKIPped as parked. save_policy now re-reads the file and writes only the counters this
process bumped (POLICY_DIRTY), so a deleted park entry or an added accept entry survives.

Regression: scripts/test_policy_merge.py (4 checks: released item stays released, external accept
entry kept, counter reaches disk, and the old behaviour would have restored it).
2026-10-11 14:08:08 +08:00
hoelee cb6c5f644e engine children: pass CREATE_NO_WINDOW on every ffmpeg/ffprobe spawn
The queues run the engines under pythonw.exe (no console). A console-subsystem child spawned by a
console-less parent without CREATE_NO_WINDOW makes Windows allocate a NEW console and SHOW it - one
visible window per ffprobe/ffmpeg call (measured 2026-10-11: Windows Terminal windows titled with the
ffmpeg binary while two encodes ran).

Fixed: transcode.run(), library_run.run()/run_watched() and the three gate helpers that call ffmpeg
directly (SSIM filtergraph, per-offset pairs, VMAF).

Proof (cache/scratch/nowin_test4.py, run in a DETACHED pythonw: GetConsoleWindow()==0, like the
engine): raw Popen without the flag -> 1 new visible console window; with the flag -> none) -> 0;
transcode.run() -> 0 windows, library_run.run() -> 0, library_run.run_watched() -> 0.
2026-10-11 13:56:54 +08:00
hoelee 2a2fcb5867 state: 2026-10-11 handoff - the gate alignment defect, the new bars, VMAF observe-only 2026-10-11 13:29:57 +08:00
hoelee 7d16fedea5 gate: find the real frame offset (step 1, both directions, per-frame fallback) and stop the alignment note from bypassing the verdict
The SSIM gate compared frame i with frame i of the other file. Measured 2026-10-11 on two
installed outputs: -fps_mode cfr inserts a duplicate wherever a frame is dropped, so the whole
window sits at a constant -1 frame; the old sweep stepped by 10 (it could never see +-1) and its
max(0, off) seek made every NEGATIVE offset identical to 0. Cost: 14 items refused in 9.6 h
(12.4 h of lane time, then parked) while healthy encodes read 0.9808/0.9862 instead of
0.9976/0.9974.

* alignment: fine step-1 +-6 -> coarse step-10 +-100 -> per-frame +-2 best match, each stage named
  in the verdict, PID-tagged temp files (two lanes share the stage dir), pair stats logs pruned
* the alignment note is INFORMATION now: it used to arrive in the irregular-timeline slot, which
  skips the whole picture verdict - the canary and two x265 items were accepted that way with the
  mean bar never enforced
* a window decode that fails is retried once and its ffmpeg stderr is kept (a transient decode
  killed a finished 16.7-minute encode with a bare 'no frames compared'); gate decodes get their
  own 60-minute stall window because trim writes nothing before the window starts; the ssim filter
  and the pair comparisons are time-bounded so a wedged ffmpeg cannot hang a lane
* bars (owner decision): mean 0.995, redo/owner-released 0.990
* VMAF, observe-only and reported as vmaf480 because the window is the 480x270 one the gate already
  decoded (480p reads ~+2.4/+3.2 points above native on the item measured) - the evidence base for
  a threshold is two items, so it accumulates instead of gating
2026-10-11 13:19:13 +08:00
hoelee febefe806f library_run: --force-tier (explicit override of the bpp rule) for the control plane
An owner decision can say a LEAN source is still worth re-encoding (measured: x265 crf27 lands at
33-53% of the source video bitrate at SSIM mean >=0.996). --tier cannot express that: it SKIPS any
file whose classification disagrees. --force-tier applies the requested tier instead, with two
guards that stay: copy is refused for a VP9/AV1 source (iOS cannot play the result) and a re-encode
is refused for a file that is already HEVC hvc1 (that is the --overwrite decision).
2026-10-10 19:09:03 +08:00
hoelee 99d03ff072 gate policy: frame-share is the verdict for owner-approved items; park after 2 failed rounds
Owner decision 2026-10-10. Eight items were livelocked in the nvenc tier, burning ~3.3
GPU-hours per pass (initial encode + quality+2 retry) and never converting: they missed the
mean bar by 0.2-1.7 thousandths (0.9626-0.9778) while keeping only 0.20-0.93% of frames
below 0.85 - and per this repo's own comment the FRAME-SHARE test is the one that actually
catches a defect, the mean bar splits a continuum. With SIZE_CEIL=1.0 the mean bar is
unreachable for them by construction.

- library_run.py: POLICY (C:\AI\transcode-run\gate_policy.json) with
  * accept - named items are judged by the frame-share test; a mean under the bar is logged,
    not enforced. An item that trips the frame-share test is refused even if listed
    (0912 洞见, 1.33%, is deliberately absent).
  * park  - failed quality ROUNDS per item; at PARK_AFTER=2 the item is skipped with a
    visible SKIP status instead of being re-encoded. Counters persist in the same file.
- scripts/build_gate_policy.py: builds that file from the run log, taking each key verbatim
  from the '--- i/n <relative path>' line (no hand-copying). Result: 7 accepted, 1 refused.
- run/relaunch_nvenc.sh: start the GPU tier ALONE (relaunch_tiers.sh hardcodes both tiers).
- STATE.md: the policy, its rationale and the round counter.
2026-10-10 17:22:45 +08:00
hoelee bd8382e334 x265-only relauncher; STATE: the 16:51 stop was a machine reboot
- run/relaunch_x265.sh: start ONLY the x265 tier. run/relaunch_tiers.sh hardcodes
  `for t in x265 nvenc`, and the nvenc tier must not start while another job owns the
  GPU (the TubeSync 58-file repair batch holds it since 2026-10-09 20:36). x265 is
  pinned to the E-cores, so it shares only the RaiDrive mount -- 2 concurrent share
  jobs is the documented safe limit.
- The launcher redirects its own banners into the log (under -WindowStyle Hidden,
  stdout goes nowhere) and documents the -ArgumentList form: the script path alone.
- STATE.md: LastBootUpTime 2026-10-09 16:51:58 -- both tiers stopped by a REBOOT, not a
  bug (x265 404/589, nvenc 308/589); the stale lock pids need no cleanup because
  transcode.Lock is staleness-aware. Memory after reboot: 13 GB free / 50.3 of 55.9 GB
  committed, but the commit limit fell from 79.6 GB because D: is 92% full.
2026-10-09 20:53:34 +08:00
hoelee f4ab797580 install the one complete leftover (崇祯传) + remove the 7 truncated staging files
崇祯传: the 493 MB <live>.new.mp4 the MemoryError left behind was complete. Passed, on a
local copy, structure + FULL DECODE + the picture gate (min 0.9980 / mean 0.9988, 1500
frames, 0 below 0.85) and a hash read-back against the share copy, only then renamed over
the live file (install read-back sha256 5a903ab8a3d1, 493,366,137 B, hevc/hvc1, 3616.8 s).
Saves a 3616 s re-encode: 822,288,651 B h264 -> 493,366,137 B HEVC.

The other 7 were truncated prefixes -> deleted; their live originals are untouched and the
tiers will redo them. 0 *.new.mp4 remain on the share.
2026-10-09 12:04:58 +08:00
hoelee bd415d2af5 fix: a MemoryError out of a share write no longer orphans the staged file
Host hit 0 GB physical free / 76.8 of 79.6 GB commit while both tiers ran (pagefile
capped at 32 GB on a 97%-full D:), and the Dokan write of the batch's largest output
raised MemoryError. except OSError does not catch that, so the item was logged
'!! FAIL MemoryError:' with an empty message and the complete 493 MB <live>.new.mp4
stayed on the share; 8 such orphans had accumulated.

- _sha_remote / copy_remote_to_local / copy_local_to_remote: except (OSError, MemoryError)
  so a transient host hiccup retries instead of failing the item
- same widening for both partial-file cleanups
- per-item handler: delete <dest>.new.mp4 unconditionally (os.remove + ignore
  FileNotFoundError, never gated on os.path.exists - stale metadata on this share)

Verified by injecting MemoryError: the upload path returns False with the partial
deleted, the source read retries then raises a clean IOError, the hash retries twice.
2026-10-09 11:38:40 +08:00
hoelee 4385724c5e gate: a re-do of an already-playable file gets a 0.975 mean bar (owner decision)
One pass measured 11 attempts rejected purely on the window mean (0.9655-0.9795)
while accepted encodes had worse frame minima (0.33-0.90): the bar was splitting a
continuum, not separating defects. 0718 马斯克原理 failed with min 0.887 and 0.00% of
frames below 0.85. Those files already play (HEVC hvc1 + AAC) and a re-do exists only
to reclaim an old setting's bloat; reaching a 0.98 mean costs more than the source's
own bitrate, which the size ceiling forbids - so the strict bar stranded them with
their bloat while burning an encode every pass.

SSIM_MEAN_MIN_REDO = 0.975 now applies only when the run is re-doing a file that is
genuinely playable (HEVC hvc1 AND aac) from the snapshot original. The frame-share
test (>1% of frames below 0.85) is unchanged and is what catches a real defect.

Verified on ONE file before the tiers were restarted: 0321 随他们去 (rejected last
pass at mean 0.9789) -> ok, mean 0.9786, min 0.5092 with 5 of 1500 frames below 0.85
(fades), 633 MB -> 418 MB installed, live byte count == the encoded output.
2026-10-08 20:07:26 +08:00
hoelee b2f61295cc skill: orphan the long runs (session death killed both tiers) + copy tier is not idempotent 2026-10-08 10:53:04 +08:00
hoelee b78c96a066 .gitattributes: keep *.sh at LF (autocrlf=true would break bash on checkout) 2026-10-08 10:52:21 +08:00
hoelee 7c278afc51 handoff: relaunch the tiers detached, progress numbers, new-episode copy run
The x265/nvenc tiers launched as Hermes background processes were killed
mid-encode at 10:37 when the user's session was closed, so persist_on_release
is not enough here: run/relaunch_tiers.sh starts them orphaned from Hermes
(Start-Process) with a retry loop, which is why they are no longer tracked and
must be stopped by PID only.

STATE.md now carries the progress table (242/589 done, 347 pending: 169 x265 +
174 nvenc + 4 copy), the reason a full `--tier copy` pass must NOT be run (its
only skip test is "already HEVC", which a copy output never satisfies - it
would redo all 193), and the four new weekly episodes handled one file at a
time.
2026-10-08 10:52:05 +08:00
hoelee 832c76619a state + skill: handoff doc, and move the measured failure modes into references/
STATE.md carries what the next session needs: the two commands that keep the tiers running, where
the logs/stage/locks/ledger live, the eight bugs this round produced (each with the measurement that
proved it), and the open items. The skill's body now keeps only the load-bearing rules; every
measured case moved to references/pitfalls.md, so the always-loaded part stays readable.
2026-10-08 10:30:59 +08:00
hoelee 5c911f5450 watchdog: kill an encode that stops producing output
The GPU tier sat frozen for 1.5 hours: the user updated the NVIDIA driver while a hevc_nvenc encode
was running, which wedges in-flight GPU work with no error at all - the process stays alive, the
output stops growing, the encoder reads 0%, and nothing anywhere reports a problem. A multi-day
unattended run cannot park like that, so every long command that writes a file (the encode, and the
gate's decodes) is now watched: no growth for 300 s and the wedged process is killed and reported as
a failure for the normal retry path to pick up. Self-checked with a process that writes once and
then sleeps: killed at ~35 s for a 20 s stall window.
2026-10-07 17:14:26 +08:00
hoelee bcbffd6e4d gate: give every run its own raw frame files
The three tiers run side by side by design (copy is I/O, x265 is CPU, nvenc is the GPU ASIC) and
they share the stage directory - but the gate's raw frame files had FIXED names, so two concurrent
gates overwrote each other's decodes. Measured: a comparison reported 100% of frames below 0.85 -
which reads exactly like a systematic defect and was nothing but two runs writing ssim_ref.yuv at
once. The raws are now tagged with the pid and the file tag. A single-file conversion failed its
gate on this and the 'defect' was entirely my own harness.
2026-10-07 14:03:33 +08:00
hoelee 66a80e2752 single-file mode: --path / --dest / --keep-source
A freshly downloaded replacement has to go through the SAME pipeline as the library - same bpp
tier rule, same gates, same hash-verified install - rather than a hand-rolled ffmpeg one-off. So:
--path converts one file anywhere on disk (its tier is still chosen by bpp; the dest defaults next
to it), --dest installs the result at an exact path (e.g. back into the library), --keep-source
never deletes the source after a verified install. Also fixes a cross-drive crash: os.path.relpath
raises ValueError when the file is on D: and the library on Z:, so logs/ledger fall back to the
absolute path (measured on the first run of this feature).
2026-10-07 13:18:07 +08:00
hoelee 5071ddfc8c probe: retry, because this share times probes out
A 30 MB file timed out a 120 s ffprobe on the share. The main loop's per-item try/except keeps the
run alive (good) but turns that hiccup into a FAIL, leaving the file unconverted for the rest of the
pass - so a probe is now retried three times before it is allowed to fail an item.
2026-10-07 12:24:47 +08:00
hoelee 59eabc7eda install: read the installed file back - metadata on this share can be a cache
One file was reported converted and was not: 'ok 1085 MB -> 478 MB' printed, every metadata probe
agreed, and the live file was still the H.264 original afterwards, with no error anywhere. RaiDrive
/ Dokan serves cached attributes, so a rename can appear to succeed while nothing landed. The
install step now reads the live file back and compares its SHA-256 with the encode it just made -
the one check a cache cannot satisfy. Costs a read per file; catches a whole class of silent
no-ops that today's 'success' reports hid.
2026-10-07 11:54:17 +08:00
hoelee aad65c56d4 gate: judge the DEFECT SHAPE, and ignore frames where SSIM means nothing
The gate failed a perfectly good encode (min 0.2552, mean 0.9841) because it demanded a per-frame
floor of 0.985 for EVERY frame. Two measured facts say that is the wrong test:

* SSIM collapses on near-flat frames. Two almost-black frames of a fade score ~0.25 while their
  neighbours score 0.998, so a minimum over all frames condemns good encodes. The gate now measures
  each source frame's luma std and drops the flat ones from the verdict (reported, never hidden;
  if more than half the window is flat the exclusion is skipped so the gate still means something).
* A defect has a SHAPE. Measured distributions on this library: good encodes 0 of 1500 frames below
  0.95; the file that triggered this 5 of 1500 below 0.85 (0.33%, isolated) at a 0.984 mean; the
  genuine decoder-defect files 44 of 1499 (2.9%) with the mean falling. So the verdict is now
  'mean < 0.98 OR more than 1% of frames below 0.85' -> fail; a handful of scattered low frames at a
  healthy mean is logged as fades, not a defect - and the log line carries the counts, so the
  decision is auditable.
2026-10-07 11:16:17 +08:00
hoelee d6bab29077 source copy: verify the staged file by hash, not by length
A read of the RIGHT LENGTH can still be wrong on this share - RaiDrive reports stale sizes, and a
full-file listing read here stopped halfway with no error at all (it looked exactly like a
truncated file). A corrupt staged source would be silently encoded into a corrupt output, so the
copy now compares a hash of what it wrote against a fresh read of the share copy (files over 64 MB,
one extra pass - cheap next to the encode it protects). Today's evidence: a 921 MB snapshot original
threw 'Error splitting the input into NAL units' in one pass and decoded perfectly in the next.
2026-10-07 10:15:13 +08:00