stream_signature() ran ffmpeg -f data - with stdout=PIPE, stderr=PIPE and drained stdout first, reading stderr only after EOF. A source that floods stderr (a Matroska with 1,612 'exceeds containing master element' errors = 219,020 bytes) fills the 64 KB stderr buffer, ffmpeg blocks writing it, stdout never closes and the read loop blocks for ever - 42 min at 2.1 s of CPU, and the supervisor's gate watchdog killed the same item three times at 60 min each. p.wait(timeout=1800) cannot help: it is unreachable until that loop ends. -f streamhash -hash md5 - lets ffmpeg do the md5 itself (byte-identical: 5cb7483040... both ways on that file, 2.3 s instead of a 48.9 MB pipe) and one subprocess.run(capture_output=True, timeout=...) drains both fds on threads, so the stderr flood cannot wedge and a wedged demuxer costs a bounded wait that returns None (the gate then says 'could not hash payload', never 'payload differs'). Return shape (nb_packets, md5) and every caller unchanged. test_tracks 55/55, including 'e2e mkv/mp4: copied streams are byte-identical' on the real fixtures.
5.0 KiB
AGENTS.md — entry point for any AI session touching this repo
This repo is the canonical source of the universal-video-transcode Hermes skill.
Read this file first, then README.md, then the specific reference you need.
Owner: Lee Teong Hoe (Mr Hoelee) · [email protected] · WhatsApp +60 12-797 2969
1. What this is
One tool that turns any video/audio file into an MP4 that plays on both iPad and Android, at the best quality the target codec allows.
| layer | what | where |
|---|---|---|
| the tool | scripts/transcode.py — path in, verified MP4 out |
this repo |
| the gate | scripts/selftest.py — builds both defect shapes and asserts the detector |
this repo |
| the skill | SKILL.md + references/ — loads into Hermes |
copied to the skill dir (§4) |
There are no credentials in this project, so there is no SECRETS.md.
2. The non-negotiables (read before you change anything)
-fps_mode cfron every video re-encode. Without it the encoder silently drops 0.5–1.3% of frames, leaving doubled frame intervals that play as judder.verify()fails an item whose output comes back non-uniform — never remove that check.-tag:v hvc1on every HEVC output, and-pix_fmt yuv420p. Apple refuseshev1(ffmpeg's default) and non-8-bit formats lose device compatibility.- Never copy a video whose timeline is defective.
-c copycannot retime — ffmpeg will not rewritestts/cttsunder stream copy — so a flat input survives into the output.plan_for()decides this; do not "simplify" it into an unconditional copy. - One encoder at a time. The lock file is not optional hygiene: two concurrent NVENC jobs share one encoder unit, starve each other, and drop frames.
- Run
python scripts/selftest.pyafter touching the detector. It is the only thing standing between this tool and shipping files that stutter. - Never write encode output straight to a network share. Encode to local disk, verify,
then copy the complete file across; a streaming
.partwrite leaves a corrupt stub on any blip. If the destination is remote, keep the output local. - Never read one child PIPE while leaving the other undrained.
subprocess.run(..., capture_output=True, timeout=…)(or sending the noisy fd to a file) is the default; awhile p.stdout.read():loop withp.stderrstill holding a PIPE will deadlock the moment the child fills that pipe — measured 2026-11-15: a corrupt Matroska emitted 219 KB of container errors, ffmpeg blocked writing stderr, the gate sat 42 min at 2.1 s CPU and the supervisor killed the item three times (seeSTATE.mdbug 14).p.wait(timeout=)does NOT save you: it is unreachable until that read loop ends. A loop that drains a child owes itself a deadline.
3. Layout
SKILL.md the Hermes skill (installed per §4)
README.md human-facing overview
docs/WHY.md the benefit case: ten real failures + the guard each produced
scripts/transcode.py the tool: plan -> encode -> verify -> keep input on failure
scripts/selftest.py proves the detector; both defect shapes, no false positives
references/compatibility-matrix.md per-platform codec/container facts with citations
references/verification-and-automation.md the defect classes, the structural gate, the 2x2 proof
4. Installing the skill
cp -r . "$LOCALAPPDATA/hermes/skills/media/universal-video-transcode"
Keep this repo the source of truth and copy to the skill dir, not the reverse — edits made only in the skill dir are lost the next time it is reinstalled.
5. What "verified" means here
An output is accepted only if all of these hold, each read back from the file:
duration within 1% · resolution identical · expected video codec · hvc1 tag on HEVC ·
audio is AAC · 8-bit yuv420p · uniform cadence · no flat composition offsets ·
full decode exits 0 · read-back after the write matches.
Do not claim a fix without running the arbiter. measure_playback.py in the
tubesync-selfhosted skill plays a file in real Chrome and reports
getVideoPlaybackQuality().droppedVideoFrames — but note Chrome cannot decode HEVC, so
an HEVC file reports 0 decoded / 0 dropped and that is not a pass. Judge HEVC by the
structural gate and confirm on the Apple device.
6. Related work
hevc-transcode— the TubeSync archive this tool was extracted from. It owns the DB-driven pipeline (tsconv.py/tsfix.py) and the deeper frame-timing forensics.tsconv.flat_timing()is that repo's copy of the detector: keep the two in step, and note that the missing-cttsshape was once missed by three duplicated copies of exactly this logic. One implementation per repo.references/verification-and-automation.mdcarries the measured 2x2 that proved the defect is container timing and not the bitstream. If you are about to argue that a bitstream property is the cause, read that first.